Reputation: 1477
I use aapt's --rename-manifest-package to generate env specific packages.
the package names in prod, I use
com.xxx.app
for uat env, I use
com.xxx.app.uat
it works fine until I added phonegap, I'm using codorva 2.2, it gives me below error
12-12 19:02:36.156: E/PluginManager(13188): =====================================================================================
12-12 19:02:36.156: E/PluginManager(13188): ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.
12-12 19:02:36.156: E/PluginManager(13188): https://git-wip-us.apache.org/repos/asf? p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml
12-12 19:02:36.156: E/PluginManager(13188): =====================================================================================
I finally traced down to below code in PluginManager
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
...
XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
the id is 0 which means it failed to reference the config.xml getActivity().getPackgeName() gives replaced package name - "com.xxx.app.uat"
it looks like .getResources().getIdentifer() was not updated to new package... could it be a bug from android?
In my test case, if I use R.xml.config, it referenced config.xml without issues.
the problem is I can't change PluginsManager which is a part of Phonegap codebase...
Upvotes: 1
Views: 1089
Reputation: 766
I've experienced the same bug, but I approached it differently then Rick Li. The app first tries to load the resource using the context's package name, if that does not work (id still 0), the app tries from the activity's class package name.
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
if (id == 0) {
// could not find the resource id, maybe we are using the wrong package name ? (the package name could have been changed via aapt at build time).
id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getClass().getPackage().getName());
if(id == 0){
this.pluginConfigurationMissing();
//We have the error, we need to exit without crashing!
return;
}
}
Upvotes: 1