命令行下面编译打包混淆对齐APK

由于IDE用不了,需要在命令行下面执行打包等一系列工作,由于我是基于源码编译的,那么我就从没有混淆的由makefile生成的中间文件classes.jar开始:

1.先对classes.jar进行混淆:

我的classes.jar的目录是在out/target/common/obj/APPS/XXX_intermediates/classes.jar

混淆命令,由于命令太长,省略了一部分classpath:

java -jar /home/easybd/kitkat/prebuilts/tools/common/proguard/proguard4.7/lib/proguard.jar @out/pop/KK$1/proguard.flags -injars out/pop/classes.jar -outjars out/pop/classes_p.jar -libraryjars /home/easybd/kitkat/vendor/easyandroid/packages/$1/libs/android.common.jar                                                                                                                                                                 -dontskipnonpubliclibraryclassmembers -optimizationpasses 5 -verbose -ignorewarnings

 

2.将jar包转成安卓的dex文件:

dx --dex --output=out/pop/classes.dex --no-optimize out/pop/classes_p.jar

 

3.打包apk

把makefile编译的中间文件package.apk文件拿出来二次利用:

package.apk文件在:out/target/product/generic/obj/APPS/KK$1_intermediates/package.apk.unsigned

A:先把package.apk里面的classes.dex 删除掉:

aapt r out/pop/package.apk classes.dex

B:再把我们第2步生成的classes.dex替换进去:

aapt add -k out/pop/package.apk out/pop/classes.dex

 

4.对APK进行签名(XXX是keystore密码)

echo的作用是避免在命令行中再手动输入keystore的密码。

echo "XXX" | jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore out/pop/apk.keystore out/pop/package.apk XXX

 

5.对APK进行优化,对齐

zipalign -v 4 out/pop/package.apk out/pop/KK$1/KK$1.apk

 

至此,我们需要的最终的APK生成了,收工。

 PS:试过直接打包APK的,但是没能成功,如下命令:

aapt package -u -z -M vendor/easyandroid/packages/Dialer/AndroidManifest.xml -S vendor/easyandroid/packages/Dialer/res -I out/target/common/obj/APPS/framework-res_intermediates/package-export.apk -F out/pop/package.apk

你可能感兴趣的:(apk)