React-Native assembleRelease fails for task ':app:bundleReleaseJsAndAssets'

后端 未结 12 2028
借酒劲吻你
借酒劲吻你 2020-12-13 02:24

When I run ./gradlew assembleRelease build is failed with this error:

Error:Execution failed for task \':app:bundleReleaseJsAndAsse         


        
12条回答
  •  没有蜡笔的小新
    2020-12-13 03:01

    The steps above really helped.

    Here's the scripts that work for us with react-native 0.55.3.

    Run the android-build command locally or CI to generate an APK.

    /packages.json (react-native):

    "android-bundle": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res",
    "android-release-fix": "node ./android-release-gradle-fix.js",
    "android-build": "yarn killbin && yarn android-clean && yarn android-release-fix && yarn android-bundle && cd android && ./gradlew assembleRelease -x bundleReleaseJsAndAssets --info",
    "android-clean": "cd android && ./gradlew clean",
    "killbin": "rm -rf ./node_modules/.bin",
    

    android-release-gradle-fix.js:

    const fs = require('fs')
    
    // Fix issues with Android resources like duplicate files
    // CI: run install with --unsafe-perm option
    // https://stackoverflow.com/questions/47084810/react-native-android-duplicate-file-error-when-generating-apk
    try {
            var curDir = __dirname
            var rootDir = process.cwd()
    
            var file = `${rootDir}/node_modules/react-native/react.gradle`
            var dataFix = fs.readFileSync(`${curDir}/android-react-gradle-fix`, 'utf8')
            var data = fs.readFileSync(file, 'utf8')
    
            var doLast = "doLast \{"
            if (data.indexOf(doLast) !== -1) {
                throw "Already fixed."
            }
    
            var result = data.replace(/                \/\/ Set up inputs and outputs so gradle can cache the result/g, dataFix);
            fs.writeFileSync(file, result, 'utf8')
            console.log('Done')
        } catch (error) {
            console.error(error)
        }
    

    android-react-gradle-fix

    doLast {
        def moveFunc = { resSuffix ->
            File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
            if (originalDir.exists()) {
                File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
                ant.move(file: originalDir, tofile: destDir)
            }
        }
        moveFunc.curry("ldpi").call()
        moveFunc.curry("mdpi").call()
        moveFunc.curry("hdpi").call()
        moveFunc.curry("xhdpi").call()
        moveFunc.curry("xxhdpi").call()
        moveFunc.curry("xxxhdpi").call()
    }
    
    // Set up inputs and outputs so gradle can cache the result
    

    /android/build.gradle:

    buildscript {
        ext {
            buildToolsVersion = "27.0.3"
            minSdkVersion = 21
            compileSdkVersion = 27
            targetSdkVersion = 27
            supportLibVersion = "27.1.1"
            googlePlayServicesVersion = "15.0.1"
            androidMapsUtilsVersion = "0.5+"
        }
    ...
    subprojects {
        afterEvaluate {project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion 27
                    buildToolsVersion '27.0.3'
                }
            }
        }
    }
    

    /android/app/build.gradle:

    dependencies {
        implementation project(':amazon-cognito-identity-js')
        implementation project(':appcenter-push')
        implementation project(':react-native-fbsdk')
        implementation(project(':react-native-google-signin')) {
            exclude group: "com.google.android.gms" // very important
        }
        implementation project(':react-native-image-picker')
        implementation project(':react-native-vector-icons')
        implementation project(':react-native-sentry')
        implementation project(':react-native-maps')
        implementation "com.google.android.gms:play-services-auth:$googlePlayServicesVersion" // Google signin
        implementation project(':react-native-sentry')
        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:$googlePlayServicesVersion"
        implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
        implementation "com.google.firebase:firebase-core:15.0.2"
        implementation "com.google.firebase:firebase-messaging:15.0.2"
        implementation project(':react-native-vector-icons')
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "com.android.support:appcompat-v7:$supportLibVersion"
        implementation 'com.facebook.react:react-native:+'
        // implementation "com.android.support:$supportLibVersion"
    }
    

提交回复
热议问题