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

时间:2018-01-23 08:51:23

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

我正在使用react native开发一个应用程序,并希望使用react本机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 more ...

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

':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
}

3 个答案:

答案 0 :(得分:1)

在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'

答案 1 :(得分:0)

通过更新所有内容到11.8.0似乎解决了问题,构建成功并且应用程序正在运行。

嗯,我现在面对包裹不运行在http:192.168.168.244:19901 idk如何为什么,eventhou它似乎工作了一次!我现在抱怨当gradle正在构建时,调试文件夹无法删除!

答案 2 :(得分:0)

firebase-messagingfacebook具有相同的依赖关系com.google.android.gms。他们必须使用相同版本的gms或者可能导致构建失败。你应该排除他们@Ranjith Kumar说。如果问题仍然存在(像我一样),那么升级/降级其中一些。

就我而言,最新的facebook sdk 今天4.31.0 其中包括gms:11.8.0,因此我可以使用firebase:11.8.0来保持一致。

但是firebase-messaging:11.8.0有关于通知图标的错误。 我已将其升级为firebase-messaging:12.0.0。但我不能,因为facebook-sdk仍在使用gms:11.8.0

我终于找到了它们的稳定版本,FYI

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'com.facebook.android:facebook-android-sdk:4.11.0'
api 'com.facebook.android:account-kit-sdk:4.11.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.android.gms:play-services-analytics:12.0.1'
}
  • 如果新的FacebookSDK(4.31.0之后)使用gms:12.0.1,则不推荐使用此功能。