【问题标题】:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/RNFetchBlob/RNFetchBlobConst;将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义Lcom/RNFetchBlob/RNFetchBlobConst;
【发布时间】:2018-08-03 07:54:15
【问题描述】:

我在尝试构建 APK 后遇到此错误,有什么想法吗?

错误:将字节码转换为 dex 时出错: 原因:com.android.dex.DexException: 多个dex文件定义了Lcom/RNFetchBlob/RNFetchBlobConst;

错误:com.android.dex.DexException:多个dex文件定义了Lcom/RNFetchBlob/RNFetchBlobConst;

错误:任务 ':app:transformDexArchiveWithDexMergerForDebug' 执行失败。

com.android.build.api.transform.TransformException: com.android.dex.DexException: 多个dex文件定义Lcom/RNFetchBlob/RNFetchBlobConst;

【问题讨论】:

  • 你的成绩文件中是否启用了multidex
  • @KunalParte 是的,如果我禁用或启用它,它不会导出它

标签: java android react-native build apk


【解决方案1】:

在 gradle.property 中加入这一行

org.gradle.jvmargs=-Xmx1024m

在清理并重建项目之后

【讨论】:

    【解决方案2】:
    Multidex exception intends that your app and libraries it references exceeds 65536 methods which means it has crossed the limit of Android build architecture.
    
    There are possible reasons for your Multidex exception.
    May be you have missed on something while enabling Multidex in you app.
    
    I would suggest you to go through the documentation and also go through the limitations of Multidex.
    
    If your minSdkversion is set to 21 the you just need to add following in your module level grade file:
    
    android {
        defaultConfig {
            minSdkVersion 21 
            targetSdkVersion 26
            multiDexEnabled true
        }
    
    }
    
     However, if your minSdkVersion set to 20 or low then you need to follow the following:
    
    in your module level grade file add this:
    android {
        defaultConfig {
            ...
            minSdkVersion 15 
            targetSdkVersion 26
            multiDexEnabled true
        }
        ...
    }
    
    dependencies {
      compile 'com.android.support:multidex:1.0.3'
    }
    
    If you are not overriding Application class the add this in your manifest file application tag:
    
        <application
                android:name="android.support.multidex.MultiDexApplication" >
            ...
        </application>
    
    if you override Application class then just replace Application with MultiDexApplication like this :
    
    public class MyApplication extends MultiDexApplication { ... }
    
    
    if you don not override Application class and you cannot change your base class then add this:
    public class MyApplication extends SomeOtherApplication {
      @Override
      protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
         MultiDex.install(this);
      }
    }
    
    following is the link for MultiDex documentation
    https://developer.android.com/studio/build/multidex
    

    【讨论】:

      【解决方案3】:

      我通过从 react-native-fetch-blob 切换到 rn-fetch-blob 解决了这个问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-03-18
        • 1970-01-01
        • 2017-11-11
        • 1970-01-01
        • 2018-04-21
        • 2018-04-09
        相关资源
        最近更新 更多