0

在我的 Android Studio 项目中添加 Firebase 分析时出现以下错误:“错误:将字节码转换为 dex 时出错:原因:com.android.dex.DexException:多个 dex 文件定义 Lcom/google/android/gms/measurement/AppMeasurementContentProvider ;"

如果有人告诉我额外的 AppmeasurementContentProvider 来自哪里以及相应的“排除”命令,我真的很感激。

这是我的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"

lintOptions {
    abortOnError false
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
    exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
    exclude 'com.google.android.gms.measurement'

}
defaultConfig {
    applicationId "com.elisiumlabs.sarthi"
    minSdkVersion 10
    targetSdkVersion 19
    testInstrumentationRunner    "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.txt'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

}

dependencies {

compile project(':androidQuery')
compile project(':pinnedSectionListActivity')
compile project(':volley')
compile project(':facebookSDK')
compile 'com.google.code.gson:gson:2.2.4'
compile 'joda-time:joda-time:2.3'
compile 'com.android.support:gridlayout-v7:21.0.0'
compile "com.google.android.gms:play-services-location:8.3.0"
// compile "com.google.android.gms:play-services-gcm:8.3.0"
compile 'com.android.support:appcompat-v7:21.0.3'


compile('com.google.android.gms:play-services-gcm:8.3.0') {
    exclude group: 'com.google.android.gms.measurement'
}
compile('com.google.firebase:firebase-core:9.0.2')
        {
           exclude group: 'com.google.android.gms.measurement'
        }
/*compile files('libs/appcompat_v7.jar')*/
compile files('libs/commons-io-1.4.jar')
compile files('libs/commons-lang-2.4.jar')
compile files('libs/httpclient-4.3.5.jar')
/*compile files('libs/objectify-5.0.3.jar')*/
compile 'commons-codec:commons-codec:1.9'
compile files('libs/splunk-mint-4.1.jar')
testCompile 'junit:junit:4.12'
// androidTestCompile 'com.android.support:support-annotations:21.0.0'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
/*  androidTestCompile('com.android.support.test.espresso:espresso-    core:2.2.1') {
    // Necessary if your app targets Marshmallow (since Espresso
    // hasn't moved to Marshmallow yet)
    exclude group: 'com.android.support', module: 'support-annotations'
}*/
androidTestCompile('com.android.support.test.espresso:espresso-   contrib:2.2.2') {
    // Necessary if your app targets Marshmallow (since Espresso
    // hasn't moved to Marshmallow yet)
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'javax.inject'
    exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2'){
    // Necessary if your app targets Marshmallow (since Espresso
    // hasn't moved to Marshmallow yet)
    exclude group: 'com.android.support', module: 'support-annotations'
}
// Optional -- UI testing with UI Automator
  androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.1'){
      // Necessary if your app targets Marshmallow (since the test runner
      // hasn't moved to Marshmallow yet)
      exclude group: 'com.android.support', module: 'support-annotations'
  }


}
configurations.all {
resolutionStrategy {
    force 'com.android.support:support-annotations:23.0.1'
}
}
4

4 回答 4

0

我真的不认为你可以混合使用 GCM 和 FCM,因为 FCM 是新的 GCM。从逻辑上讲,它们必须共享一个几乎相似的 api 才能互通。

您应该选择 FCM 或 GCM。从您的 build.gradles 看起来您使用 gcm。所以删除 FCM 代码。删除这些行:

compile('com.google.firebase:firebase-core:9.0.2')
{
   exclude group: 'com.google.android.gms.measurement'
}

阅读Setting Up Google Play Services中的 GCM 播放服务设置和Add Firebase to your Android Project中的 FCM 。

于 2016-06-27T16:02:30.593 回答
0

当我尝试并且版本级别不匹配时,Android Studio 会发出以下警告:

请通过更新 google-services 插件的版本来修复版本冲突(有关最新版本的信息可在https://bintray.com/android/android-tools/com.google.gms.google-services/获得)

因此,设置为相同的版本级别可以解决相互不兼容的依赖关系

    compile('com.google.android.gms:play-services-gcm:11.8.0')
    compile('com.google.firebase:firebase-core:11.8.0')
于 2018-01-11T20:30:05.443 回答
0

试试我的回答......

链接在这里

Android Studio Gradle 错误:使用 Ion koush lib 执行任务“:app:dexDebug”失败

请把谷歌服务作为我的答案,并在你的 gradle 中添加一些代码,如图所示还在你的主要文件中添加一些代码

如答案所示

首先编译构建

编译'com.android.support:multidex:1.0.1'

编译 'com.google.android.gms:play-services:+'

在你的AndroidManifest.xml添加这行android:name

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication"
    >

并且在您的build.gradle 中还添加

dexOptions {
    //incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g"
}
于 2016-06-27T14:44:50.777 回答
0

使用 Gradle 为 Multidex 配置您的应用程序参考https://developer.android.com/studio/build/multidex.html#mdex-gradle

修改模块级别的 build.gradle 文件配置以包含支持库并启用 multidex 输出,如以下代码片段所示:

android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
    ...
    minSdkVersion 14
    targetSdkVersion 21
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
...
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

扩展 Application 类,您可以重写 attachBaseContext() 方法并调用 MultiDex.install(this) 以启用 multidex。有关详细信息,请参阅 MultiDexApplication 参考文档。

于 2016-06-27T14:36:22.693 回答