[英]How to build runnable apk with aapt2?
I have a simple android project . 我有一个简单的android 项目 。 This commands compile resources and build apk without dex:
这个命令编译资源并构建没有dex的apk:
aapt2 compile project/res/values/strings.xml project/res/layout/activity_main.xml -o project/compiled_res
aapt2 link -o project/apk/unsigned_app.apk -I sdk/platforms/android-28/android.jar --manifest project/src/AndroidManifest.xml -R project/compiled_res/*.flat --java project/src --auto-add-overlay
Quote from documentation : 引用文档 :
However, the generated APK does not contain DEX bytecode and is unsigned
但是,生成的APK不包含DEX字节码,并且未签名
......
you can use other command line tools, such as d8 to compile Java bytecode into DEX bytecode and apksigner to sign your APK.您可以使用其他命令行工具,例如d8,将Java字节码编译为DEX字节码,然后使用apksigner签名APK。
Ok. 好。 I can:
我可以:
d8 project/compiled_classes/com/illuzor/buildtest/*.class --output project/dex
But how to pack this dex to apk? 但是如何将这种dex打包为apk? aapt2 can`t recognize classes.dex:
aapt2无法识别classes.dex:
I can just add classes.dex to my apk by zipping: 我可以通过压缩将classes.dex添加到我的apk中:
zip -uj project/apk/unsigned_app.apk project/dex/classes.dex
And it works after aligning and signing. 对齐并签名后即可使用。 But must be another way, more proper.
但是必须是另一种方式,更合适。
I'm looking for a proper way too. 我也在寻找合适的方法。 But I have no luck even it is 2019 now, and I searched everywhere, for days.
但是即使到了2019年,我也没有运气,我到处搜寻了好几天。
I guess aapt add
will get the job done, but your solution with zip
is not bad. 我猜
aapt add
可以完成工作,但是您的zip
解决方案还不错。
Hope aapt
won't be deprecated soon, or aapt2
should get enhanced before that happens. 希望
aapt
不会很快被弃用,否则aapt2
应该在此之前得到增强。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.