【问题标题】:React-Native (Android) - Execution failed for task ':app:transformClassesWithMultidexlistForRelease'React-Native (Android) - 任务 ':app:transformClassesWithMultidexlistForRelease' 执行失败
【发布时间】:2018-12-12 15:46:12
【问题描述】:

将库 react-native-fcm 更新到版本 16(现在支持 Android 8)后,出现以下错误:

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

知道如何解决这个问题吗?

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/"  }
            }
        }
    }
}

还有我的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'

【问题讨论】:

    标签: android react-native gradle


    【解决方案1】:

    我认为添加multiDexEnabled = true 是不够的。 尝试将此行添加到您的 app/build.gradle 文件中:

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

    你的 Application 类(如果你有的话)应该是这样的:

    public class App extends MultiDexApplication {
        ...
    }
    

    或者像这样:

    public class App extends Application {
    
        @Override
            public void onCreate() {
                super.onCreate();
                MultiDex.install(this);
        }
    }
    

    希望对你有帮助。

    【讨论】:

    • 您好,感谢您的回答。自从我从react-native-fcm@16.0.4 恢复到react-native-fcm@16.0.2 后,我没有机会尝试它,它解决了这个问题。如果我看到同样的错误,我会尝试一下。
    • 只记得 import 对于扩展案例:import android.support.multidex.MultiDexApplication; 并使用 MultiDex.install(this); import android.support.multidex.MultiDex; import android.content.Context;
    猜你喜欢
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2022-11-08
    • 2021-07-09
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多