软件环境
Android R
编译命令
在AOSP目录下执行以下命令。
$ source build/envsetup.sh
$ lunch
–> 选择编译的平台。
$ make otapackage
错误信息:
2022-08-25 11:05:10 - common.py - INFO : Running: "java -Xmx2048m -Djava.library.path=out/host/linux-x86/lib64 -jar out/host/linux-x86/framework/signapk.jar -w build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8 /home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/soong/.temp/tmpp3oPHS.zip /home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/soong/.temp/tmpn6he42.zip"
2022-08-25 11:05:10 - ota_from_target_files.py - ERROR :
ERROR:
Traceback (most recent call last):
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 2258, in <module>
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 2231, in main
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 1932, in GenerateAbOtaPackage
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 1328, in FinalizeMetadata
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 1314, in ComputeAllPropertyFiles
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/ota_from_target_files.py", line 492, in SignOutput
File "/home/danny/work/la1.2.1-cs2/la121-cs-qcom/aosp/out/host/linux-x86/bin/ota_from_target_files/common.py", line 1848, in SignFile
proc.returncode, stdoutdata))
ExternalError: Failed to run signapk.jar: return code 1:
Error: Unable to access jarfile out/host/linux-x86/framework/signapk.jar
11:05:10 ninja failed with: exit status 1
#### failed to build some targets (08:20 (mm:ss)) ####
解决方案:
$ make signapk
然后再次执行命令:
$ make otapackage
2022-08-25 11:05:11 - common.py - INFO : Running: "java -Xmx2048m -Djava.library.path=out/host/linux-x86/lib64 -jar out/host/linux-x86/framework/signapk.jar -w build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8 /opt/danny/work/la1.2.1-cs2/la121-vapi-cs/aosp/out/soong/.temp/tmpcYUgX4.zip /opt/danny/work/la1.2.1-cs2/la121-vapi-cs/aosp/out/soong/.temp/tmpAc680A.zip"
2022-08-25 11:05:18 - common.py - INFO : Running: "zip -d /opt/danny/work/la1.2.1-cs2/la121-vapi-cs/aosp/out/soong/.temp/tmpAc680A.zip META-INF/com/android/metadata"
2022-08-25 11:05:18 - common.py - INFO : deleting: META-INF/com/android/metadata
2022-08-25 11:05:18 - common.py - INFO : Running: "java -Xmx2048m -Djava.library.path=out/host/linux-x86/lib64 -jar out/host/linux-x86/framework/signapk.jar -w build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8 /opt/danny/work/la1.2.1-cs2/la121-vapi-cs/aosp/out/soong/.temp/tmpAc680A.zip out/target/product/msmnile_au/msmnile_au-ota-eng.danny.zip"
2022-08-25 11:05:22 - ota_from_target_files.py - INFO : done.
#### build completed successfully (08:53 (mm:ss)) ####
查看生成结果
danny@ubuntu:~/aosp$ ls out/target/product/msmnile_au/*.zip -lh
-rw-rw-r-- 1 danny danny 496M Aug 25 11:05 out/target/product/msmnile_au/msmnile_au-ota-eng.danny.zip
其他小知识
以上可利用Android源代码生成的签名文件signapk.jar给apk签名。
依赖文件
aosp/out/host/linux-x86/framework/signapk.jar
aosp/build/make/target/product/security/platform.x509.pem
aosp/build/make/target/product/security/platform.pk8
apk签名示例
给asign-test.apk进行系统签名,生成签名apk为sign-test-out.apk
$ java -Djava.library.path=out/host/linux-x86/lib64 -jar out/host/linux-x86/framework/signapk.jar build/make/target/product/security/platform.x509.pem build/make/target/product/security/platform.pk8 sign-test.apk sign-test-out.apk