0

After updating the library react-native-fcm to version 16 (which now supports Android 8), I have the following error:

Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

Any idea on how to approach this?

project/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        // Add jitpack repository (added by tipsi-stripe)
        maven { url "https://jitpack.io" }
        mavenLocal()
        jcenter()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.android:facebook-android-sdk:4.28.0'
                force 'com.android.support:support-v4:27.1.0'
                force 'com.android.support:design:27.1.0'
            }
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

subprojects {
    if (project.name.contains('react-native-image-picker') || 
        project.name.contains('react-native-vector-icons')) {
        buildscript {
            repositories {
                jcenter()
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}

and my project/app/build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 28
buildToolsVersion "28.0.2"

    defaultConfig {
        applicationId "com.lisdoworker"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 14
        versionName "1.0.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        manifestPlaceholders = [
            tipsiStripeRedirectScheme: "example"
        ]
        multiDexEnabled true
    }
    signingConfigs {
        release {
          storeFile file(MYAPP_RELEASE_STORE_FILE)
          storePassword MYAPP_RELEASE_STORE_PASSWORD
          keyAlias MYAPP_RELEASE_KEY_ALIAS
          keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    dexOptions {
        jumboMode true
    }
}

dependencies {
    compile project(':react-native-fast-image')
    compile ('com.google.firebase:firebase-core:10.2.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-base:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-location:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-places:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-maps:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-gcm:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-wallet:10.2.1') {
        force = true;
    }
    compile ('com.google.android.gms:play-services-identity:10.2.1') {
        force = true;
    }
    compile project(':tipsi-stripe')
    compile project(':react-native-fcm')
    compile project(':react-native-extra-dimensions-android')
    compile project(':react-native-google-places')
    compile project(':react-native-vector-icons')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-image-picker')
    compile project(':react-native-fetch-blob')
    compile project(':react-native-fbsdk')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:27.1.0"
    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'

1 Answer 1

2

I believe that adding multiDexEnabled = true is just not enough. Try to add this line to your app/build.gradle file:

implementation 'com.android.support:multidex:1.0.3'

Also your Application class (if you have one) should be kinda like this:

public class App extends MultiDexApplication {
    ...
}

or like this:

public class App extends Application {

    @Override
        public void onCreate() {
            super.onCreate();
            MultiDex.install(this);
    }
}

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Hello, thanks for your answer. I did not get a chance to try it out since I reverted from [email protected] to [email protected] and it solved the issue. Will try it out if I see same error though.
Just remember to import For the extends case: import android.support.multidex.MultiDexApplication; and using the MultiDex.install(this); import android.support.multidex.MultiDex; import android.content.Context;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.