无法编译发布React Native 0.59 Android:内存不足

时间:2019-10-08 14:47:14

标签: java android react-native gradle release

我刚刚将React Native升级到0.59.5版本,并且在调试模式下一切正常。当我尝试组装发行版(./gradlew assembleRelease)时,问题就来了。编译器给我错误:

任务':app:mergeDexRelease'的执行失败。

  

com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException:java.lang.OutOfMemoryError

我做了一些重新研究,可能由于多种原因而发生:

  • 不良图像处理

  • 内存泄漏

  • 大ScrollView和Flatlist处理不当

  • ...

我试图优化我的代码,它在调试模式下运行的非常顺畅,并且似乎运行良好。厌倦了尝试优化代码,我注释了代码的所有大部分,但仍然收到此错误。

我还尝试指定Andorid来升级堆内存空间,并在Android Manifest上启用大堆,但这也不起作用。

有人知道为什么会这样吗?预先感谢。

这是我的android / app / build.gradle文件:

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

defaultConfig {
    applicationId "com.example.app"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 56
    multiDexEnabled true
    versionName "2.2.1"
    ndk {
        abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
    vectorDrawables.useSupportLibrary = true
}
signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}
dexOptions {
    javaMaxHeapSize "4g"
}
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
buildTypes {
    release {
        //minifyEnabled true
        //shrinkResources true
        //proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        signingConfig signingConfigs.release
    }
}
// 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, "arm64-v8a": 3, "x86_64": 4]
        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
        }
    }
}

0 个答案:

没有答案