The project can be cloned here: https://github.com/rafaelbrunoss/react-native-error
Error while building react native app
I tried to create a new project using react-native
npx react-native init Navigator --template react-native-template-typescript
After that, I tried to create the production files for Android using the command
cd android && ./gradlew assembleRelease
And it worked. But when I try to add some configuration to the initial project, the build starts to throw some errors. One of them I was able to solve executing
mkdir android/app/src/main/assets && 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
But then, for some reason, if I try to create the bundle again I get the error
error index.js: Import statement may only appear at top level in file index.js at 4:2.
Error: Import statement may only appear at top level in file index.js at 4:2
at minifyCode (/home/rafael/Documents/Library/react-native-error/node_modules/#react-native-community/cli-plugin-metro/node_modules/metro-transform-worker/src/index.js:99:13)
Using the last bundle file and then modifying the build command to
cd android && ./gradlew assembleRelease -x bundleReleaseJsAndAssets
I keep getting this error
Execution failed for task ':app:mapReleaseSourceSetPaths'.
> Error while evaluating property 'extraGeneratedResDir' of task ':app:mapReleaseSourceSetPaths'
> Failed to calculate the value of task ':app:mapReleaseSourceSetPaths' property 'extraGeneratedResDir'.
> Querying the mapped value of provider(java.util.Set) before task ':app:bundleReleaseJsAndAssets' has completed is not supported
I created some npm scripts to make it easy to execute this commands
npm run fix:bundle
npm run gradle:clean
npm run build:prod:android
They are all in the project here: https://github.com/rafaelbrunoss/react-native-error
I tried changing the version of gradle and android gradle plugin. I also tried to tweak something on babel.config.js and metro.config.js, but I got nothing.
It seems that the devDependency "react-native-gradle-plugin": "0.72.0" somehow messes with the build process. After I removed that, the build was successful.
Unable to Build .apk in react native
(You have symlinks in your project - watchman does not follow symlinks. OR Check blockList in your metro.config.js and make sure it isn't excluding the file path.
while tring tu build dev-app.apk (react-native bundle --platform android --dev false --entry-file app.js --bundle-output android/app/build/generated/assets/react/release/index.android.bundle --assets-dest android/app/src/main/res)
error:
SHA-1 for file N:\flutter client\client app\app.js (N:\flutter client\client app\app.js) is not computed.
Potential causes:
1) You have symlinks in your project - watchman does not follow symlinks.
2) Check blockList in your metro.config.js and make sure it isn't excluding the file path.
delete and reinstal node_modules
I am trying to bundle my APK. When I use gradlew assembleRelease or assembleReleaseStaging there are no changes in my app. When I use 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 before assembling it creates a lot of new files, if i delete all of them except index.android.bundle and run gradlew assembleRelease or gradlew assembleReleaseStaging everything works just fine. My question is - is there any way to assemble release without manual bundling? I have tried gradlew clean and other ways found on stackoverflow. Any advice is highly appreciated.
You need to hook react.gradle to your module's build.gradle.
Go to app/build.gradle and add the following:
// Configures the bundleJS commands for React-Native
project.ext.react = [
// whether to bundle JS and assets in debug mode
bundleInDebug: false,
// whether to bundle JS and assets in release mode
bundleInRelease: true,
// the root of your RN project, i.e. where "package.json" lives
root: "path_to_rn_project_directory"
]
apply from: "<path to RN project>/node_modules/react-native/react.gradle"
After this, assembleRelease will start bundling as well.
I got the below error when i tried to build a apk fron react-native using this command ./gradlew assembleRelease
D:\tmp\taamapp\android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigationstack_src_views_assets_backicon.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.
There's another option you can try in gradle.properties which is org.gradle.configureondemand=true. So use that instead of android.enableAapt2=false.
and removed all drawable* folders
rm -rf android/app/src/main/res/drawable-*
use the following command to bundle assets:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/
Run ./gradlew clean after.
hope it will help you :)
I want to generate the unsigned app-release.apk without the react-packager server.
I am running the following commands for that.
cd react-native-project-dir
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
After the following command I get the error in command prompt like these:
cd android && gradlew assemblerelease
app:processReleaseManifestessReleaseManifest
:app:processReleaseResources
D:\ReactNativeProject\android\app\build\intermediates\res\merged\release\drawable-mdpi-v4\image_background_unique_2.jpg: error: Duplicate file.
D:\ReactNativeProject\android\app\build\intermediates\res\merged\release\drawable-mdpi\image_background_unique_2.jpg: Original is here. The version qualifier may be implied.
:app:processReleaseResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processReleaseResources'.
com.android.ide.common.process.ProcessException: Failed to execute aapt
And I am not able to generate the app-release.apk and not understanding why the image_background_unique_2.jpg file is getting added two times in different folders.
The issue is that the new version of react-native bundles the assets under /app/build/intermediates/res/merged/release instead of app/src/main/res
To resolve it, this is what I did
rm -rf android/app/src/main/res/drawable-*
Now bundle assets using this command:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/
Note the updated --assets-dest in the above command. Assembling the APK worked ok after that!
react-native run-android --variant=release
I was trying to generate a signed APK following the steps from https://facebook.github.io/react-native/docs/signed-apk-android.html to generate a signed apk.
I had the same issue. Showed error: Duplicate file for some of my images when I ran ./gradlew assembleRelease. assembleRelease seems to cause some problems with drawable- folders. I deleted all the drawable- folders from /android/app/src/main/res/. Then I ran ./gradlew assembleRelease again. Finaly, it generated a signed APK at /android/app/build/outputs/apk/.
It seems that you bundled your app and installed it to your phone with assembleDebug. When you decided to go for assembleRelease then you should delete drawable- folders. They create problem somehow when you decide to produce an .apk file.
First delete all folders that are potentially causing this error by typing:
rm -rf ./android/app/build/intermediates/res/merged/release/drawable-*
Then change mdpi to mdpi-v4 in:
./node_modules/react-native/local-cli/bundle/assetPathUtils.js
function getAndroidAssetSuffix(scale) {
switch (scale) {
case 0.75: return 'ldpi';
case 1: return 'mdpi-v4';
case 1.5: return 'hdpi';
case 2: return 'xhdpi';
case 3: return 'xxhdpi';
case 4: return 'xxxhdpi';
}
}
Then bundle your offline includes:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/
Finally build the release version of your app:
cd ./android && ./gradlew assembleRelease
Did you try a react native clean build ? Try resetting the cache and then bundle. Maybe it will resolve this issue.
I have managed to solve this problem by deleting the duplicates of the folder in react native /android/app/build/intermediates/res/merged/release/drawable-mdpi
this worked for me
Add the following code to file node_modules/react-native/react.gradle :
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()
}
inside def currentBundleTask = tasks.create(...
found this solution here https://github.com/facebook/react-native/issues/5787
you can do one things for debug to make react native bundle run below command
react-native bundle --assets-dest ./android/app/src/main/res/ --entry-file ./index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --platform android --dev true
For release:
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/build/intermediates/res/merged/release/