平台
RK3288 + Android 5.1
问题
内置应用失败, 编译LOG如下:
PRODUCT_COPY_FILES vendor/rockchip/common/nand/modules/arm/rk30xxnand_ko.ko.3.10.0:root/rk30xxnand_ko.ko.3.10.0 ignored. target Prebuilt: PrebuildApk (out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk) build/core/prebuilt_internal.mk:221: recipe for target 'out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk' failed make: *** [out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk] Error 1
Android.mk内容如下.
############################################################################### LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := PrebuildApk LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_TAGS := optional LOCAL_BUILT_MODULE_STEM := package.apk LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_OVERRIDES_PACKAGES := Launcher3 LOCAL_PREBUILT_JNI_LIBS := \ lib/armeabi-v7a/libconceal.so \ lib/armeabi-v7a/libmp3lame.so \ lib/armeabi-v7a/libserial_port.so include $(BUILD_PREBUILT)
若LOCAL_CERTIFICATE := PRESIGNED
改为LOCAL_CERTIFICATE := platform
则编译正常.
分析
报错位置: $(transform-prebuilt-to-target) |-- build/core/prebuilt_internal.mk $(built_module) : $(my_prebuilt_src_file) | $(ACP) $(ZIPALIGN) $(SIGNAPK_JAR) $(transform-prebuilt-to-target) ifdef extracted_jni_libs $(hide) zip -d $@ 'lib/*.so' # strip embedded JNI libraries. endif ifneq ($(LOCAL_CERTIFICATE),PRESIGNED) $(sign-package) endif ifdef LOCAL_DEX_PREOPT ifneq (nostripping,$(LOCAL_DEX_PREOPT)) $(call dexpreopt-remove-classes.dex,$@) endif endif $(align-package) endif # ifeq ($(LOCAL_ADD_ENCED_PLATFORM_KEYS_TO_APK),true)
|-- build/core/definitions.mk
# Copy a prebuilt file to a target location. define transform-prebuilt-to-target @echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)" $(copy-file-to-target) endef # The -t option to acp and the -p option to cp is # required for OSX. OSX has a ridiculous restriction # where it's an error for a .a file's modification time # to disagree with an internal timestamp, and this # macro is used to install .a files (among other things). # Copy a single file from one place to another, # preserving permissions and overwriting any existing # file. # If files are identical then don't copy. # We disable the "-t" option for acp cannot handle # high resolution timestamp correctly on file systems like ext4. # Therefore copy-file-to-target is the same as copy-file-to-new-target. define copy-file-to-target @mkdir -p $(dir $@) $(hide)(cmp -s $< $@ ; if [ $$? -ne 0 ] ; then $(ACP) -fp $< $@ ; fi) endef
上面的代码, 没做很复杂的工作, 除了COPY, 就是COPY…
从报错的LOG来看, 是找不到 out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk
对应目录下当前的文件:
ls out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/ package.apk.aligned package.apk.unaligned
package.apk文件的产生与$(align-package) 有关:
|-- build/core/definitions.mk
# Align STORED entries of a package on 4-byte boundaries # to make them easier to mmap. # define align-package $(hide) mv $@ $@.unaligned $(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned $(hide) mv $@.aligned $@ endef
这段代码执行了脚本
package.apk => package.apk.unaligned
zipalign -f 4 package.apk.unaligned => package.apk.aligned
package.apk.aligned => package.apk
zipalign相关: APK优化工具zipalign的详细介绍和使用
在$(hide) $(ZIPALIGN) -f 4 $@.unaligned $@.aligned 后打上LOG:
$(hide) echo “zipalign finish”
发现并无LOG输出.
由此可推出, 在执行zipalign的过程出错了, 导致后面没有完成package.apk.aligned 到 package.apk的文件移动动作.
Zip alignment utility Copyright (C) 2009 The Android Open Source Project Usage: zipalign [-f] [-v] [-z] <align> infile.zip outfile.zip zipalign -c [-v] <align> infile.zip <align>: alignment in bytes, e.g. '4' provides 32-bit alignment -c: check alignment only (does not modify file) -f: overwrite existing outfile.zip -v: verbose output -z: recompress using Zopfli
添加 -c 试试:
$(hide) $(ZIPALIGN) -v -f 4 $@.unaligned $@.aligned 8659383 res/mipmap-hdpi-v4/xiaoxue.png (BAD - 3) 8661537 res/mipmap-hdpi-v4/xiaoyu.png (BAD - 1) 8664369 res/mipmap-hdpi-v4/xuanzhong.png (BAD - 1) 8686381 res/mipmap-hdpi-v4/yanzhengma_icon.png (BAD - 1) 8688650 res/mipmap-hdpi-v4/yanzhengma_icon1.png (BAD - 2) 8692149 res/mipmap-hdpi-v4/yin.png (BAD - 1) 8708049 res/mipmap-hdpi-v4/yujiaxue.png (BAD - 1) 8710568 res/mipmap-hdpi-v4/zanting_icon.png (OK) 8720163 res/mipmap-hdpi-v4/zhangsheng_icon.png (BAD - 3) 8728721 res/mipmap-hdpi-v4/zhenyu.png (BAD - 1) 8732137 res/mipmap-hdpi-v4/zhezhao.png (BAD - 1) 8733131 res/mipmap-hdpi-v4/zhongxue.png (BAD - 3) 8735976 res/mipmap-hdpi-v4/zhongyu.png (OK) 8738530 res/mipmap-mdpi-v4/ic_launcher.png (BAD - 2) 8740807 res/mipmap-xhdpi-v4/ic_launcher.png (BAD - 3) 8745725 res/mipmap-xxhdpi-v4/arrow_down_grey.png (BAD - 1) 8745943 res/mipmap-xxhdpi-v4/beijing.png (BAD - 3) 9669819 res/mipmap-xxhdpi-v4/bg_login.png (BAD - 3) 10658417 res/mipmap-xxhdpi-v4/fanhui_icon.png (BAD - 1) 10660124 res/mipmap-xxhdpi-v4/fenlei_di.png (OK) 10671604 res/mipmap-xxhdpi-v4/general_back.png (OK) 10678633 res/mipmap-xxhdpi-v4/general_back_b.png (BAD - 1) 10679246 res/mipmap-xxhdpi-v4/gerenzhongxin_icon.png (BAD - 2) 10694311 res/mipmap-xxhdpi-v4/ic_launcher.png (BAD - 3) 10702098 res/mipmap-xxhdpi-v4/kegelei.png (BAD - 2) 10746375 res/mipmap-xxhdpi-v4/logo.png (BAD - 3) 10760700 res/mipmap-xxhdpi-v4/quxiao_icon.png (OK) 10762940 res/mipmap-xxhdpi-v4/rili_icon.png (OK) 10767988 res/mipmap-xxhdpi-v4/shanchu_icon.png (OK) 10772517 res/mipmap-xxhdpi-v4/shangyiye.png (BAD - 1) 10774226 res/mipmap-xxhdpi-v4/shezhi_icon.png (BAD - 2) 10779434 res/mipmap-xxhdpi-v4/shezhilan.png (BAD - 2) 10789570 res/mipmap-xxhdpi-v4/shouji_icon.png (BAD - 2) 10791186 res/mipmap-xxhdpi-v4/shoujidenglu_icon.png (BAD - 2) 10802009 res/mipmap-xxhdpi-v4/shuru_kuang.png (BAD - 1) 10804007 res/mipmap-xxhdpi-v4/suoding_icon.png (BAD - 3) 10806431 res/mipmap-xxhdpi-v4/tianqi_kuang.png (BAD - 3) 10810536 res/mipmap-xxhdpi-v4/tiaoyin_icon.png (OK) 10824741 res/mipmap-xxhdpi-v4/touxiang_icon.png (BAD - 1) 10829308 res/mipmap-xxhdpi-v4/tuichudenglu_icon.png (OK) 10831564 res/mipmap-xxhdpi-v4/weiixndenglu_icon.png (OK) 10841843 res/mipmap-xxhdpi-v4/xiangji_icon.png (BAD - 3) 10846701 res/mipmap-xxhdpi-v4/xiaole_logo.png (BAD - 1) 10885761 res/mipmap-xxhdpi-v4/yanzhengma_icon.png (BAD - 1) 10888053 res/mipmap-xxxhdpi-v4/custommineitem_jiantou.png (BAD - 1) 10888771 res/mipmap-xxxhdpi-v4/ic_launcher.png (BAD - 3) 10925979 resources.arsc (BAD - 3) Verification FAILED build/core/prebuilt_internal.mk:218: recipe for target 'out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk' failed
Verification FAILED, zipalign执行失败, 但文件生成了, 而align-package也执行中断, 导致packae.apk不存在.
根据Makefile命令中的@和-符号中说明, 尝试加上 - (忽略执行结果)试试:
- $(ZIPALIGN) -v -f 4 $@.unaligned $@.aligned
hide := @, 在definitions.mk中有定义
build/core/prebuilt_internal.mk:218: recipe for target 'out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk' failed make: [out/target/product/rk3288/obj/APPS/PrebuildApk_intermediates/package.apk] Error 1 (ignored) Copy: out/target/product/rk3288/system/app/PrebuildApk/lib/arm/libconceal.so Copy: out/target/product/rk3288/system/app/PrebuildApk/lib/arm/libmp3lame.so Copy: out/target/product/rk3288/system/app/PrebuildApk/lib/arm/libserial_port.so Install: out/target/product/rk3288/system/app/PrebuildApk/PrebuildApk.apk
编译通过.
参考:
Makefile命令中的@和-符号: https://blog.csdn.net/whu_zhangmin/article/details/21959245
APK优化工具zipalign的详细介绍和使用: https://blog.csdn.net/fulushan/article/details/80841649