0

我正在关注https://wladimir-tm4pda.github.io/porting/build_cookbook.html并修改了构建一个简单的 APK

Android.mk 文件位于顶层。

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)

我已将其包含在 Android 10 AOSP 中,并mm在终端中使用命令构建。

输出的 apk 有 1MB 大(应该是 5MB),之后 adb install -r -t -f LocalPackage.apk 它不会出现在应用程序列表中。在 Android Studio 中构建时,它工作正常。

我的目标是让这个应用程序成为系统应用程序,但第一步是让mm构建成功。如何纠正这种情况?

在此处输入图像描述

在此处输入图像描述

更新:

我现在将Android.mk文件的位置更改AndroidManifest.xml为存在的位置,并且还更改了我的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

现在我得到了一个 2MB 的应用程序,该应用程序在安装后显示在设备上,但是一旦我运行它并出现错误就会崩溃

--------- 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

形成的apk的内容是 在此处输入图像描述

使用 Gradle 构建的内容是 在此处输入图像描述

如何使用 mm 构建我的 apk 并成功运行?

4

1 回答 1

0

我能够为我的 Kotlin Android 应用程序使用 Soong 编译。我使用了以下 Android.bp 文件。

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,
  },
}

在将 Android 应用程序完全转换为 Java 后,我还尝试编译它。这是 Android.mk 文件

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)
于 2021-09-17T06:51:11.693 回答