error when generating Apk file in react native - android

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 :)

Related

Error while evaluating property 'extraGeneratedResDir' of task ':app:mapReleaseSourceSetPaths'

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.

Failed to Build .apk in react native (You have symlinks in your project - watchman does not follow symlinks)

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

gradlew assembleRelease command in react-native android is not generating the app-release.apk

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/

react-native bundle throws SyntaxError in dev and prod mode

I am using react-native to bundle an Android APK.
I am able to run it properly in dev mode but have not been able to release a signed apk yet.
node version: `v5.10.0`
npm version: `3.8.3`
react-native version: `0.22.2`
Tried with babel-core versions
6.5.1
6.4.5
6.7.4
The error I am getting on running either of these commands
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/
react-native bundle --platform android --dev true --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
is
bundle: Created ReactPackager
uncaught error Error: SyntaxError: /Users/'username'/projects/personal/openchs/openchs-client/node_modules/react-native/Libraries/react-native/react-native.js:
Unexpected token (120:2)
// Note: this must be placed last to prevent eager
// evaluation of the getter-wrapped submodules above
...require('React'),
};
if (__DEV__) {
at Parser.pp.raise (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:1378:13)
at Parser.pp.unexpected (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:2817:8)
at Parser.pp.parseIdentifier (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:1227:10)
at Parser.pp.parsePropertyName (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:1070:135)
at Parser.pp.parseObj (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:986:12)
at Parser.pp.parseExprAtom (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:718:19)
at Parser.parseExprAtom (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:4305:22)
at Parser.pp.parseExprSubscripts (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:504:19)
at Parser.pp.parseMaybeUnary (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:484:19)
at Parser.pp.parseExprOps (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/babylon/index.js:415:19)
See logs /var/folders/zj/sk4075x566l8jdl1gwzjl79h0000gn/T/react-packager.log
at SocketClient._handleMessage (SocketClient.js:144:23)
at BunserBuf.<anonymous> (SocketClient.js:53:42)
at emitOne (events.js:90:13)
at BunserBuf.emit (events.js:182:7)
at BunserBuf.process (/Users/mihir/projects/personal/openchs/openchs-client/node_modules/bser/index.js:289:10)
at /Users/mihir/projects/personal/openchs/openchs-client/node_modules/bser/index.js:244:12
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
More of my code is here - https://github.com/OpenCHS/openchs-client
Anyone that finds this and is looking for the answer, it can be found here: SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
you will need to install babel-preset-react-native-stage-0 package and include it in your .babelrc presets array

React native android code push installRelease build fails

I am trying to add code push to my react native app, and followed all steps mentioned in https://github.com/Microsoft/react-native-code-push
After doing it, my debug build works fine
I use :
$ ./gradlew installDebug
but the release build fails which is given by following command :
$ ./gradlew installRelease
which gives following error :
:app:generateReleaseResources
:app:mergeReleaseResources
:app:bundleReleaseJsAndAssets
FAILURE: Build failed with an exception.
* What went wrong:
Could not list contents of '/Users/jayshah/Documents/testdir/ExampleApp/node_modules/.bin/_mocha'.
GitHub
Microsoft/react-native-code-push
react-native-code-push - React Native plugin for the CodePush service.
I use following command to generate the bundle :
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
my react native version is 0.18,
code push version is 0.16
Turns out this is a problem frequently encountered when upgrading in react native from pre 0.15 to post 0.15 versions.
The react gradle task bundleReleaseJsAndAssets seems to be the culprit.
one can disable it using
enabled config.bundleInRelease ?: false
in react.gradle or comment the line (no guarantees to work properly though)
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
and manually made bundle file using
react-native bundle 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/src/main/res/
or curl based command
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

Categories

Resources