Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 640
M. Smith Avatar asked Jul 25 '26 06:07

M. Smith


1 Answers

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.

like image 77
Marc Bacvanski Avatar answered Jul 28 '26 13:07

Marc Bacvanski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!