M. Smith
M. Smith

Reputation: 389

Integrating Google Analytics with Android App

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>

Upvotes: 3

Views: 1687

Answers (2)

Marc Bacvanski
Marc Bacvanski

Reputation: 1538

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.

Upvotes: 5

Javier Hinmel
Javier Hinmel

Reputation: 719

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

Upvotes: 0

Related Questions