My project (made in Delphi) need to manually generate for each package it's include the R.java file manually. Actually I put all resources of each library in a single .res directory and I run aapt.exe on this directory for each package like this for android.support.compat:
"aapt.exe" package -v -f -m
-M "\libraries\android.support.compat\AndroidManifest.xml"
-I "C:\SDKs\android\platforms\android-32\android.jar"
-S ".\res"
-J ".\tmp\src"
--auto-add-overlay
--output-text-symbols .\tmp\
and this for each package ex for android.support.coreui
"aapt.exe" package -v -f -m
-M "\libraries\android.support.coreui\AndroidManifest.xml"
-I "C:\SDKs\android\platforms\android-32\android.jar"
-S ".\res"
-J ".\tmp\src"
--auto-add-overlay
--output-text-symbols .\tmp\
The problem is that at the end I have for each package the same R.java that is quite big because it's include all resources ids of the whole App. ex :
package androidx.core;
public final class R {
public static final class styleable {
public static final int[] ActionBar = new int[]{2130771969, 2130771971, 2130771972, 2130771973, 2130771974, 2130771975, 2130771976, 2130771977, 2130771978, 2130771979, 2130771980, 2130771981, 2130771982, 2130771983, 2130771984, 2130771985, 2130771986, 2130771987, 2130771988, 2130771989, 2130771990, 2130771991, 2130771992, 2130771993, 2130771994, 2130771995, 2130771996, 2130771997, 2130772082};
public static final int ActionBar_background = 10;
public static final int ActionBar_backgroundSplit = 12;
....
and
package android.support.coreui;
public final class R {
public static final class styleable {
public static final int[] ActionBar = new int[]{2130771969, 2130771971, 2130771972, 2130771973, 2130771974, 2130771975, 2130771976, 2130771977, 2130771978, 2130771979, 2130771980, 2130771981, 2130771982, 2130771983, 2130771984, 2130771985, 2130771986, 2130771987, 2130771988, 2130771989, 2130771990, 2130771991, 2130771992, 2130771993, 2130771994, 2130771995, 2130771996, 2130771997, 2130772082};
public static final int ActionBar_background = 10;
public static final int ActionBar_backgroundSplit = 12;
Is there a way to generate for each package a R.java with only the resource ids need by the package?
You can (and should) use at least one of these:
The code shrinker r8, which has been introduced to replace ProGuard (together with d8 which replaced dx). For a start take a look at the corresponding Android Dev Docs on how to shrink, obfuscate, and optimize your app and this guide. Especially the doc's section on resource shrinking may be of interest.
The code inspector lint will help you to find various problems with the code, inter alia unused resources which also unnecessarily bloat your
R.javafile.For an elaboration on purpose and structure of resource IDs in
R.javayou might take a look at this Stackoverflow thread.Note, that it's highly unrecommended to manipulate
R.javamanually. As it is written in B.Burd & J.P.Mueller, Android Application Development All-in-One For Dummies, 3rd Ed., 2020, Wiley, pp.87 (a serious book, despite the name) in respect toR.javaand Android Studio:as well as
and finally
Though I don't agree on such kind of paternalism, one really shouldn't manually edit
R.java(even if one could when not using Android Studio, like in your case). As I've put it once somewhere:The last sentence would also be valid in your case.