react-native icon indicating copy to clipboard operation
react-native copied to clipboard

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

Open idan-ratzabi opened this issue 10 years ago • 26 comments

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 ?

idan-ratzabi avatar Apr 27 '16 13:04 idan-ratzabi

@facebook-github-bot label Android

AndrewJack avatar Apr 27 '16 18:04 AndrewJack

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 avatar Apr 28 '16 15:04 idan-ratzabi

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 avatar Apr 28 '16 20:04 dsibiski

@facebook-github-bot expected

dsibiski avatar Apr 28 '16 20:04 dsibiski

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 avatar Apr 28 '16 20:04 ghost

@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 avatar Apr 29 '16 05:04 idan-ratzabi

@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. 😄

dsibiski avatar Apr 29 '16 10:04 dsibiski

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 avatar Apr 29 '16 13:04 idan-ratzabi

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

dsibiski avatar Apr 29 '16 14:04 dsibiski

@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 avatar Apr 29 '16 14:04 idan-ratzabi

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:

dsibiski avatar Apr 29 '16 14:04 dsibiski

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

idan-ratzabi avatar Apr 29 '16 16:04 idan-ratzabi

@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 : https://github.com/facebook/react-native/issues/7325

idan-ratzabi avatar May 02 '16 09:05 idan-ratzabi

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 avatar May 19 '16 12:05 AvatarQing

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

idan-ratzabi avatar May 19 '16 12:05 idan-ratzabi

@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 avatar May 19 '16 13:05 AvatarQing

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 avatar May 19 '16 13:05 idan-ratzabi

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 avatar May 20 '16 00:05 AvatarQing

Great you found it!

idan-ratzabi avatar May 20 '16 03:05 idan-ratzabi

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

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

zhangwebb avatar Jun 02 '16 16:06 zhangwebb