问题描述
我正在关注
更新:
我现在将 Android.mk
文件的位置更改为 AndroidManifest.xml
所在的位置,并且还更改了我的 Android.mk
.
ifeq ($(TARGET_FWK_SUPPORTS_FULL_VALUEADDS),true)ifeq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),平台)LOCAL_PATH := $(调用我的目录)包括 $(CLEAR_VARS)res_dir := res $(LOCAL_PATH)/resLOCAL_MODULE_TAGS := 可选#LOCAL_SDK_VERSION := 当前LOCAL_SRC_FILES := $(call all-java-files-under, java)LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))LOCAL_USE_AAPT2 := 真LOCAL_JAVA_LIBRARIES := com.google.android.material_material \LOCAL_STATIC_ANDROID_LIBRARIES := \androidx.core_core \androidx.appcompat_appcompat \androidx.fragment_fragment \android-support-constraint-layout \LOCAL_DEX_PREOPT := 假LOCAL_CERTIFICATE := 平台LOCAL_PRIVILEGED_MODULE := 真#LOCAL_PRODUCT_MODULE := 真LOCAL_PACKAGE_NAME := 媒体解码LOCAL_PRIVATE_PLATFORM_APIS := 真包括 $(BUILD_PACKAGE)万一万一
现在我得到了一个 2MB 的应用程序,该应用程序在安装后显示在设备上,但在我运行时立即崩溃并出现错误
--------- 崩溃的开始04-21 21:43:20.852 4319 4319 E AndroidRuntime:致命异常:主要04-21 21:43:20.852 4319 4319 E AndroidRuntime:进程:com.example.mediadecode,PID:431904-21 21:43:20.852 4319 4319 E AndroidRuntime:java.lang.RuntimeException:无法实例化活动组件信息{com.example.mediadecode/com.example.mediadecode.MainActivity}:java.lang.ClassNotFoundException:找不到类com.example.mediadecode.MainActivity"在路径上:DexPathList[[zip 文件/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/arm64、/system/lib64、/system/product/lib64]]04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3195)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.os.Handler.dispatchMessage(Handler.java:107)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.os.Looper.loop(Looper.java:214)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.ActivityThread.main(ActivityThread.java:7397)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 java.lang.reflect.Method.invoke(本机方法)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)04-21 21:43:20.852 4319 4319 E AndroidRuntime:引起:java.lang.ClassNotFoundException:未找到类com.example.mediadecode.MainActivity"在路径上:DexPathList[[zip 文件/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/arm64、/system/lib64、/system/product/lib64]]04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 java.lang.ClassLoader.loadClass(ClassLoader.java:379)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 java.lang.ClassLoader.loadClass(ClassLoader.java:312)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.Instrumentation.newActivity(Instrumentation.java:1251)04-21 21:43:20.852 4319 4319 E AndroidRuntime:在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3183)04-21 21:43:20.852 4319 4319 E AndroidRuntime:... 11 更多
形成的apk内容是
使用 Gradle 构建的内容是
如何使用 mm 构建我的 apk 并成功运行?
我能够在我的 Kotlin Android 应用程序中使用 Soong 编译.我使用了以下 Android.bp 文件.
android_app {名称:Camera2Video2",清单:AndroidManifest.xml",特权:真实,platform_apis: 真,证书:平台",源代码:[java/com/example/android/camera2/video/*.kt",java/com/example/android/camera2/video/fragments/*.kt",java/com/example/android/camera2/video/overlay/*.kt",java/com/example/android/camera2/video/utils/*.kt",],资源目录:[res/",],静态库:[androidx-constraintlayout_constraintlayout",androidx.appcompat_appcompat",androidx.localbroadcastmanager_localbroadcastmanager",com.google.android.material_material",androidx.exifinterface_exifinterface",androidx.core_core",androidx.preference_preference",androidx.fragment_fragment",],库:[电话通用",],优化:{启用:假,},dex_preopt:{启用:假,},}
我还尝试在将 Android 应用程序完全转换为 Java 后对其进行编译.这是Android.mk文件
LOCAL_PATH := $(call my-dir)包括 $(CLEAR_VARS)res_dir := res $(LOCAL_PATH)/resLOCAL_MODULE_TAGS := 可选#LOCAL_SDK_VERSION := 当前LOCAL_SRC_FILES := $(call all-java-files-under, java)LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))LOCAL_USE_AAPT2 := 真LOCAL_JAVA_LIBRARIES := com.google.android.material_material \LOCAL_STATIC_ANDROID_LIBRARIES := \androidx.appcompat_appcompat \androidx-constraintlayout_constraintlayout \androidx.preference_preference \androidx.fragment_fragment \androidx.core_core \#LOCAL_DEX_PREOPT := falseLOCAL_CERTIFICATE := 平台LOCAL_PRIVILEGED_MODULE := 真#LOCAL_PRODUCT_MODULE := 真LOCAL_PACKAGE_NAME := QMediaLOCAL_PRIVATE_PLATFORM_APIS := 真包括 $(BUILD_PACKAGE)
I am following https://wladimir-tm4pda.github.io/porting/build_cookbook.html and have modified Building a simple APK
The Android.mk file is at the top level.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-arch-lifecycle-extensions \
android-support-v7-recyclerview \
android-support-v7-appcompat \
android-support-constraint-layout \
# Build all java files in the java subdirectory
#LOCAL_SRC_FILES := $(call all-subdir-java-files)
#Commented line just made a ~17kB apk file
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_SDK_VERSION := current
#Otherwise build failing
# Tell it to build an APK
include $(BUILD_PACKAGE)
I have included it in Android 10 AOSP and built using mm
command in terminal.
The output apk is 1MB big (should be 5 MB) and after doingadb install -r -t -f LocalPackage.apk
it does not show up in the apps list.When built in Android Studio it is working fine.
My aim is to make this app a system app but first step is making mm
build succeed. How to rectify this?
UPDATE:
I now changed the location of Android.mk
file to where AndroidManifest.xml
is present and also changed my Android.mk
.
ifeq ($(TARGET_FWK_SUPPORTS_FULL_VALUEADDS),true)
ifeq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),platform)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
res_dir := res $(LOCAL_PATH)/res
LOCAL_MODULE_TAGS := optional
#LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_USE_AAPT2 := true
LOCAL_JAVA_LIBRARIES := com.google.android.material_material \
LOCAL_STATIC_ANDROID_LIBRARIES := \
androidx.core_core \
androidx.appcompat_appcompat \
androidx.fragment_fragment \
android-support-constraint-layout \
LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
#LOCAL_PRODUCT_MODULE := true
LOCAL_PACKAGE_NAME := mediadecode
LOCAL_PRIVATE_PLATFORM_APIS := true
include $(BUILD_PACKAGE)
endif
endif
Now I am getting a 2MB app and the app shows up on the device after install but crashes as soon as I run it with the error
--------- beginning of crash
04-21 21:43:20.852 4319 4319 E AndroidRuntime: FATAL EXCEPTION: main
04-21 21:43:20.852 4319 4319 E AndroidRuntime: Process: com.example.mediadecode, PID: 4319
04-21 21:43:20.852 4319 4319 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.mediadecode/com.example.mediadecode.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.mediadecode.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/lib/arm64, /system/lib64, /system/product/lib64]]
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3195)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7397)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.mediadecode.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.mediadecode-vTqIZ9aZv0FsEDQ8xzj4GA==/lib/arm64, /system/lib64, /system/product/lib64]]
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3183)
04-21 21:43:20.852 4319 4319 E AndroidRuntime: ... 11 more
The contents of the apk formed are
The contents on building with Gradle is
How can I build my apk with mm and run it successfully?
I was able to use Soong compilation for my Kotlin Android app. I used the following Android.bp file.
android_app {
name: "Camera2Video2",
manifest: "AndroidManifest.xml",
privileged: true,
platform_apis: true,
certificate: "platform",
srcs: [
"java/com/example/android/camera2/video/*.kt",
"java/com/example/android/camera2/video/fragments/*.kt",
"java/com/example/android/camera2/video/overlay/*.kt",
"java/com/example/android/camera2/video/utils/*.kt",
],
resource_dirs: [
"res/",
],
static_libs: [
"androidx-constraintlayout_constraintlayout",
"androidx.appcompat_appcompat",
"androidx.localbroadcastmanager_localbroadcastmanager",
"com.google.android.material_material",
"androidx.exifinterface_exifinterface",
"androidx.core_core",
"androidx.preference_preference",
"androidx.fragment_fragment",
],
libs: [
"telephony-common",
],
optimize: {
enabled: false,
},
dex_preopt: {
enabled: false,
},
}
I also tried compiling my Android app after converting it fully to Java. Here is the Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
res_dir := res $(LOCAL_PATH)/res
LOCAL_MODULE_TAGS := optional
#LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dir))
LOCAL_USE_AAPT2 := true
LOCAL_JAVA_LIBRARIES := com.google.android.material_material \
LOCAL_STATIC_ANDROID_LIBRARIES := \
androidx.appcompat_appcompat \
androidx-constraintlayout_constraintlayout \
androidx.preference_preference \
androidx.fragment_fragment \
androidx.core_core \
#LOCAL_DEX_PREOPT := false
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
#LOCAL_PRODUCT_MODULE := true
LOCAL_PACKAGE_NAME := QMedia
LOCAL_PRIVATE_PLATFORM_APIS := true
include $(BUILD_PACKAGE)
这篇关于使用 Android.mk mm 命令构建的 APK 安装后未在设备中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!