New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react.gradle doesn't create index.android.bundle - Android #7258

Closed
idan-ratzabi opened this Issue Apr 27, 2016 · 26 comments

Comments

Projects
None yet
@idan-ratzabi

idan-ratzabi commented Apr 27, 2016

I created a sample project using 'react-native init project' on Mac OS.

When I run ./gradlew assembleRelease no index.android.bundle file gets created.
Plus no react related tasks appear in Android Studio.

It seems like the command:
commandLine "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir doesn't run.
When I run the same command manually everything works smoothly.

Not sure how relevant this is but the command :```

            doFirst {
                   jsBundleDir.mkdirs()
                  resourcesDir.mkdirs()
            }

Also doesn't work, unless I take both commands outside the "doFirst".

Any suggestions ?

@AndrewJack

This comment has been minimized.

Show comment
Hide comment
@AndrewJack

AndrewJack Apr 27, 2016

Contributor

@facebook-github-bot label Android

Contributor

AndrewJack commented Apr 27, 2016

@facebook-github-bot label Android

@ghost ghost added Android Ran Commands labels Apr 27, 2016

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi Apr 28, 2016

So i'm pretty sure it's gradle related. When I put the same code inside a script it works.

So now I call it like this:
commandLine './packageJS.sh',"--devEnabled","${devEnabled}", "--entryFile", entryFile, "--jsBundleFile", jsBundleFile, "--resourcesDir", resourcesDir

And my packageJS.sh :

while [[ "$#" > 1 ]]; do case $1 in
    --entryFile) entryFile="$2";;
    --devEnabled) devEnabled="$2";;
    --jsBundleFile) jsBundleFile="$2";;
    --resourcesDir) resourcesDir="$2";;
    *);;
  esac; shift
done

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev ${devEnabled} --entry-file ${entryFile} --bundle-output ${jsBundleFile} --assets-dest ${resourcesDir}

exit 0

The last thing is that for some reason the task bundleReleaseJsAndAssets doesn't seem to run, so what I ended up doing is :

// Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
            currentBundleTask.dependsOn("merge${targetName}Resources")
            currentBundleTask.dependsOn("merge${targetName}Assets")

            runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
            runBefore("processX86${targetName}Resources", currentBundleTask)
            runBefore("processUniversal${targetName}Resources", currentBundleTask)
            runBefore("process${targetName}Resources", currentBundleTask)

            currentBundleTask.execute()


And to generate the **index.android.bundle** file:
`./gradlew assembleRelease`

P.S - Worth mentioning that this still doesn't work when I build the project for release inside Android Studio. For that to work I had to create a symbolic link :
ln -s /Users/**<your_user>**/.nvm/versions/node/v5.10.1/bin/node /usr/local/node

And inside react.gradle I add the following:
def PATH = environment.getAt("PATH")
PATH = PATH + ":/usr/local"
environment.putAt("PATH",PATH)

idan-ratzabi commented Apr 28, 2016

So i'm pretty sure it's gradle related. When I put the same code inside a script it works.

So now I call it like this:
commandLine './packageJS.sh',"--devEnabled","${devEnabled}", "--entryFile", entryFile, "--jsBundleFile", jsBundleFile, "--resourcesDir", resourcesDir

And my packageJS.sh :

while [[ "$#" > 1 ]]; do case $1 in
    --entryFile) entryFile="$2";;
    --devEnabled) devEnabled="$2";;
    --jsBundleFile) jsBundleFile="$2";;
    --resourcesDir) resourcesDir="$2";;
    *);;
  esac; shift
done

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev ${devEnabled} --entry-file ${entryFile} --bundle-output ${jsBundleFile} --assets-dest ${resourcesDir}

exit 0

The last thing is that for some reason the task bundleReleaseJsAndAssets doesn't seem to run, so what I ended up doing is :

// Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
            currentBundleTask.dependsOn("merge${targetName}Resources")
            currentBundleTask.dependsOn("merge${targetName}Assets")

            runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
            runBefore("processX86${targetName}Resources", currentBundleTask)
            runBefore("processUniversal${targetName}Resources", currentBundleTask)
            runBefore("process${targetName}Resources", currentBundleTask)

            currentBundleTask.execute()


And to generate the **index.android.bundle** file:
`./gradlew assembleRelease`

P.S - Worth mentioning that this still doesn't work when I build the project for release inside Android Studio. For that to work I had to create a symbolic link :
ln -s /Users/**<your_user>**/.nvm/versions/node/v5.10.1/bin/node /usr/local/node

And inside react.gradle I add the following:
def PATH = environment.getAt("PATH")
PATH = PATH + ":/usr/local"
environment.putAt("PATH",PATH)

@dsibiski

This comment has been minimized.

Show comment
Hide comment
@dsibiski

dsibiski Apr 28, 2016

Contributor

When you run ./gradlew assembleRelease it does indeed create the bundle, but it creates it in the app/build/intermediates/assets/release directory, so you wouldn't see that in your source control or even know that it exists normally.

Contributor

dsibiski commented Apr 28, 2016

When you run ./gradlew assembleRelease it does indeed create the bundle, but it creates it in the app/build/intermediates/assets/release directory, so you wouldn't see that in your source control or even know that it exists normally.

@dsibiski

This comment has been minimized.

Show comment
Hide comment
@dsibiski
Contributor

dsibiski commented Apr 28, 2016

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Apr 28, 2016

The comment above tells me this is expected behavior. Closing this as we'd like to use the GitHub issue tracker for bugs. If you'd like to change how this feature works please post a feature request on Product Pains so that other people can vote on it.

ghost commented Apr 28, 2016

The comment above tells me this is expected behavior. Closing this as we'd like to use the GitHub issue tracker for bugs. If you'd like to change how this feature works please post a feature request on Product Pains so that other people can vote on it.

@ghost ghost closed this Apr 28, 2016

@ghost ghost added the Ran Commands label Apr 28, 2016

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi Apr 29, 2016

@dsibiski I obviously know it should have been created it in the app/build/intermediates/assets/release folder, that's exactly the problem, that for me it doesn't.
It looks like you're not experiencing the issue I am.

idan-ratzabi commented Apr 29, 2016

@dsibiski I obviously know it should have been created it in the app/build/intermediates/assets/release folder, that's exactly the problem, that for me it doesn't.
It looks like you're not experiencing the issue I am.

@dsibiski

This comment has been minimized.

Show comment
Hide comment
@dsibiski

dsibiski Apr 29, 2016

Contributor

@idan-ratzabi Thanks for clarifying. Just to be sure, you definitely have a valid keystore there setup in your build.gradle?

Also if it's at all possible to put together a sample repo ready to run this command (with a keystore and everything) it would greatly help us to be able to more easily debug on our end. 😄

Contributor

dsibiski commented Apr 29, 2016

@idan-ratzabi Thanks for clarifying. Just to be sure, you definitely have a valid keystore there setup in your build.gradle?

Also if it's at all possible to put together a sample repo ready to run this command (with a keystore and everything) it would greatly help us to be able to more easily debug on our end. 😄

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi Apr 29, 2016

Actually it happens even on an empty project created with react-native init.
I'm attaching the one i just created again to make sure. I also created a key store with it.

running ./gradlew assembleRelease doesn't produce any index.android.bundle file.
I suspect it might be an issue with my environment, though I'm not 100% sure.

Awesome2.zip

idan-ratzabi commented Apr 29, 2016

Actually it happens even on an empty project created with react-native init.
I'm attaching the one i just created again to make sure. I also created a key store with it.

running ./gradlew assembleRelease doesn't produce any index.android.bundle file.
I suspect it might be an issue with my environment, though I'm not 100% sure.

Awesome2.zip

@dsibiski

This comment has been minimized.

Show comment
Hide comment
@dsibiski

dsibiski Apr 29, 2016

Contributor

@idan-ratzabi Yeah it looks like it's a problem with your env as the bundle builds fine for me:

Contributor

dsibiski commented Apr 29, 2016

@idan-ratzabi Yeah it looks like it's a problem with your env as the bundle builds fine for me:

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi Apr 29, 2016

@dsibiski so weird. Have no idea what could it be. Can you tell me your environment details ? OS, Gradle version, shell etc'.... Thanks

idan-ratzabi commented Apr 29, 2016

@dsibiski so weird. Have no idea what could it be. Can you tell me your environment details ? OS, Gradle version, shell etc'.... Thanks

@dsibiski

This comment has been minimized.

Show comment
Hide comment
@dsibiski

dsibiski Apr 29, 2016

Contributor

OS X 10.10.5
Gradle Version: 2.10 (it seems like it gets installed with each app, not globally)
Shell: zsh

This is what I have installed for Android:

Contributor

dsibiski commented Apr 29, 2016

OS X 10.10.5
Gradle Version: 2.10 (it seems like it gets installed with each app, not globally)
Shell: zsh

This is what I have installed for Android:

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi Apr 29, 2016

Looks like we have more or less the same environment :/

idan-ratzabi commented Apr 29, 2016

Looks like we have more or less the same environment :/

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi May 2, 2016

@dsibiski Apparently the issue was org.gradle.configureondemand=true set in my gradle.properties.
Had to remove it and stuff went back to normal on my local machine.

Unfortunately now I have the same issue on Travis, though there the gradle properties seem to be fine. Maybe you can help with that ?
Opened another issue :
#7325

idan-ratzabi commented May 2, 2016

@dsibiski Apparently the issue was org.gradle.configureondemand=true set in my gradle.properties.
Had to remove it and stuff went back to normal on my local machine.

Unfortunately now I have the same issue on Travis, though there the gradle properties seem to be fine. Maybe you can help with that ?
Opened another issue :
#7325

@AvatarQing

This comment has been minimized.

Show comment
Hide comment
@AvatarQing

AvatarQing May 19, 2016

I face the same problem , and I did not add org.gradle.configureondemand=true in my gradle.properties, assembleRelease does not run bundleReleaseJsAndAssets task.

AvatarQing commented May 19, 2016

I face the same problem , and I did not add org.gradle.configureondemand=true in my gradle.properties, assembleRelease does not run bundleReleaseJsAndAssets task.

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi May 19, 2016

@AvatarQing did you check in your ~./gradle folder as well ? Do you use flavor dimensions by any chance ?

idan-ratzabi commented May 19, 2016

@AvatarQing did you check in your ~./gradle folder as well ? Do you use flavor dimensions by any chance ?

@AvatarQing

This comment has been minimized.

Show comment
Hide comment
@AvatarQing

AvatarQing May 19, 2016

@idan-ratzabi Hi, thanks for reply, I think I found the reason. My OS is windows7, I created an empty project with react-native init, and configed a keystore for release build type, now if I run gradle assembleRelease in command line,bundleReleaseJsAndAssets is executed, but when I run app in Android Studio (I choose the build variant to release), bundleReleaseJsAndAssets doesn't executed. I just thought the two ways have the same functionality, but now it appears there is something different between them. I can't figure out the difference for now.

AvatarQing commented May 19, 2016

@idan-ratzabi Hi, thanks for reply, I think I found the reason. My OS is windows7, I created an empty project with react-native init, and configed a keystore for release build type, now if I run gradle assembleRelease in command line,bundleReleaseJsAndAssets is executed, but when I run app in Android Studio (I choose the build variant to release), bundleReleaseJsAndAssets doesn't executed. I just thought the two ways have the same functionality, but now it appears there is something different between them. I can't figure out the difference for now.

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi May 19, 2016

The only difference I can think of are environment variables might not be present while running from Android Studio, so perhaps it can't find some modules (node, for instance) ? But you say no error appears, so i'm not sure either..

idan-ratzabi commented May 19, 2016

The only difference I can think of are environment variables might not be present while running from Android Studio, so perhaps it can't find some modules (node, for instance) ? But you say no error appears, so i'm not sure either..

@AvatarQing

This comment has been minimized.

Show comment
Hide comment
@AvatarQing

AvatarQing May 20, 2016

You said exactly right. In Android Studio, go to File | Settings | Build, Execution, Deployment | Compiler, the option Configure on demand is checked by default for speeding up builds, uncheck it then everything is ok now.

AvatarQing commented May 20, 2016

You said exactly right. In Android Studio, go to File | Settings | Build, Execution, Deployment | Compiler, the option Configure on demand is checked by default for speeding up builds, uncheck it then everything is ok now.

@idan-ratzabi

This comment has been minimized.

Show comment
Hide comment
@idan-ratzabi

idan-ratzabi May 20, 2016

Great you found it!

idan-ratzabi commented May 20, 2016

Great you found it!

@zhangwebb

This comment has been minimized.

Show comment
Hide comment
@zhangwebb

zhangwebb Jun 2, 2016

Great! Cool!!
not add org.gradle.configureondemand=true in gradle.properties
but, why?

Thank you @AvatarQing @idan-ratzabi ...and everybody !

zhangwebb commented Jun 2, 2016

Great! Cool!!
not add org.gradle.configureondemand=true in gradle.properties
but, why?

Thank you @AvatarQing @idan-ratzabi ...and everybody !

@luoyushouchai

This comment has been minimized.

Show comment
Hide comment
@luoyushouchai

luoyushouchai Mar 3, 2017

@zhangwebb Enables new incubating mode that makes Gradle selective when configuring projects. Only relevant projects are configured which results in faster builds for large multi-projects. See the section called “Configuration on demand”.****

luoyushouchai commented Mar 3, 2017

@zhangwebb Enables new incubating mode that makes Gradle selective when configuring projects. Only relevant projects are configured which results in faster builds for large multi-projects. See the section called “Configuration on demand”.****

@wildseansy

This comment has been minimized.

Show comment
Hide comment
@wildseansy

wildseansy Mar 9, 2017

Contributor

If I disable Configure on Demand, I start gradle errors with the following:

* What went wrong:
Execution failed for task ':app:recordFilesBeforeBundleCommandDebug'.
> A problem occurred starting process 'command 'node''

I'm running React 42 with Android Studio 2.3, buildToolsVersion 25.0.2

Looking around stack overflow, a lot of sources point to using Code Push (which I use). Does anyone else get this problem?

Contributor

wildseansy commented Mar 9, 2017

If I disable Configure on Demand, I start gradle errors with the following:

* What went wrong:
Execution failed for task ':app:recordFilesBeforeBundleCommandDebug'.
> A problem occurred starting process 'command 'node''

I'm running React 42 with Android Studio 2.3, buildToolsVersion 25.0.2

Looking around stack overflow, a lot of sources point to using Code Push (which I use). Does anyone else get this problem?

@ChasonTang

This comment has been minimized.

Show comment
Hide comment
@ChasonTang

ChasonTang Jun 14, 2017

@AvatarQing is right, the issue is happen with the featureConfigure on Demand

ChasonTang commented Jun 14, 2017

@AvatarQing is right, the issue is happen with the featureConfigure on Demand

@susheelramadoss

This comment has been minimized.

Show comment
Hide comment
@susheelramadoss

susheelramadoss Nov 29, 2017

@wildseansy did you manage resolve the issue ? i get the similar issue -

  • Execution failed for task ':bundle{*}JsAndAssets'
  • Process 'command 'node'' finished with non-zero exit value 1

susheelramadoss commented Nov 29, 2017

@wildseansy did you manage resolve the issue ? i get the similar issue -

  • Execution failed for task ':bundle{*}JsAndAssets'
  • Process 'command 'node'' finished with non-zero exit value 1
@SweetInk

This comment has been minimized.

Show comment
Hide comment
@SweetInk

SweetInk Feb 2, 2018

@AvatarQing 今天才接触RN,遇到了上述问题,感谢老铁,关掉那个选项后,就能正常打包了。

SweetInk commented Feb 2, 2018

@AvatarQing 今天才接触RN,遇到了上述问题,感谢老铁,关掉那个选项后,就能正常打包了。

@Willyham

This comment has been minimized.

Show comment
Hide comment
@Willyham

Willyham May 23, 2018

For anyone having this problem where Configure on Demand is off, ensure that you have:

apply from: "../../node_modules/react-native/react.gradle"

in your build.gradle file. It's there by default, but was somehow removed along the way for our project.

Willyham commented May 23, 2018

For anyone having this problem where Configure on Demand is off, ensure that you have:

apply from: "../../node_modules/react-native/react.gradle"

in your build.gradle file. It's there by default, but was somehow removed along the way for our project.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.