38

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

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

I searched on the internet and found some topics about it, but I couldn't solve my problem.

React-Native version: 0.54.0

EDIT:
Now I'm running ./gradlew assembleRelease --info from the terminal instead of Android Studio and I get different error.
Here is the result:

> 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


It seems gradle is looking for libs folder in all modules, but there are no libs folders in the node modules. It's true, but I don't know why gradle is looking for libs folder.

Reza Mousavi
  • 4,105
  • 5
  • 27
  • 46
Hamid
  • 1,668
  • 4
  • 23
  • 34

16 Answers16

68

First:

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

finally build:

./gradlew assembleRelease -x bundleReleaseJsAndAssets
Stephen Rauch
  • 44,696
  • 30
  • 102
  • 125
anibalajt
  • 830
  • 6
  • 11
  • 2
    WHen I run this in my cli it is successfully building but the APK is unsigned and when I try and sign the APK via Android studio I am getting the error above – Will Goodhew Oct 02 '18 at 17:25
  • 2
    The above almost worked for me, but when I run the build, I get: `Task 'bundleReleaseJsAndAssets' not found in root project` – Daniel Jun 27 '19 at 23:19
  • 2
    just ./gradlew assembleRelease -x bundleReleaseJsAndAssets saved me. Thx – Sahin Elidemir Aug 03 '19 at 22:32
  • Getting Task :react-native-firebase-analytics:verifyReleaseResources FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':react-native-firebase-analytics:verifyReleaseResources'. – Anuj Nov 26 '19 at 15:26
  • If you run Windows 10, use cmd with administrator rights (no git bash), make sure that you're using the actual version of @react-native-community/cli, that directory android/app/src/main/assets exists and use yarn react-native bundle instead of react-native bundle – Liam Kernighan Jun 25 '20 at 15:19
19

Looks like you haven't made a js bundle so please make a bundle first by using command :-

 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

then in your project directory

 cd android 

Clean your gradle

 ./gradlew clean

and make a build finally

./gradlew assembleDebug

Try this. Hope it will helps you.

Kartik Shah
  • 808
  • 4
  • 18
17

For me the creating the bundle failed, but I noticed this comment by Sahin Elidemir:

just ./gradlew assembleRelease -x bundleReleaseJsAndAssets saved me.

It almost worked for me. What worked at the end was (notice the app:, which for me it fails without, and a clean for good measure):

./gradlew clean app:assembleRelease -x bundleReleaseJsAndAssets
MikeL
  • 2,496
  • 1
  • 21
  • 37
13

Just using ./gradlew --stop and then ./gradlew assembleRelease worked for me.

Y-B Cause
  • 1,193
  • 15
  • 38
Behzad Fattahi
  • 329
  • 3
  • 4
6

I had the same problem, the solution was :

cd to yourApp/android folder

run this

./gradlew --stop

and then

./gradlew assembleRelease

This gonna build your app.

After build is done, go to see your application(apk).

android\app\build\outputs\apk\release

Qui-Gon Jinn
  • 2,786
  • 3
  • 22
  • 26
4

This is working for me, Please follow the below steps:-

1) Stop Running 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) Update the android app build gradle

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

3) Get Node details

$ which node 

> (Result will be like "/usr/username/.nvm/versions/node/v10.7.0/bin/node")

4) Link node (very imp step copy the above result in step 3)

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

5) If Step - 4 return file exist - then to go the folder /usr/local/bin/ and delete the "node" file and perform the step -4 again.

6) If Step - 4 run successfully then this node issue will be resolved.

omprakash8080
  • 1,111
  • 14
  • 11
4

I now this is late. may be this will help somebody.

For me it i had to upgrade to latest react-native-sentry.

apply from: "../../node_modules/react-native-sentry/sentry.gradle"

was causing problem

dasl
  • 374
  • 3
  • 5
  • 2
    They changed to a new npm package https://www.npmjs.com/package/@sentry/react-native which I completely missed! – hannojg Oct 17 '19 at 18:57
2

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"
}
Thomas Hagström
  • 3,811
  • 1
  • 18
  • 27
2

I did it like this and it works:

  • Removed node modules (you can do it by running this command rm -rf node_modules)
  • Run npm installl or yarn install
  • Then run ./gradlew clean && ./gradlew app:assembleRelease or ./gradlew app:assembleDebug
Adriatik Gashi
  • 292
  • 3
  • 10
0

I was using the wrong image size (i.e image@5x.png) which caused me this problem. When I deleted that image@5x.png file...it worked!!

Akhilesh Sinha
  • 821
  • 12
  • 17
0

As of RN 0.58, for CI builds the commands is as follows:

First create directories:

mkdir -p app/build/generated/assets/react/production/release/ && mkdir -p app/build/generated/res/react/production/release

Next:

node ../node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --entry-file index.android.js --bundle-output app/build/generated/assets/react/production/release/index.android.bundle --assets-dest app/build/generated/res/react/production/release --max-workers 1 --reset-cache

Also you may also want to add for your production builds according to this;

--minify true

Taken from RN's source

NOTE: We added --max-workers 1 not to deplete CI resources since they are limited to lower numbers (mem&cpu).

px5x2
  • 1,425
  • 2
  • 14
  • 29
0

Consider checking all your JS (React native). I faced this issue coz have a coding error in the JS file (React native).

Balagurubaran
  • 519
  • 6
  • 18
0

For me:

  • OS: Windows.
  • I just copied the .keystore file to android\app.
  • cd android && gradlew --stop then gradlew assembleRelease.
ac23
  • 51
  • 1
  • 1
  • 5
0

if you are running these commands in VS code, Just open the project in cmd (administrator mode) in android folder run $ gradlew clean $ gradlew assembleRelease

0

if you are using macOS and using react native try this:

  1. brew install react-native-cli

  2. ./gradlew --stop

  3. ./gradlew clean

  4. ./gradlew aRor ./gradlew assembleRelease

Zight
  • 1
-1

I had the same problem. In my case, after a few hours, I saw this on GitHub: https://github.com/getsentry/sentry-react-native/issues/578#issuecomment-503428032. I had renamed the project on Sentry. If you renamed the project on, update the android/sentry.properties and ios/sentry.properties file.

defaults.url=https://sentry.io/
defaults.org=yourorg
defaults.project=newprojectname
auth.token=

And that's it