How to fix the error: duplicate resources for global_tracker.xml when adding Google Analytics?

I am trying to implement Google Analytics in my application, but when compiling I get the following error:

Error: execution completed for task ': app: mergeDebugResources'. [XML / global_tracker] C: \ Users \ Carlos \ AndroidStudioProjects \ Capstone \ SP \ Stocks Panel Lite \ app \ src \ main \ res \ xml \ global_tracker.xml [xml / global_tracker] C: \ Users \ Carlos \ AndroidStudioProjects \ Capstone \ SP \ Stocks Panel Lite \ application \ assembly \ generated \ Res \ Google services \ Debug \ XML \ global_tracker.xml: Error: duplication of resources

I tried to run a clean project, but getting the same error. I also get the same error if I remove app / build.

Thanks in advance.

UPDATE: build.gradle

apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 23 buildToolsVersion "23.0.2" useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "com.carlos.capstone" minSdkVersion 11 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' } } repositories { mavenCentral() maven { url "https://jitpack.io" } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:gridlayout-v7:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:support-annotations:23.1.1' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' compile 'io.reactivex:rxandroid:1.0.1' compile 'io.reactivex:rxjava:1.1.1' compile 'com.squareup.okhttp:logging-interceptor:2.6.0' compile 'com.github.PhilJay:MPAndroidChart:v2.1.6' compile 'com.bignerdranch.android:expandablerecyclerview:2.0.4' compile 'com.crazyhitty.chdev.ks:rss-manager:0.21' compile 'com.github.frankiesardo:linearlistview: 1.0.1@aar ' compile 'com.github.bumptech.glide:glide:3.5.2' compile 'com.facebook.stetho:stetho-urlconnection:1.3.1' compile 'com.facebook.stetho:stetho:1.3.1' compile 'com.android.support:customtabs:23.0.0+' compile 'com.squareup.leakcanary:leakcanary-android:1.3.1' compile 'org.apache.commons:commons-lang3:3.1' compile 'org.apache.poi:poi:3.14' compile 'net.sf.supercsv:super-csv:2.4.0' compile 'com.google.android.gms:play-services-gcm:8.3.0' compile 'com.google.android.gms:play-services-analytics:8.3.0' } 
+7
android android-resources google-analytics-v4
source share
1 answer

This happens if you put global_tracker.xml in your xml resources folder and in addition to that add apply plugin: 'com.google.gms.google-services' to your build.gradle file. The solution is to simply remove global_tracker.xml from your xml folder, as the google-services plugin will automatically add all the necessary data from the google-services.json configuration file when creating your application.

It is also recommended that you place the line apply plugin: 'com.google.gms.google-services' at the bottom of your build.gradle after the dependency section. This is strange, but the presence at the top causes errors in some configurations. Hope this helps.

+15
source share

All Articles