Reputation: 2088
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.
Upvotes: 54
Views: 152836
Reputation: 461
For default APK build:
./gradlew app:assembleRelease
For default AAB build:
./gradlew app:bundleRelease
Upvotes: 0
Reputation: 1
I have fixed using this command :
cd android
./gradlew --stop
./gradlew assembleRelease
Upvotes: 0
Reputation: 1710
For my case, only this command solved the issue:
cd android && ./gradlew --stop
Upvotes: 0
Reputation: 1
I had to upgrade sentry to 5.33.1 to generate my build after Xcode version got updated to 16 but I started getting this same error when trying to generate android app bundle. Just downgrading the version for generating android build resolved the issue for me.
Upvotes: 0
Reputation: 539
I've tried this and hopefully it's worked for me.
first install hermes engine,
npm install hermes-engine --save --force //--force is optional
then install node_modules,
npm install --force //you can delete node_modules or just leave it as it is
then for IOS sync,
cd ios && pod install
then Android sync,
cd android && ./gradlew clean
finally,
npx react-native run-android
the above cmds solved my issue.
Upvotes: 0
Reputation: 1
I had the same problem, and what solved it for me was running it:
npx expo install --fix
I hope it helps someone
Upvotes: 0
Reputation: 1
I solved this using:
brew uninstall watchman
brew install watchman
watchman shutdown-server (just in case it's running)
watchman watch-del-all
yarn start --reset-cache
Upvotes: 0
Reputation: 216
change the default node version make the defauilt version that is compatible for app
"nvm alias default <version>"
after this
"./gradlew clean"
"./gradlew assembleRelease"
Upvotes: 0
Reputation: 2894
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
Upvotes: 22
Reputation: 2162
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.
Upvotes: 1
Reputation: 51
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
Upvotes: 1
Reputation: 201
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
Upvotes: 1
Reputation: 318
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".
Upvotes: 0
Reputation: 69
try android/app/build.gradle
def enableSeparateBuildPerCPUArchitecture = false
in new rn versions it is set to true
then
gradlew clean
gradlew assembleRelease
Upvotes: 0
Reputation: 1145
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.
Upvotes: 1
Reputation: 83
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.
Upvotes: 0
Reputation: 11
Solution :
1- android\app\build.gradle
project.ext.react = [
enableHermes: false,
]
2-
cd android
gradlew clean
3- gradlew bundleRelease
Upvotes: 1
Reputation: 1544
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.
Upvotes: 2
Reputation: 362
I did it like this and it works:
rm -rf node_modules
)npm install
or yarn install
./gradlew clean
&& ./gradlew app:assembleRelease
or ./gradlew app:assembleDebug
Upvotes: 3
Reputation: 31
if you are using macOS and using react native try this:
brew install react-native-cli
./gradlew --stop
./gradlew clean
./gradlew aR
or ./gradlew assembleRelease
Upvotes: 3
Reputation: 742
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
Upvotes: 1
Reputation: 91
For me:
Windows
.cd android && gradlew --stop
then gradlew assembleRelease
.Upvotes: 2
Reputation: 569
Consider checking all your JS (React native). I faced this issue coz have a coding error in the JS file (React native).
Upvotes: 1
Reputation: 4398
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
Upvotes: 18
Reputation: 432
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
Upvotes: 4
Reputation: 489
Just using ./gradlew --stop
and then ./gradlew assembleRelease
worked for me.
Upvotes: 28
Reputation: 1565
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).
Upvotes: 1
Reputation: 881
I was using the wrong image size (i.e [email protected]) which caused me this problem. When I deleted that [email protected] file...it worked!!
Upvotes: 1
Reputation: 1391
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.
Upvotes: 9
Reputation: 4528
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"
}
Upvotes: 3