如何修复错误:添加Google Analytics时,global_tracker.xml的资源是否重复?

Car*_*Gil 12 android android-resources google-play-services google-analytics-firebase

我正在尝试在我的应用中实施Google Analytics,但在编译时我收到以下错误:

错误:任务':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\app\build\generated\res\google-services\debug\xml\global_tracker.xml:错误:重复资源

我试图运行干净的项目,但我得到了同样的错误.如果我删除app/build,我也会得到同样的错误.

提前致谢.

更新: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'

}
Run Code Online (Sandbox Code Playgroud)

Lev*_*von 19

出现这种情况,当你把一个global_tracker.xml在你的资源的xml文件夹中,除了添加apply plugin: 'com.google.gms.google-services'在您的build.gradle文件.这就是将实现跟踪器的旧方法与新的工作方式混合在一起.解决方案是简单地global_tracker.xml从xml文件夹中删除,因为google-services插件会google-services.json在构建应用程序时自动添加配置文件中的所有必需数据.

此外,建议将apply plugin: 'com.google.gms.google-services'行放在build.gradle依赖项部分之后的底部.这很奇怪,但将它放在顶部会导致某些配置出错.

此外,您可能会看到错误:在尝试构建项目时找不到符号变量global_tracker,尤其是在转换旧项目时,google-services.json从Firebase控制台下载并同时使用旧版Google Analytics时.在这种情况下,打开新添加的google-services.json并在"services"对象中找到"analytics_service".您需要添加以下内容:

"analytics_property": {
    "tracking_id": "<your tracking id>"
Run Code Online (Sandbox Code Playgroud)

所以整个部分看起来像这样(在那里放置你自己的UA-XXXXXXXX-X跟踪ID):

"analytics_service": {
  "status": 2,
  "analytics_property": {
      "tracking_id": "UA-12345678-9"
  }
},
Run Code Online (Sandbox Code Playgroud)

之后,请确保在重建之前清理项目并重新同步Gradle.希望有所帮助.