tags:

views:

50

answers:

1

Hi, I'm writing a plugin-enabled android application here. I have 2 applications(2 apk), one is main program and another is a plugin.

Now I want the plugin constructs it's own interface in main program's Activity. But I found the R.java in 2 applications has the same values:

The R.java in plugin:

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int button1=0x7f050000;
        public static final int button2=0x7f050001;
    }
    public static final class layout {
        public static final int widget=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
        public static final int button1text=0x7f040001;
        public static final int button2text=0x7f040002;
    }
}

And, R.java of main program:

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int mainWidgetLayout=0x7f050000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

Just as you can see, there are a lot of same values in these 2 R.java, this makes chaos. In plugin, if I wanna construct the interface via resource defined in R.java, it may refer to the same value in main program resource.

So, how to handle this? Is it possible to make the 2 R.java in 2 applications have different values? Thanks a lot. Any suggestions are appreciated.

A: 

I haven't done that myself, but the following thread might be of interest. Especially the part saying

Each resource identifier consists of 32 bits were 8 top bits defines the package in which the resource belongs to. Platform resources are 0x01 and 0x7F are application resources. The idea is to use the remaining 253 values for extension packages.

So you might be able to generate different resource identifiers using aapt -x (launch aapt without arguments to get a list of options).

Julien
Thank you, Julien. "aapt -x" works, I use this command and get a new R.java. Thanks. ~/Android/programs/android-sdk-linux_86/platforms/android-8/tools/aapt package -f -m -x -J ~/Android/workspace/AcsPluginGuiMainWidget/gen -S res -I ~/Android/programs/android-sdk-linux_86/platforms/android-8/android.jar -M AndroidManifest.xml
Eric