react.gradle file not bundling Js code
See original GitHub issuei uncommented app.gradle code to following
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*/
project.ext.react = [
// the name of the generated asset file containing your JS bundle
bundleAssetName: "index.android.bundle",
// the entry file for bundle generation
entryFile: "index.android.js",
// whether to bundle JS and assets in debug mode
bundleInDebug: true,
// whether to bundle JS and assets in release mode
bundleInRelease: true,
// whether to bundle JS and assets in another build variant (if configured).
// See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
// The configuration property can be in the following formats
// 'bundleIn${productFlavor}${buildType}'
// 'bundleIn${buildType}'
// bundleInFreeDebug: true,
// bundleInPaidRelease: true,
// bundleInBeta: true,
// the root of your project, i.e. where "package.json" lives
root: "../../",
// where to put the JS bundle asset in debug mode
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
// where to put the JS bundle asset in release mode
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
// where to put drawable resources / React Native assets, e.g. the ones you use via
// require('./image.png')), in debug mode
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
// where to put drawable resources / React Native assets, e.g. the ones you use via
// require('./image.png')), in release mode
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
// by default the gradle tasks are skipped if none of the JS files or assets change; this means
// that we don't look at files in android/ or ios/ to determine whether the tasks are up to
// date; if you have any other folders that you want to ignore for performance reasons (gradle
// indexes the entire tree), add them here. Alternatively, if you have JS files in android/
// for example, you might want to remove it from here.
inputExcludes: ["android/**", "ios/**"],
// override which node gets called and with what additional arguments
nodeExecutableAndArgs: ["node"],
// supply additional arguments to the packager
extraPackagerArgs: []
]
apply from: "../../node_modules/react-native/react.gradle"
but no js is bundled in apk file upon building in both debug and release mode and no js files are placed in assets folder.
and following exception is thrown
08-27 03:52:08.736 9630-9630/com.simpfuel E/unknown:React: Exception in native call from JS
java.lang.RuntimeException: Could not get BatchedBridge, make sure your bundle is packaged correctly
at com.facebook.react.cxxbridge.CatalystInstanceImpl.loadScriptFromAssets(Native Method)
at com.facebook.react.cxxbridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:37)
at com.facebook.react.cxxbridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:177)
at com.facebook.react.XReactInstanceManagerImpl$4.call(XReactInstanceManagerImpl.java:889)
at com.facebook.react.XReactInstanceManagerImpl$4.call(XReactInstanceManagerImpl.java:882)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$1.run(MessageQueueThreadImpl.java:74)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:148)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at java.lang.Thread.run(Thread.java:818)
i am using react-native version 0.32.0
on windows 10 and for android
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Bundling React-native android release not picking up code ...
gradlew assembleRelease is not bundling the code changes unless I run a script : ... react.gradle is applied in app/build.gradle file
Read more >Bundling React Native during Android release builds
Looking into the react-native directory reveals a Gradle file that defines a bundling task. This is the react.gradle file that is mentioned in...
Read more >RAM Bundles and Inline Requires - React Native
Before react-native can execute JS code, that code must be loaded into memory and parsed. With a standard bundle if you load a...
Read more >Bundling React Native during Android release builds
Looking into the react-native directory reveals a Gradle file that defines a bundling task. This is the react.gradle file that is mentioned in ......
Read more >Exploring React Native's new architecture - LogRocket Blog
cd .. yarn add react-native-gradle-plugin code android/settings.gradle ... a React Native application is run, the JavaScript code is bundled ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So I think I figured it all out, I definitely now have builds reliably running properly when hitting the “Run” button.
There are two issues (on OSX):
bundle[buildType]JsAndAssets
step for release-type buildsTo Solve:
1) Bundling being skipped
Uncheck “Configure on demand” as discussed above
2) Android Studio not finding node
Even after fixing bundling being skipped, the build still fails with
A problem occurred starting process 'command 'node''
. As noted by @andpor:There are workarounds for trying to get OSX apps to use your PATH, but basically - they’re all terrible, relatively difficult, require restarts, and generally break between OSX versions, and for other reasons.
So the solution - when
gradle
runs, it checksgradle.properties
as follows (documented at https://docs.gradle.org/current/userguide/build_environment.html):What we want to do is tell
gradle
directly what the node path is. We don’t want to do this in the project’sgradle.properties
- you’ll commit that to version control, and the node path may vary between developers.Instead, you set it in the
gradle
user home. Users can override this, but generally it’sUSER_HOME/.gradle
, so on OSX, generally~/.gradle
. So (and this is the bit you want to add to your project README so your developers know how to configure it), we can configure our node path for gradle like this:Now open
~/.gradle/gradle.properties
in your preferred editor, and add the line:NODE_PATH=/usr/local/bin/node
Or wherever your node install is located of course - check this with$ which node
Open
android/app/build.gradle
There should be a line that saysapply from: "../../node_modules/react-native/react.gradle"
Just before that line, add the following (or add to your existingproject.ext.react
if you have one):The
nodeExecutableAndArgs
is something you can configure for thereact
gradle
file, which makes it use the path and args you supply, instead of looking in the environment (as discussed above, the environment won’t work). This line checks whether theNODE_PATH
has been configured, and uses it if supplied, and if not, sets the property to null (which causes thereact
gradle file to fall back to using the environment)I was able to get this working in Android Studio by going to Preferences > Build, Execution, Deployment > Build Tools > Compiler and unchecking “Configure on demand”.
It was always working for me when running
./gradlew assembleRelease
from the command line, which is why I suspected an Android Studio config issue. Anyway, those are two things to try.