Search code examples
javaandroidjarlibgdxapk

Building an Android APK by hand, external Jar's resource files


I'm building an apk manually with aapt, dx etc.

I have some external jar files, I'm using LibGDX, gdx includes some resource files in its classpath (in the jar file itself) when i compile the code, dx only processes the .class files and discards resources (for example gdx has a default font at com/badlogic/gdx/utils/arial-15.png in the jar file) I'm wondering how do i get to bundle those resource files too, i extracted an apk of another game made with gdx and seems like those files are placed in the root of the apk like apkroot/com/badlogic/gdx/.. how does IDEs do that, do i have to manually extract the jar files and get the resources?


Solution

  • It's been a while and no one answered me, until then i kept experimenting with various stuff, and i finally found a way that is not extracting manually, so basically on my build flow instead of letting aapt make the initial apk file i make it with dx instead i.e

    dx --dex --verbose --num-threads=4 --output=file.apk obj libs/dex
    

    obj is the folder containing compiled .class files from my code, libs/ includes external jar files, libs/dex holds cached jars of libs/ that are already dexed before for quicker builds, by letting dx make the initial apk it can also bundle the resources in the apk now the apk has the resources as expected, then we use aapt after dx (actually we use it once before dx for generating R.java to be clear but DO NOT create the apk with aapt) with aapt we use package command as always but include the -u flag so it modifies the apk and not rewrite it, now we can package normal android resource stuff and also the external jar's resources in the final apk. to be clear this wasn't meant to be a full clear guide of making an apk by hand you are expected to know aapt/dx toolchain already, I'm just explaining a workaround with the toolchain that solves my problem.