Firebase Onesignal多个dex文件定义Lcom / google / android / gms / auth / api / signin / zzc

时间:2017-09-06 08:53:33

标签: android firebase react-native onesignal

我的android / app / build.gradle(底部):

dependencies {
    compile project(':react-native-onesignal')
    compile project(':react-native-youtube')
    compile(project(":react-native-google-sign-in")) {
        exclude group: "com.google.android.gms"
    } 
    compile project(':react-native-svg')
    compile project(':react-native-facebook-login')
    compile project(':react-native-i18n')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.google.android.gms:play-services-auth:10.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}


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

我的android / build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        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
    }
}

错误:

Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/auth/api/signin/zzc;

我尝试了各种解决方案,没有任何作用:/ 似乎是某种版本不匹配,但我不知道如何匹配它。

2 个答案:

答案 0 :(得分:0)

只需按以下方式启用multidex:

android {    
  defaultConfig {
    // Enabling multidex support.
    multiDexEnabled true
  }  
}
  dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

像这样创建一个类

public class Multi_Dex extends Application {
  @Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }
}

现在在你最明显的文件中添加

<application
    android:name=".Multi_Dex"
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

答案 1 :(得分:0)

该问题的解决方案如下:

我的build.gradle有这一行:

com.google.android.gms:play-services-auth:10.0.1

所以我不得不像这样更改/node_modules/react-native-onesignal/android/build.gradle:

compile 'com.google.android.gms:play-services-gcm:10.0.1'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'

在尝试我在网上找到的所有其他解决方案后,这是唯一可行的方法。