React Native:com.android.build.api.transform.TransformException:生成主dex列表时出错

时间:2018-11-05 18:54:25

标签: firebase react-native firebase-cloud-messaging

我没有做任何更改,现在我的项目无法正常工作。自从今天早上以来,我一直收到此错误:

  • 出了什么问题: 任务':app:transformClassesWithMultidexlistForDebug'的执行失败。
      

    com.android.build.api.transform.TransformException:生成主dex列表时出错。

我尝试实现multiDexEnabled。在我的build.gradle中,我像这样添加了multiDexEnabled:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
        versionCode 8
        versionName "1.3"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

这是我的依赖

dependencies {
    implementation project(':react-native-firebase')
    implementation project(':react-native-video')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-touch-id')
    implementation project(':react-native-picker')
    implementation(project(':react-native-maps')) {
      exclude group: 'com.google.android.gms', module: 'play-services-base'
      exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:+'
    implementation 'com.google.android.gms:play-services-maps:+'

    implementation project(':react-native-keychain')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-google-analytics-bridge')
    implementation project(':react-native-device-info')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.firebase:firebase-core:16.0.4"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'
}

我也将我的MultiDexApplication申请更改为:

import android.support.multidex.MultiDexApplication;

public class MainApplication extends MultiDexApplication implements ReactApplication {
...
}

这是错误的堆栈跟踪

失败:构建失败,并出现异常。

  • 出了什么问题: 任务':app:transformClassesWithMultidexlistForDebug'的执行失败。

      

    com.android.build.api.transform.TransformException:生成主dex列表时出错。

  • 尝试: 使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。

  • 例外是: org.gradle.api.tasks.TaskExecutionException:任务':app:transformClassesWithMultidexlistForDebug'的执行失败。     在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)     在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)     在org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)处     在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)     在org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)     在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)     在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)     在org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)     在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)处     在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)     在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)     在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)     在org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)     在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.run(DefaultTaskGraphExecuter.java:248)     在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处     在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)     在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)     在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)     在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)处     在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)处     在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)处     在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:79)     在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:104)     在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:98)     在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)处     在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)处     在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)     在org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)     在org.gradle.internal.concurrent.ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46)     在org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 引起原因:java.lang.RuntimeException:com.android.build.api.transform.TransformException:生成主dex列表时出错。     在com.android.builder.profile.Recorder $ Block.handleException(Recorder.java:55)     在com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)     在com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)     在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)     在org.gradle.api.internal.project.taskfactory.IncrementalTask​​Action.doExecute(IncrementalTask​​Action.java:46)     在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)     在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)     在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:121)     在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处     在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)     在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)     在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)     在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)处     在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)     ...另外29个 引起原因:com.android.build.api.transform.TransformException:生成主dex列表时出错。     在com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:127)     在com.android.build.gradle.internal.pipeline.TransformTask $ 2.call(TransformTask.java:221)     在com.android.build.gradle.internal.pipeline.TransformTask $ 2.call(TransformTask.java:217)     在com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)     ...另外41个 引起原因:com.android.builder.multidex.D8MainDexList $ MainDexListException:com.android.tools.r8.errors.CompilationError:程序类型已存在:com.google.android.gms.internal.measurement.zzsh     在com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:87)     在com.android.build.gradle.internal.transforms.D8MainDexListTransform.transform(D8MainDexListTransform.kt:114)     ...另外44个 引起原因:com.android.tools.r8.errors.CompilationError:程序类型已存在:com.google.android.gms.internal.measurement.zzsh     在com.android.tools.r8.utils.ProgramClassCollection.resolveClassConflictImpl(ProgramClassCollection.java:64)     在com.android.tools.r8.utils.ProgramClassCollection.lambda $ create $ 0(ProgramClassCollection.java:25)     在com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:24)     在com.android.tools.r8.graph.LazyLoadedDexApplication $ Builder.build(LazyLoadedDexApplication.java:121)     在com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:122)     在com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:86)     在com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:40)     在com.android.tools.r8.GenerateMainDexList.run(GenerateMainDexList.java:110)     在com.android.builder.multidex.D8MainDexList.generate(D8MainDexList.java:83)     ...还有45个

请帮助,我不知道我在想什么。 谢谢你给我的提示。

2 个答案:

答案 0 :(得分:0)

最后我开始工作了

app / build.gradle

    dependencies {
        implementation ("com.google.firebase:firebase-core:16.0.5")
        implementation ("com.google.firebase:firebase-messaging:17.3.4")
    ...
}

build.gradle 和

dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.google.gms:google-services:4.2.0'

我还必须补充一点,https://firebase.google.com/support/release-notes/android#latest_sdk_versions说,firebase-core的最新版本是16.0.4,但这对我不起作用

答案 1 :(得分:0)

将此内容粘贴到app.gradle中的defaultConfig {}下。它对我有用

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }