web-dev-qa-db-fra.com

React-Native assemblembleRelease échoue pour la tâche ': app: bundleReleaseJsAndAssets'

Quand j'exécute ./gradlew assembleRelease, la construction échoue avec cette erreur:

Error:Execution failed for task ':app:bundleReleaseJsAndAssets. 
> A problem occurred starting process 'command 'node'

J'ai cherché sur Internet et trouvé des sujets à ce sujet, mais je n'ai pas pu résoudre mon problème.

Version de React-Native: 0.54.0

MODIFIER:
Maintenant, je lance ./gradlew assembleRelease --info depuis le terminal au lieu d’Android Studio et j’obtiens une erreur différente.
Voici le résultat:

> Task :app:processReleaseResources
Putting task artifact state for task ':app:processReleaseResources' into context took 0.007 secs.
file or directory '**/Android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/Android/libs', not found
file or directory '**/node_modules/appcenter-analytics/Android/libs', not found
file or directory '**/node_modules/appcenter/Android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/Android/libs', not found
file or directory '**/node_modules/react-native-navigation/Android/app/libs', not found
file or directory '**/Android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/Android/libs', not found
file or directory '**/appcenter-analytics/Android/libs', not found
file or directory '**/node_modules/appcenter/Android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/Android/libs', not found
file or directory '**/node_modules/react-native-navigation/Android/app/libs', not found
Executing task ':app:processReleaseResources' (up-to-date check took 0.035 secs) due to:
  Task has failed previously.
All input files are considered out-of-date for incremental task ':app:processReleaseResources'.
Unable do incremental execution: full task run
file or directory '**/Android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/Android/libs', not found
file or directory '**/node_modules/appcenter-analytics/Android/libs', not found
file or directory '**/node_modules/appcenter/Android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/Android/libs', not found
file or directory '**/node_modules/react-native-navigation/Android/app/libs', not found
file or directory '**/Android/app/libs', not found
file or directory '**/node_modules/appcenter-crashes/Android/libs', not found
file or directory '**/node_modules/appcenter-analytics/Android/libs', not found
file or directory '**/node_modules/appcenter/Android/libs', not found
file or directory '**/node_modules/react-native-interactable/lib/Android/libs', not found
file or directory '**/node_modules/react-native-navigation/Android/app/libs', not found
Aapt2QueuedResourceProcessor is using **/Android/sdk/build-tools/26.0.2/aapt2
Failed to execute aapt
com.Android.ide.common.process.ProcessException: Failed to execute aapt
*
*
*
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> Failed to execute aapt


Il semble que gradle recherche un dossier libs dans tous les modules, mais il n’existe aucun dossier libs dans les modules de nœud. C'est vrai, mais je ne sais pas pourquoi Gradle recherche un dossier libs.

5
Hamid

Premier:

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

enfin construire:

./gradlew assembleRelease -x bundleReleaseJsAndAssets
11
anibalajt

Cela fonctionne pour moi, s'il vous plaît suivez les étapes ci-dessous: -

1) Arrête de courir Gradle  

 $ cd RectNatoveProjectName & cd Android  (Open your project and go to Android folder)  
 $ ./gradlew --stop (Run this command to stop old running Gradle service )

2) Mettre à jour le niveau de construction de l'application Android  

project.ext.react = [
        nodeExecutableAndArgs : ["/usr/local/bin/node"]
];

3) Obtenir les détails du nœud

$ which node 

> (Le résultat ressemblera à "/usr/nomutilisateur/.nvm/versions/node/v10.7.0/bin/node")

4) Noeud de liaison (copie très complète de l’étape 3 ci-dessus)

- ln -s /usr/username/.nvm/versions/node/v10.7.0/bin/node /usr/local/bin/node

5) Si le fichier de retour Étape 4 existe - puis allez dans le dossier/usr/local/bin /, supprimez le fichier "noeud" et effectuez à nouveau l'étape -4.

6) Si l'étape 4 aboutit, le problème de ce noeud sera résolu.

2
omprakash8080

Les étapes ci-dessus ont vraiment aidé. 

Voici les scripts qui fonctionnent pour nous avec react-native 0.55.3

Exécutez la commande Android-build localement ou le CI pour générer un APK.

/packages.json (réact-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"
}
1
Thomas Hagström

On dirait que vous n'avez pas créé de bundle js, veuillez donc d'abord le créer en utilisant la commande suivante: -

 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

puis dans votre répertoire de projet 

 cd Android 

Nettoyez votre diplôme

 ./gradlew clean

et faire un build enfin

./gradlew assembleDebug

Essayez ceci . J'espère que cela vous aidera.

0
Kartik Shah