如何启用multidex for react native?

时间:2017-05-23 16:37:20

标签: java android react-native

我非常确定它是内置功能,但在搜索时或在文档中我找不到任何内容。是否有启用multidex的构建标志?

另一方面说明: 有什么方法可以看出哪些库弄乱了你的方法计数?达到64k的限制令人非常惊讶。

4 个答案:

答案 0 :(得分:4)

在其他地方找到答案。与为任何常规Android项目启用它没有什么不同。

android {
    ....
    defaultConfig {
        ...
        multiDexEnabled true
    }

至于方法计数,这个网站可以解决这个问题:http://inloop.github.io/apk-method-count/

答案 1 :(得分:4)

机器人/应用/的build.gradle

$bars = DB::table('foos')
            ->Join('bars', function($join) {
              $join->on('foos.id', '=', 'bars.foo_id')
                  ->where('bars.test', '!=', '0');
            })
            ->select('foos.id');

  $result = DB::table('foos')
              ->leftJoin('bars', 'foos.id', '=', 'bars.foo_id')
              ->select('foos.id')
              ->whereNull('bars.foo_id')
              ->union($bars)
              ->get();

如果您使用的是Multidex,您的应用程序应该扩展MultiDexApplication而不是Application。

MyApplication.java

android {
    ....
    defaultConfig {
        ...
        multiDexEnabled true
    }

答案 2 :(得分:3)

对于RN 0.59+和使用Gradle 3.4.1,这里没有答案提供完整的解决方案。我做了以下工作,它起作用了:

  1. android/app/build.gradle中,更新dependency块:

    dependencies {
        // ... your other dependencies
    
        // Multidex
        implementation 'com.android.support:multidex:1.0.3'
    }
    

    还要更新defaultConfig块中的android

    defaultConfig {
        // ... your `applicationId`, etc.
        multiDexEnabled true
    }
    
  2. MainApplication.java中,替换
    import android.app.Application;
    
    在顶部
    import android.support.multidex.MultiDexApplication;
    
    然后更换
    public class MainApplication extends Application implements ReactApplication {
    
    public class MainApplication extends MultiDexApplication implements ReactApplication {
    

答案 3 :(得分:1)

由于Application必须扩展ReactApplication,因此我使用了与the one suggested here类似的方法,该方法在Android开发人员reference on multidex的第2点中进行了介绍,以附加到基本上下文:

  

app / build.gradle

android {
    compileSdkVersion projectCompileSdkVersion // Or your version

    defaultConfig {
        minSdkVersion projectMinSdkVersion // Or your version
        targetSdkVersion projectTargetSdkVersion // Or your version
        multiDexEnabled true // *
    }
    dexOptions {
        jumboMode true // *
    }
}

dependencies {
  compile 'com.android.support:multidex:1.0.3' // https://mvnrepository.com/artifact/com.android.support/multidex
}
  

MainApplication.java

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}