歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Linux源碼環境下編譯apk實踐

模擬點擊的ap實現中,需要在源碼環境下對ap進行編譯,

android:sharedUserId="android.uid.system

讓ap具有INJEST_EVENT權限。

之前在Linux源碼中進行過編譯測試,但是編譯出來的apk打開就出錯。

這次繼續研究,還是出錯。

01-01 12:01:22.285: E/AndroidRuntime(4807): FATALEXCEPTION: main

01-01 12:01:22.285: E/AndroidRuntime(4807):Process: com.example.test2, PID: 4807

01-01 12:01:22.285: E/AndroidRuntime(4807):java.lang.RuntimeException: Unable to instantiate activityComponentInfo{com.example.test2/com.example.test2.MainActivity}:java.lang.ClassNotFoundException: Didn't find class "com.example.test2.MainActivity"on

path: DexPathList[[zip file"/system/app/Test2/Test2.apk"],nativeLibraryDirectories=[/system/app/Test2/lib/arm,/vendor/lib, /system/lib]]

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2493)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2691)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.-wrap11(ActivityThread.java)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1491)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.os.Handler.dispatchMessage(Handler.java:111)

01-01 12:01:22.285: E/AndroidRuntime(4807): at android.os.Looper.loop(Looper.java:207)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.main(ActivityThread.java:5779)

01-01 12:01:22.285: E/AndroidRuntime(4807): at java.lang.reflect.Method.invoke(NativeMethod)

01-01 12:01:22.285: E/AndroidRuntime(4807): atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)

01-01 12:01:22.285: E/AndroidRuntime(4807): atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:739)

01-01 12:01:22.285: E/AndroidRuntime(4807): Causedby: java.lang.ClassNotFoundException: Didn't find class"com.example.test2.MainActivity" on path: DexPathList[[zip file"/system/app/Test2/Test2.apk"],nativeLibraryDirectories=[/system/app/Test2/lib/arm,/vendor/lib,

/system/lib]]

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

01-01 12:01:22.285: E/AndroidRuntime(4807): atjava.lang.ClassLoader.loadClass(ClassLoader.java:511)

01-01 12:01:22.285: E/AndroidRuntime(4807): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.Instrumentation.newActivity(Instrumentation.java:1072)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2483)

01-01 12:01:22.285: E/AndroidRuntime(4807): ... 9 more

01-01 12:01:22.285: E/AndroidRuntime(4807): Suppressed: java.io.IOException: Nooriginal dex files found for dex location /system/app/Test2/Test2.apk

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexFile.openDexFileNative(Native Method)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexFile.openDexFile(DexFile.java:295)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexFile.<init>(DexFile.java:80)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexFile.<init>(DexFile.java:59)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexPathList.loadDexFile(DexPathList.java:279)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexPathList.makePathElements(DexPathList.java:248)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.DexPathList.<init>(DexPathList.java:120)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)

01-01 12:01:22.285: E/AndroidRuntime(4807): atdalvik.system.PathClassLoader.<init>(PathClassLoader.java:65)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.LoadedApk.getClassLoader(LoadedApk.java:385)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.LoadedApk.makeApplication(LoadedApk.java:580)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.handleBindApplication(ActivityThread.java:4983)

01-01 12:01:22.285: E/AndroidRuntime(4807): atandroid.app.ActivityThread.-wrap1(ActivityThread.java)

01-01 12:01:22.285: E/AndroidRuntime(4807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)

01-01 12:01:22.285: E/AndroidRuntime(4807): ... 6 more

01-01 12:01:22.285: E/AndroidRuntime(4807): Suppressed:java.lang.ClassNotFoundException: com.example.test2.MainActivity

01-01 12:01:22.285: E/AndroidRuntime(4807): atjava.lang.Class.classForName(Native Method)

01-01 12:01:22.285: E/AndroidRuntime(4807): atjava.lang.BootClassLoader.findClass(ClassLoader.java:781)

01-01 12:01:22.285: E/AndroidRuntime(4807): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)

01-01 12:01:22.285: E/AndroidRuntime(4807): atjava.lang.ClassLoader.loadClass(ClassLoader.java:504)

01-01 12:01:22.285: E/AndroidRuntime(4807): ... 12 more

01-01 12:01:22.285: E/AndroidRuntime(4807): Caused by: java.lang.NoClassDefFoundError:Class not found using the boot class loader; no stack trace available

01-01 12:01:25.986: E/AndroidRuntime(4977): FATALEXCEPTION: main

01-01 12:01:25.986: E/AndroidRuntime(4977):Process: com.example.test2, PID: 4977

01-01 12:01:25.986: E/AndroidRuntime(4977):java.lang.RuntimeException: Unable to instantiate activityComponentInfo{com.example.test2/com.example.test2.MainActivity}:java.lang.ClassNotFoundException: Didn't find class "com.example.test2.MainActivity"on path:

DexPathList[[zip file"/system/app/Test2/Test2.apk"],nativeLibraryDirectories=[/system/app/Test2/lib/arm,/vendor/lib, /system/lib]]

搜索 Linux源碼編譯apk,反復試驗,終於解決,編譯的apk也具有了系統權限,可以實現跨進程的屏幕點擊

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4

LOCAL_DEX_PREOPT := false

LOCAL_MULTILIB := 32

LOCAL_PACKAGE_NAME := Test2

LOCAL_CERTIFICATE := platform

#LOCAL_CERTIFICATE := share

LOCAL_OVERRIDES_PACKAGES := Home

include $(BUILD_PACKAGE)

Copyright © Linux教程網 All Rights Reserved