gpt4 book ai didi

android - 添加 Google Analytics 时如何修复错误 : Duplicate resources for global_tracker. xml?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:08 24 4
gpt4 key购买 nike

我正在尝试在我的 App 中实现 Google Analytics,但在编译时出现以下错误:

Error:Execution failed 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\app\build\generated\res\google-services\debug\xml\global_tracker.xml: Error: Duplicate resources

我尝试运行干净的项目,但我遇到了同样的错误。如果我删除 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'

}

最佳答案

当您在资源 xml 文件夹中放置一个 global_tracker.xml 并且除此之外添加 apply plugin: 'com.google.gms.google-services' 时会发生这种情况> 在你的 build.gradle 文件中。那就是将实现跟踪器的旧方法与新的做事方式混合起来。解决方案是简单地从您的 xml 文件夹中删除 global_tracker.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>"

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

"analytics_service": {
"status": 2,
"analytics_property": {
"tracking_id": "UA-12345678-9"
}
},

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

关于android - 添加 Google Analytics 时如何修复错误 : Duplicate resources for global_tracker. xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36496785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com