java - 无法在 Android Studio 上构建应用程序,谷歌服务冲突

标签 java android android-studio react-native firebase-cloud-messaging

我正在使用 React Native 开发一个应用程序,并且想使用 React Native FCM 库,但由于某种原因,我在构建应用程序时遇到了困难!

我的应用程序 gradle 如下所示:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 26
  buildToolsVersion '26.0.2'

  defaultConfig {
    applicationId "fi.x.y"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    ndk {
      abiFilters 'armeabi-v7a', 'x86'
    }
    manifestPlaceholders = [
      'appAuthRedirectScheme': 'fi.x.y'
    ]
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  dexOptions {
    javaMaxHeapSize "8g"
  }
  lintOptions {
    abortOnError false
  }
}

task exponentPrebuildStep(type: Exec) {
  workingDir '../../'

  if (System.getProperty('os.name').toLowerCase().contains('windows')) {
    commandLine 'cmd', '/c', '.\\.expo-source\\android\\detach-scripts\\prepare-detached-build.bat'
  } else {
    commandLine './.expo-source/android/detach-scripts/prepare-detached-build.sh'
  }
}
preBuild.dependsOn exponentPrebuildStep

repositories{
  flatDir{
    dirs "../../node_modules/react-native-background-geolocation/android/libs"
  }
  mavenLocal()
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile(project(':react-native-firebase')) {
        transitive = false
    }
    compile project(':react-native-vector-icons')
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:multidex:1.0.2'

  compile 'com.google.android.gms:play-services:11.6.2'
  compile 'com.google.android.gms:play-services-location:11.6.2'
  compile 'com.google.android.gms:play-services-places:11.6.2'
  compile 'com.google.android.gms:play-services-maps:11.6.2'
  compile 'com.google.android.gms:play-services-ads:11.6.2'
  compile project(':react-native-fcm')
  compile 'com.google.firebase:firebase-core:11.6.2' //this decides your firebase SDK version

  compile('host.exp.exponent:expoview:22.0.0@aar') {
    exclude group: 'com.facebook.android', module: 'facebook-android-sdk'
    exclude group: 'com.facebook.android', module: 'audience-network-sdk'
    exclude group: 'io.nlopez.smartlocation', module: 'library'
    transitive = true
  }

  compile ('com.facebook.android:facebook-android-sdk:4.+')
  compile('com.facebook.android:audience-network-sdk:4.+') {
    exclude module: 'play-services-ads'
  }
  compile('io.nlopez.smartlocation:library:3.2.11') {
    transitive = false
  }
  compile(project(':react-native-background-geolocation')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
  }
  compile(name: 'tslocationmanager', ext: 'aar') {
    exclude group: 'com.google.android.gms'
  }
  compile "com.google.firebase:firebase-messaging:11.6.2"


}
apply plugin: 'com.google.gms.google-services'

我在 Android Studio 中遇到的错误: 所有 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 11.8.0、11.6.2、11.6.0。示例包括 com.google.android.gms:play-services-basement:11.8.0 和 com.google.android.gms:play-services-ads:11.6.2 更多...

有了这个警告,似乎构建成功了,但是当我尝试运行该应用程序时,我收到错误消息:错误:任务执行失败

':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {
  repositories {
    jcenter()
    google()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.google.gms:google-services:3.1.1'
    classpath 'com.google.gms:google-services:3.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    mavenLocal()
    jcenter()
    maven {
      // Point to local maven repository
      url "$rootDir/../.expo-source/android/maven"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

最佳答案

在 Facebook 广告依赖中排除 -> gms

compile ('com.facebook.android:audience-network-sdk:4.+'){
         exclude group: 'com.google.android.gms'
}

并且还删除以下行项目级 build.gradle

classpath 'com.google.gms:google-services:3.1.1'

关于java - 无法在 Android Studio 上构建应用程序,谷歌服务冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48397535/

相关文章:

java - 寻找 JDOM2 XPath 示例

java - DWP(Eclipse)中的登录jsp错误

java - 除以 0 的正则表达式

java - fragment 着色器无效。链接无法继续

java - 当我们打印数组列表时,为什么在开头打印一个逗号?

android - SVG 在手机 View 中截断

java - Android Searchview 导致 App 崩溃

android - Android Studio 3.1 中的 android.enableD8.desugaring 与 android.enableD8 的区别

java - Android Studio : onTouchEvent either doesn't run or can't update variables

android - 如何在 API 19 上支持 fast_out_slow_in?