Skip to content

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

Closed

Description

@dannycochran

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

Activity

  1. SandroMachado commented on Dec 20, 2016

    @SandroMachado
    Contributor

    Use --configuration and not --config.

    2a2d3c6#diff-a003f89d34db18b4567fdb55080a003eR230

  2. dannycochran commented on Dec 20, 2016

    @dannycochran
    ContributorAuthor

    @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?

  3. SandroMachado commented on Dec 20, 2016

    @SandroMachado
    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?

  4. dannycochran commented on Dec 20, 2016

    @dannycochran
    ContributorAuthor

    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

  5. SandroMachado commented on Dec 20, 2016

    @SandroMachado
    Contributor

    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

  6. dannycochran commented on Dec 21, 2016

    @dannycochran
    ContributorAuthor

    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
    
  7. SandroMachado commented on Dec 21, 2016

    @SandroMachado
    Contributor

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

  8. dannycochran commented on Dec 21, 2016

    @dannycochran
    ContributorAuthor

    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.

  9. dannycochran commented on May 17, 2017

    @dannycochran
    ContributorAuthor

    this was fixed by 0.41.0

  10. sahir commented on May 24, 2017

    @sahir

    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/

  11. erm3nda commented on Jul 5, 2017

    @erm3nda

    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.

  12. locked as resolved and limited conversation to collaborators on May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions