50

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,420
  • 5
  • 31
  • 48
Hamid
  • 1,948
  • 4
  • 25
  • 38

24 Answers24

80

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
  • 47,830
  • 31
  • 106
  • 135
anibalajt
  • 958
  • 6
  • 12
  • 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
  • 3
    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
  • if someone gets the error `ENOENT: no such file or directory, open 'android/app/src/main/assets/index.android.bundle'` , you must create the `assets` folder in main directory . [more info here](https://stackoverflow.com/q/58767106/7500651) – ansh sachdeva Sep 21 '22 at 08:46
  • it work in first phase , in the seccond time after i do some development and update some file , it also work but updated feature not shown it stuck in first phase – Khadam Ikhwanus Apr 12 '23 at 02:27
24

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
  • 866
  • 5
  • 19
22

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
Sanka Sanjeewa
  • 1,993
  • 14
  • 16
MikeL
  • 2,756
  • 2
  • 23
  • 41
20

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

Zoette
  • 1,241
  • 2
  • 18
  • 49
Behzad Fattahi
  • 399
  • 3
  • 4
13

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
  • 3,722
  • 3
  • 25
  • 32
8

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,211
  • 16
  • 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
  • 426
  • 7
  • 6
  • 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
3

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
  • 4,371
  • 1
  • 21
  • 27
3

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 install or yarn install
  • Then run ./gradlew clean && ./gradlew app:assembleRelease or ./gradlew app:assembleDebug
Ramesh R
  • 7,009
  • 4
  • 25
  • 38
Adriatik Gashi
  • 332
  • 4
  • 10
3

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
  • 31
  • 2
2

For me:

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

This error also occurs when you have stacked your project inside many folders

Try copying your project folder into one of your hard drives without putting that project into any folder.

Mishen Thakshana
  • 1,050
  • 1
  • 14
  • 38
1

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
  • 861
  • 12
  • 20
1

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,495
  • 2
  • 14
  • 29
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, i hope it helps

1

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

Balagurubaran
  • 549
  • 6
  • 18
1

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

1

In my case

npx was not able to go into the correct directory due to a space in the parent directory name

example :-

D:\dk\native\aiims raipur\aiimsraipur

Removed space from directory -> aiims raipur to aiims_raipur

Build works fine.

Deepak Singh
  • 749
  • 4
  • 16
1

First thing before trying other stuffs you should do the below:

cd yourProject/android and run

./gradlew --stop

and

./gradlew clean

next try again. Sometimes, when you update the assets you might have that gradle issue within terminal

0

Solution :

1- android\app\build.gradle

project.ext.react = [
    enableHermes: false, 
]

2-

cd android
gradlew clean

3- gradlew bundleRelease

Iva
  • 2,447
  • 1
  • 18
  • 28
0

Check your project to make sure that you didn't name any of your folders with spaces in between. For me, there was a space in the name of my project's parent folder. When I remove the space (from Source Codes to codes) my build was successful.

BigBros
  • 73
  • 1
  • 10
0

try android/app/build.gradle

def enableSeparateBuildPerCPUArchitecture = false

in new rn versions it is set to true

then

gradlew clean
gradlew assembleRelease
Ragu
  • 51
  • 4
0

In my case,

The solution is so simple,

your project ancestors folder names should not contain spaces, like: D:\Documents\React Native\MyRNProjectTest in this "React Native" folder has space in it, removing the space from folder name could solve the problem, like this "ReactNative".

Manal Liaquat
  • 229
  • 2
  • 7
0

I faced this same issue on Mac OS, was related to metro-bundler not having access to the folder in which my project was kept. I restarted my system and re-run the command. The bundler asked for permission to access the folder and after that I was able to generate the build.

Hope it helps. Thanks

P.S : All the fixes mentioned did not work for me.

Arpan Sharma
  • 2,142
  • 11
  • 22