2

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.
saxzez
  • 102
  • 9

1 Answers1

2

You're trying to provide the resources the way you'd provide an APK (e.g. 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, e.g. compiled/*).

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

Izabela Orlowska
  • 7,431
  • 2
  • 20
  • 33
  • How do I include `apk/lib/armeabi-v7a/libMyApp.so` in the apk? I tried `-A`, but this puts it in an `assets` sub-folder. Right now I have an apk with no .so. – saxzez Dec 20 '20 at 06:43
  • Your suggestion to use -R was right, but I still have not fully converted to aapt2 because I can't include my native .so file. – saxzez Dec 20 '20 at 07:25
  • Yeah aapt2 is only used for the rest/ directory. For assets and other files just zip them into an .APK and continue with zipalign etc. – Izabela Orlowska Dec 21 '20 at 10:22
  • I created an apk with everything but the .so and then tried just adding the .so to the apk, but the app doesn't run on my phone (crashes immediately). Is there any magic to adding a .so to an apk with zip? Have you heard of anyone doing this successfully? I guess what we're concluding here is that aapt2 is not used for native build apk creation? – saxzez Dec 21 '20 at 16:14
  • I'm not certain... I think it has to be in the correct directory in the APK, e.g. /libs? Have a look at the old APK created by aapt, and make sure you put it into exactly the same path. – Izabela Orlowska Dec 21 '20 at 17:47
  • Also double check if they're STORED or DEFLATED. – Izabela Orlowska Dec 21 '20 at 17:47
  • Thanks, I'll check the STORED vs DEFLATED. The lib is in the same directory (e.g. `libs/armeabi-v7a/libMyApp.so`). The only thing I remember seeing that was different was the order of the apk elements, but the locations were all the same. – saxzez Dec 21 '20 at 21:45
  • Yep, they are the same between packages as far as inflating vs extracting. Only difference is the order in which the files appear. :( What magic am I missing??? – saxzez Dec 21 '20 at 22:48
  • I'm having the same issue, my vs project spits out .so and .a libs for arm64-v8a just fine, I wrote an ant post build step the apk gets created and resources copied but an empty libs folder is generated. No idea where appt or zipalign or whatever handles it tries to look for any native libs. I so want to avoid Grade and I do not need a build step as I already do it in VS 2022. – Sixjac Mar 11 '22 at 12:59
  • @saxzez did you figure out how to get appt to find your prebuilt native libs so it packages them into the apk? – Sixjac Mar 11 '22 at 13:08