简体   繁体   中英

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>

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM