Android11編譯導入PRODUCT_BOOT_JARS

Android P如下版本導入PRODUCT_BOOT_JARS

Android編譯導入PRODUCT_BOOT_JARS

PRODUCT_PACKAGES += \
   com.king.test.module \
PRODUCT_BOOT_JARS += \
    com.king.test.module \

增長package白名單

源碼文件build/make/core/tasks/check_boot_jars/package_allowed_list.txt增長jar包名白名單javascript

###################################################
#e.g. com.king.test.module-dex.jar
com\.king\.test
com\.king\.test\..*

編寫jar包Android.mk文件(此jar包爲dex文件)

LOCAL_PATH := $(call my-dir)
#e.g. com.king.test.module-dex.jar 
include $(CLEAR_VARS)
LOCAL_MODULE := com.king.test.module
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := com.king.test.module-dex.jar
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
include $(BUILD_PREBUILT)

make編譯

$make –j8

Android 11 版本導入PRODUCT_BOOT_JARS

編寫jar包Android.bp文件(此jar包爲class文件)

使用androidmk命令把Android.mk文件生成Android.bp

$androidmk Android.mk > Android.bp

生成後的文件以下:java

java_import { 
    name: "com.king.test.module",
    jars: ["com.king.test.module-class.jar"],
}

Android.bp增長java_library

如上Android.bp文件會編譯報錯:android

internal error: failed to find a dex jar path for module ’ com.king.test.module’, note that some jars may be filtered out by module constraintsapp

增長java_library定義,installable 爲 true ,不然會一樣錯誤,以下:ui

java_import { 
    name: "com.king.test.module_jar",
    jars: ["com.king.test.module-class.jar"],
}
java_library { 
    name: "com.king.test.module",
    static_libs: [
        " com.king.test.module_jar",
    ],
    installable: true,
}

jar包爲dex文件編譯運行出錯處理

若是jar包是已經編譯好的dex文件而不是純class文件,在Android11上編譯會有如下問題,處理方式可參見說明spa

check_boot_jars.py 檢查出錯

Error: out/target/common/obj/JAVA_LIBRARIES/ com.king.test.module_intermediates/classes.jar does not contain any class files.code

解決方法: 修改build/make/core/tasks/check_boot_jars/check_boot_jars.py,註釋"if classes == 0"的判斷
在這裏插入圖片描述
也可java_library 增長空的java文件,以下

blog

// srcs: [
// "src/**/*.java",
// ],

不過此方法會後面編譯出錯:圖片

Error: Cannot create android app from an archive ‘out/soong/.intermediates/vendor/king/ com.king.test.module/android_common/combined/com.king.test.module.jar’ containing both DEX and Java-bytecode contentip

merge_zips合併jar包出錯

merge_zips.go:752: Duplicate path classes.dex found in out/soong/.intermediates/vendor/king/com.king.test.module/android_common/dex/classes.dex.jar!classes.dex and out/soong/.intermediates/vendor/king/com.king.test.module_jar/android_common/combined/com.king.test.module_jar.jar

解決方法: 修改build/soong/cmd/merge_zips/merge_zips.go,修改參數ignore-duplicates爲true
在這裏插入圖片描述

相關文章
相關標籤/搜索