Search code examples
androidfirebasereact-nativeandroid-multidexreact-native-firebase

React native app is multiple dex with over 65536 methods


I am programming react native app on android. When I run on android, it show error: multiple dex with over 65536 methods. Here is android/app/build.gradle:

dependencies {
compile project(':react-native-device-info')
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile project(':react-native-fbsdk')
compile(project(':react-native-firebase')) {
    exclude group: "com.google.firebase"
}
compile project(':bugsnag-react-native')
compile(project(':react-native-push-notification')) {
}
compile project(':react-native-vector-icons')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.facebook.react:react-native:+'
// From node_modules
compile('com.google.firebase:firebase-core:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-config:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-auth:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-database:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-storage:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-messaging:10.2.6') {
    force = true;
}
compile('com.google.firebase:firebase-crash:10.2.6') {
    force = true;
}
compile('com.google.android.gms:play-services-gcm:10.2.6') {
    force = true;
}
compile project(':react-native-onesignal')
compile project(':react-native-fast-image')
compile project(':react-native-camera')
compile project(':RNWebView')
compile project(':zpdk-production')

}

android/build.gradle

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

}

file package.json

"dependencies": {
"async": "^2.5.0",
"bugsnag-react-native": "^2.2.0",
"he": "^1.1.1",
"moment": "^2.18.1",
"oauth-1.0a": "^2.1.0",
"prop-types": "^15.5.10",
"react": "16.0.0-alpha.12",
"react-native": "0.48.3",
"react-native-camera": "^0.13.0",
"react-native-datepicker": "^1.4.7",
"react-native-device-info": "^0.11.0",
"react-native-drawer": "^2.3.0",
"react-native-fast-image": "^1.0.0",
"react-native-fbsdk": "^0.6.1",
"react-native-firebase": "1.1.2",
"react-native-image-progress": "^1.0.1",
"react-native-keyboard-aware-scroll-view": "^0.2.7",
"react-native-modal-dropdown": "^0.4.2",
"react-native-navbar": "^1.5.0",
"react-native-onesignal": "^3.0.6",
"react-native-progress": "^3.4.0",
"react-native-push-notification": "^2.2.1",
"react-native-root-toast": "^1.0.3",
"react-native-router-flux": "^3.37.0",
"react-native-scrollable-tab-view": "^0.8.0",
"react-native-swiper": "^1.5.12",
"react-native-vector-icons": "^4.0.0",
"react-native-webview-android": "^1.1.17",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.3",
"redux": "^3.7.2",
"redux-logger": "^2.6.1",
"redux-persist": "^4.9.1",
"redux-thunk": "^2.1.0"

},

In react-native-firebase, I only use anlytics to log events of user who use my app. I don't know which dependencies I should remove. Please help me with my issue.

I tried enable multiple dex. But when I run app -> login with facebook -> app is crashed.

My config multidex. I consider I am missing some configuration.

android/app/build.gradle

 defaultConfig {
    applicationId "com.vannguyen.demotest"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 15
    versionName "1.1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }

    multiDexEnabled true
}

In MainApplication.java:

public class MainApplication extends MultiDexApplication implements ReactApplication {

Thank you so much.


Solution

  • You should enable multidex library in a project: open {project root}/android/app/build.gradle, then add following lines:

    android {
        ...
        defaultConfig {
            ...
            multiDexEnabled true
        }
    }
    

    And (if your sdk is lower than 21)

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

    Hope it helps. More info you could fine here.