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

时间:2018-08-03 07:54:16

标签: java android react-native build apk

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

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

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

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

  

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

3 个答案:

答案 0 :(得分:0)

添加gradle.property这一行

org.gradle.jvmargs=-Xmx1024m

在清理并重建项目后

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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