In order to understand better how the Android app development tools work, I started on a pure GNU Makefile in order to create an APK completely independent of ant or gradle. From this Makefile I call low-level tools (plumber commands) such as aapt, javac, jarsigner, zipalign, dalvik-exchange, aidl. (I refer to https://spin.atomicobject.com/2011/08/22/building-android-application-bundles-apks-by-hand/ for some background knowledge) For small and straightforward app projects, this is now working very well, but I have some issues with some more complicated apps.
In this particular case, there is an Android app which includes a separate library project containing both code and resources. When I use aapt to generate the R.java file for the library project, it turns out like this:
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mycompany.myapp.mylibrary;
public final class R {
public static final class attr {
}
public static final class drawable {
public static int image1=0x7f020000;
public static int image2=0x7f020001;
public static int image3=0x7f020002;
public static int image4=0x7f020003;
}
public static final class raw {
public static int indexes=0x7f030000;
public static int vertices=0x7f030001;
}
}
and the file gets placed in gen/com/mycompany/myapp/mylibrary/R.java.
The command used to create the file looks like this.
aapt package --non-constant-id -f -m -0 apk --output-text-symbols ../MyLibraryProject/bin -M ../MyLibraryProject/AndroidManifest.xml -S ../MyLibraryProject/res -I /usr/lib/android-sdk/platforms/android-16/android.jar -J ../MyLibraryProject/gen --generate-dependencies -G ../MyLibraryProject/bin/proguard.txt
Later, I create a common R.java for the main App project. This one will also fill in the resource IDs for the library project (among with other resources), but here the IDs for the library project are different. (note that "..." below indicates many other lines related to resources from other library projects / the app project itself)
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mycompany.myapp.mylibrary;
public final class R {
...
public static final class drawable {
...
public static final int image1=0x7f02006f;
public static final int image2=0x7f020070;
public static final int image3=0x7f020073;
public static final int image4=0x7f020074;
...<
}
public static final class raw {
public static final int indexes=0x7f040000;
public static final int vertices=0x7f040001;
}
...
}
The file gets placed in gen/com/mycompany/myapp/R.java. To generate this file, I run:
aapt package -f -m -0 apk --output-text-symbols bin --auto-add-overlay -M AndroidManifest.xml -S res -S ../MyLibraryProject/bin/res -S ../MyLibraryProject/res -I /usr/lib/android-sdk/platforms/android-16/android.jar -J gen --generate-dependencies -G bin/proguard.txt
What puzzles me is that the resource IDs are different in these two cases. I have noticed that in order to get the App to work, I will have to modify the first file and change the IDs to what they are in the last file. I have yet to find any plumber tool that does this automatically, so I feel a need to write a custom tool to do that job. But when building with ant this obviously happens automatically somehow, so I think I must be missing something... Can anyone tell me what I am missing?