Cordova-plugin-firebase: Error: Found item String/google_app_id more than one time

Created on 25 Aug 2017  ·  23Comments  ·  Source: arnesson/cordova-plugin-firebase

Breaking change in the new tag: "cordova-plugin-firebase": "^0.1.24",

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':mergeReleaseResources'.
    > /Users/zoltan/Developer/myProject/platforms/android/res/values/strings.xml: Error: Found item String/google_app_id more than one time

The content of strings.xml:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">My app name</string>
    <string name="launcher_name">@string/app_name</string>
    <string name="activity_name">@string/launcher_name</string>
    <string name="google_app_id">xxxxxxx---xxxxxxx</string>
    <string name="google_api_key">xxxxxxx---xxxxxxx</string>
    <string name="google_app_id">@string/google_app_id</string>
    <string name="google_api_key">@string/google_api_key</string>
</resources>

Most helpful comment

Remove this in strings.xml

<string name="google_app_id">Your API ID</string>
<string name="google_api_key">Your API KEY</string>
<string name="google_app_id">@string/google_app_id</string>
<string name="google_api_key">@string/google_api_key</string>

Work for me

All 23 comments

you probably have another plugin that is also adding google_app_id and google_api_key

I faced same problem too in 0.1.24. ~And this problem occurs only release build.~
I don't have another plugin that is also adding google_app_id and google_api_key.

To reproduce the issue:

  1. delete the plugins, and platform folder
  2. add the platform android
  3. add the platform ios
  4. try to build the android version

The problem is, that if the ios platform added, then the after_prepare file runs again.
Also it tries:
if (directoryExists(IOS_DIR)) { copyKey(PLATFORM.IOS); } else if (directoryExists(ANDROID_DIR)) { copyKey(PLATFORM.ANDROID, updateStringsXml) }

So the copyKey(PLATFORM.ANDROID, updateStringsXml) runs,
it copies the keys, then in the function exception happens, so the callback function won't be called.

Anyone found the solution of this problem. I tried removing few lines from plugin.xml after which build was successful but i saw below error in logs:
GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id.

hi, i also have this issue, the version 0.1.22 is the last working for me

@zerdos confirmed, good analysis.

I was doing cordova platform add android before cordova platform add ios ... now it works.

I get this problem every time I do cordova build android, it re-adds the google_app_id / key to res/values/strings.xml every time, and so the build fails.

@inidona downgrading to 0.1.22 also worked for me.

I get the same problem. However, I notice that the content of actual after_prepare is newer than the version of the npm package, though the script was merged in the same date of version ?

$ cordova clean android worked here

The problem I believe is this in the config:-

<config-file parent="/resources" target="res/values/strings.xml">
    <string name="google_app_id">@string/google_app_id</string>
</config-file>
<config-file parent="/resources" target="res/values/strings.xml">
    <string name="google_api_key">@string/google_api_key</string>
</config-file>

Not sure what that is attempting to achieve but I changed mine to

<preference name="API_KEY"/>
<preference name="APP_ID"/>

<config-file parent="/resources" target="res/values/strings.xml">
    <string name="google_app_id">$APP_ID</string>
    <string name="google_api_key">$API_KEY</string>
</config-file>

and I install the plugin by adding

cordova plugin add ../plugins/my-firebase-plugin --variable APP_ID=my-app-id --variable API_KEY=my-api-key

and it works fine now.

I made a change to thecordova-plugin-firebase/scripts/after_prepare.js so that both ios and android get copied if they both exist.

if (directoryExists(IOS_DIR)) {
    copyKey(PLATFORM.IOS);
}

if (directoryExists(ANDROID_DIR)) {
    copyKey(PLATFORM.ANDROID, updateStringsXml);
}

Same issue! Any solution?
Firstly I copy the google-services.js after that I add the plugin via cli and and i build it. and I got the above error....

@rabinski99 this a very good suggestion!

Remove this in strings.xml

<string name="google_app_id">Your API ID</string>
<string name="google_api_key">Your API KEY</string>
<string name="google_app_id">@string/google_app_id</string>
<string name="google_api_key">@string/google_api_key</string>

Work for me

@stephdgenius Excellent! that is the correct solution, delete and nothing else. It worked for me. Thank you very much!

Your API ID
Your API KEY
@string/google_app_id
@string/google_api_key

@stephdgenius @pamelita04
i removed it, but now i am getting this error.
Error: Cannot set property 'text' of null

Updating strings.xml or any file created during the build is not a solution it is a workaround of an issue. We need reliable repeatable builds without manually having to update files.

https://github.com/arnesson/cordova-plugin-firebase/issues/407#issuecomment-337633326

Is reliable, and repeatable and doesn't require manually updating files.

I removed and re-added android platform, the error( Found item String/google_app_id more than one time) disappeared.

cordova platform rm android
cordova platform add android

I think I have found the cause of the issue, please see this issue https://github.com/phonegap/phonegap-plugin-push/issues/1660.

Essentially it happens if you are using version < 2.0 of the phonegap-plugin-push cordova plugin, so obviously there is going to be a conflict whatever version of this plugin is used (I tried with 0.1.22, but even that did not work).

Also see https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md#co-existing-with-plugins-that-use-firebase

closing for now, reopen if still an issue with the latest version of the plugin

hi there,
kindly help me please resultTextview always error why?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    Button addBtn = (Button) findViewById(R.id.addBtn);
    addBtn.setOnClickListener(new View.OnClickListener()){
        @Override
        public void OnClick(View View){
            EditText FirstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
            EditText SecondNumEditText = (EditText) findViewById(R.id.secoundNumEditText);
            TextView Result = (TextView)findViewById(R.id.resultTextview);

            int num1 = Integer.parseInt(FirstNumEditText.getText() .toString());
            Resources secoundNumEditText;
            int num2 = Integer.parseInt(secoundNumEditText.getText() .toString());
            int result = num1 + num2;
            int result = num1 / num2;
            int result = num1 * num2;
            resultTextview.SetText{result + "");

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    Button addBtn = (Button) findViewById(R.id.addBtn);
    addBtn.setOnClickListener(new View.OnClickListener()){
        @Override
        public void OnClick(View View){
            EditText FirstNumEditText = (EditText) findViewById(R.id.firstNumEditText);
            EditText SecondNumEditText = (EditText) findViewById(R.id.secoundNumEditText);
            TextView Result = (TextView)findViewById(R.id.resultTextview);

            int num1 = Integer.parseInt(FirstNumEditText.getText() .toString());
            Resources secoundNumEditText;
            int num2 = Integer.parseInt(secoundNumEditText.getText() .toString());
            int result = num1 + num2;
            int result = num1 / num2;
            int result = num1 * num2;
            resultTextview.SetText{result + "");

erro the resultTextView here i don't no reson why?

Was this page helpful?
0 / 5 - 0 ratings