简体   繁体   中英

Switch from aapt to aapt2 for native app packaging

We have a great build system, so we're not looking to use gradle. Right now, we use appt to build an APK and it works great and the APK runs well. I see that aapt2 is the future, though, and so we'd like to move to it before we're forced to.

What we currently do:

  1. We have a simple icon in res/mipmap/our_icon.png
  2. We have our ./AndroidManifest.xml file
  3. We have our libMyApp.so stored in apk/lib/armeabi-v7a/libMyApp.so
  4. We build using the following command: aapt package -f -M AndroidManifest.xml -S ./res -I /opt/android-sdk/platforms/android-28/android.jar -F my app-unsigned.apk apk/

We then zipalign and sign using apksigner and the app loads just fine. As you can see, all very simple and gives us just what we need.

I've tried the following with aapt2, but of course it is incorrect:

aapt2 compile ./res/mipmap/our_icon.png -o ./compiled
aapt2 link -v -I /opt/android-sdk/platforms/android-28/android.jar -I compiled/mipmap_our_icon.png.flat --manifest AndroidManifest.xml -o MyApp-unsigned.apk
note: including compiled/minmap_our_icon.png.flat.
error: failed to open APK: Invalid file.

You're trying to provide the resources the way you'd provide an APK (eg android.jar):

-I compiled/mipmap_our_icon.png.flat

To pass compiled resources use the -R flag (per each resource or use the wildcard * if you want to pass the whole directory, eg compiled/* ).

You can find more info on differences between aapt and aapt2 in my old answer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM