'React-Native assembleRelease fails for task ':app:bundleReleaseJsAndAssets'
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.
Solution 1:[1]
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
Solution 2:[2]
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.
Solution 3:[3]
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
Solution 4:[4]
Just using ./gradlew --stop
and then ./gradlew assembleRelease
worked for me.
Solution 5:[5]
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
Solution 6:[6]
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.
Solution 7:[7]
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
Solution 8:[8]
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"
}
Solution 9:[9]
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
oryarn install
- Then run
./gradlew clean
&&./gradlew app:assembleRelease
or./gradlew app:assembleDebug
Solution 10:[10]
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!!
Solution 11:[11]
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).
Solution 12:[12]
Consider checking all your JS (React native). I faced this issue coz have a coding error in the JS file (React native).
Solution 13:[13]
For me:
- OS:
Windows
. - I just copied the .keystore file to android\app.
cd android && gradlew --stop
thengradlew assembleRelease
.
Solution 14:[14]
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
Solution 15:[15]
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
Solution 16:[16]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow