3

I'm setting up an existing app with some of the activity tracking events offered through Google Analytics. I've added all the gradle changes and what not, but I keep getting an error related to having duplicate google_app_ids. I know one of the ids comes from using Google Maps in my app originally. I believe I may have been given a new google_app_id from the one auto generated from the google-services.json file you have to add for Google Analytics. I'm not sure how to fix it.

Here's the error I get when trying to build:

Error:Execution failed for task ':app:mergeDebugResources'.
> [string/google_app_id] C:\Users\smithm24\AndroidStudioProjects\NOAAHSO\app\src\main\res\values\strings.xml    [string/google_app_id] 
C:\Users\smithm24\AndroidStudioProjects\NOAAHSO\app\build\generated\res\google-services\debug\values\values.xml: Error: Duplicate resources

Here is my values.xml, which is the auto generated file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="ga_trackingId" translatable="false">UA-76597942-1</string>
    <string name="gcm_defaultSenderId" translatable="false">287841560662</string>
    <string name="google_app_id" translatable="false">1:287841560662:android:18d8b4b538346094</string>
</resources>

Here is my strings.xml with my app id I added a long time ago for Google Maps:

<resources>
    <string name="app_name">Weather AND Haul Route</string>
    <string name="action_settings">Settings</string>
    <string name="button_text">Get Weather</string>
    <string name="title_activity_maps">Map</string>
    <string name="google_app_id">380060644351</string>
</resources>
M. Smith
  • 379
  • 1
  • 20
  • You have in both files. Try removing 380060644351 or rename it from strings.xml – Slobodan Antonijević Apr 20 '16 at 20:52
  • Would that mess up my google maps stuff. I looked on the google developer portal and it looks like I was given a new id for a new project when I signed up for the google analytics. Is there any way to integrate the two? – M. Smith Apr 20 '16 at 20:59
  • Did you sign up for analytics from the same account for maps API? – Slobodan Antonijević Apr 20 '16 at 21:10
  • Try going to Project->Clean Project... – Isaac Urbina Apr 21 '16 at 03:05
  • @SlobodanAntonijević Yes I did, in my developers portal it looks like two seperate projects. When I signed up for analytics I don't believe it gave me the option to integrate it with my pre-existing project – M. Smith Apr 21 '16 at 13:13
  • I don't think this should mess anything up, your strings.xml was created by you and not generated. Could you try deleting the entry from strings and see the result? – Slobodan Antonijević Apr 21 '16 at 13:53
  • @SlobodanAntonijević yea taking the string out worked and my map still worked. Still confused on how my map was working if I removed my app_id...oh well lol – M. Smith Apr 22 '16 at 15:52

2 Answers2

5

You have the same descriptor in both your own strings.xml as well as the Google provided values.xml, which confuses Gradle of which descriptor to use. Simply rename your own google_app_id resource to another name.

Marc Bacvanski
  • 1,458
  • 4
  • 17
  • 33
0

I had the same problem. Just delete the generated file analytics.xml, clean your project. After that, it's worked

Javier Hinmel
  • 599
  • 6
  • 9