How to properly generate the R.java file for an Android library project when creating an APK from a pure Makefile?

To better understand how Android application development tools work, I started with a clean GNU Makefile to make the 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 basic knowledge). For small and simple application projects, this works very well, but I have some problems with some more complex applications.

In this particular case, there is an Android application that includes a separate library project containing both code and resources. When I use aapt to create an R.java file for a library project, it looks 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 is placed in gen / com / mycompany / myapp / mylibrary / R.java.

The command used to create the file is as follows.

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 shared R.java file for the main application project. This will also populate the resource identifiers for the library project (among other resources), but here the identifiers for the library project are different. (note that the "..." below indicates many other lines related to resources from other projects of the library / application 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 is 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

, , . , , , , . , , . ant , , -, , - ... - , ?

+4

Source: https://habr.com/ru/post/1665561/


All Articles