Skip to content
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

Cannot run Android release build when index.android.js not in main directory #11571

Closed
dannycochran opened this issue Dec 20, 2016 · 11 comments
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@dannycochran
Copy link
Contributor

dannycochran commented Dec 20, 2016

Description

I recently upgraded to react-native 0.39.2 from 0.37, and my command to run a production build on the emulator no longer works.

react-native run-android --configuration Release --variant prod --root artifacts/lib

Fails with the error:

Cannot find entry file index.android.js in any of the roots: ["/Users/Documents/reactApp"]

I'm using Typescript to compile assets into an artifacts folder, such that my directory structure is:

  • reactApp
    • package.json
    • ios
    • android
      • gradle
      • ...
    • artifacts
      • lib
        • index.android.js
        • ...
      • ...
    • src
      • lib
        • index.android.ts
        • ...
      • ...

Reproduction

Have a directory structure similar to the one above where index.android.js is not in the main directory folder and run:
react-native run-android --configuration Release --variant prod

Solution

I believe this was caused by a pull request in 0.39, from @SandroMachado

2a2d3c6#diff-a003f89d34db18b4567fdb55080a003eR103

The react-native bundle command seems to assume the index.android.js exists in the root directory of a project, and no longer sets the process current directory to be the root arg passed in when running react-native run-android.

Additional Information

  • React Native version: 0.39.2
  • Platform: Android
  • Operating System: MacOS
@SandroMachado
Copy link
Contributor

SandroMachado commented Dec 20, 2016

Use --configuration and not --config.

2a2d3c6#diff-a003f89d34db18b4567fdb55080a003eR230

@dannycochran
Copy link
Contributor Author

dannycochran commented Dec 20, 2016

@SandroMachado sorry, my mistake. I am using --configuration.

I was thinking the issue is on line 110 of local-cli/runAndroid/runAndroid.js -- the index.android.js entry file is always expected to be at the root directory, no?

@SandroMachado
Copy link
Contributor

This is the command executed to generate the release react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output ${androidProjectDir}/app/src/main/assets/index.android.bundle --assets-dest ${androidProjectDir}/app/src/main/res/

So the problem is your index.android.js is under the artifacts directory?

@dannycochran
Copy link
Contributor Author

correct, index.android.js is under artifacts/lib.

when running in dev, I run two separate commands on two different terminal screens:

screen 1:
node node_modules/react-native/local-cli/cli.js start --root artifacts/lib --reset-cache
screen 2:
react-native run-android --variant dev

In production, I run:

react-native run-android --configuration Release --variant prod --root artifacts/lib

But the artifacts/lib root isn't respected for the line you pasted above, line 110 of local-cli/runAndroid/runAndroid.js

@SandroMachado
Copy link
Contributor

SandroMachado commented Dec 20, 2016

Yup, it is an issue. It is easy to fix, unfortunately that code is not on master anymore. It was removed by 85c8333 So, I cannot make a PR to fix it...

BTW, as a quick fix you can run the release command, directly, I pasted above and fix the directory. It should work.

react-native bundle --platform android --dev false --entry-file artifacts/lib/index.android.js ...

/cc @grabbou

@dannycochran
Copy link
Contributor Author

dang. what would the fix look like? I hardcoded line 115 to look like this:

'--entry-file artifacts/lib/index.android.js ' +

and that results in a new error that makes little sense to me:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processProdReleaseResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/dannycochran/Library/Android/sdk/build-tools/23.0.1/aapt'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

@SandroMachado
Copy link
Contributor

SandroMachado commented Dec 21, 2016

Hum, can this be a memory (RAM) issue? In the past, developing for Android, I saw that kind of errors caused by insufficient memory.

@dannycochran
Copy link
Contributor Author

I'm guessing this is a separate issue from the one I originally posted, and may have to do with the fact that my app has a webview which loads various assets. When I run:

react-native run-android --configuration Release --variant prod

Five additional directories are created in android/app/src/main/res/:

  • drawable-hdpi
  • drawable-mdpi
  • drawable-xhdpi
  • drawable-xxhdpi
  • drawable-xxxhdpi

The bundler also creates two files in android/app/src/main/assets/:

  • index.android.bundle
  • index.android.bundle.meta

If I remove all these files right after they're created (git clean -f -d) by the bundle command, the app builds successfully on the emulator. If I don't remove them, I get the error above.

@dannycochran
Copy link
Contributor Author

this was fixed by 0.41.0

@sahir
Copy link

sahir commented May 24, 2017

Thanks @dannycochran it's fixed in 0.41.0. This is the command executed to generate the release Bundle.

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/

@erm3nda
Copy link

erm3nda commented Jul 5, 2017

Case of my install i have modified the @sahir 's command to:

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/

Now the bundle file is present.

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants