0

我在 Android Studio 中构建我的项目并生成签名的 apk,然后将我的 apk 放入 Android 开源项目中以将我的应用程序与系统映像打包。
我按照这些步骤将我的应用程序与系统映像打包在一起。
我的问题是这一行Android.mk

LOCAL_CERTIFICATE := < desired key >

如果我不签署 apk 并使用

LOCAL_CERTIFICATE := platform

一切顺利,构建成功
,但如果我签署我的 apk 并使用

LOCAL_CERTIFICATE := PRESIGNED

我的构建失败并出现错误 1:

make: *** [out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk] Error 1

对于详细日志,我使用它制作项目,make showcommands这就是发生错误的地方:

mv out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk.unaligned
out/host/linux-x86/bin/zipalign -f -p 4 out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk.unaligned out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk.aligned
make: *** [out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk] Error 1

所以问题是zipalign!构建系统不应该对签名的 apk 使用 zipalign,但为什么要使用呢?

我完整的 Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := MyApp
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := my_app.apk
LOCAL_PRIVILEGED_MODULE = true
LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3


include $(BUILD_PREBUILT)
4

1 回答 1

0

mv out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk.unaligned

out/host/linux-x86/bin/zipalign -f -p 4 out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk.unaligned out/target/product/helpera64-v2/obj/APPS /MyApp_intermediates/package.apk.aligned

制作:*** [out/target/product/helpera64-v2/obj/APPS/MyApp_intermediates/package.apk] 错误 1

从错误日志来看,执行的zipalign命令失败了,所以可能失败的原因是你的 apk 错误align。也许您可以按照Android 的 zipalign文档来确保您的 apk 具有正确的align.

PS:我也遇到过类似的问题,因为presigned apk有错误的alignso文件。

于 2021-05-05T09:51:08.883 回答