Phonegap PluginManager无法使用--rename-manifest-package加载plugins / config.xml

时间:2012-12-12 12:30:23

标签: android cordova

我使用aapt的--rename-manifest-package生成env特定包。

See this question

包名 在生产中,我使用

com.xxx.app

对于uat env,我使用

com.xxx.app.uat

它工作正常,直到我添加了phonegap,我正在使用codorva 2.2,它给了我以下错误

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): =====================================================================================

我最终追溯到PluginManager中的代码

int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
...
XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);

id为0表示无法引用config.xml getActivity()。getPackgeName()给出替换的包名 - “ com.xxx.app.uat

它看起来像.getResources()。getIdentifer()没有更新到新包...它可能是来自android的错误吗?

在我的测试用例中, 如果我使用R.xml.config,它会引用config.xml而不会出现问题。

问题是我无法更改PluggManager,这是Phonegap代码库的一部分......

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误,但是我和Rick Li的处理方式不同。应用程序首先尝试使用上下文的包名称加载资源,如果这不起作用(id仍为0),则应用程序将尝试从活动的类包名称。

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;
            }
        }