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

Flavors & App Bundle missing index.android.bundle #29398

Closed
lorenzoangelini opened this issue Jul 16, 2020 · 38 comments
Closed

Flavors & App Bundle missing index.android.bundle #29398

lorenzoangelini opened this issue Jul 16, 2020 · 38 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@lorenzoangelini
Copy link

Description

We use the flavors into our apps to use different version. We have dev, test and prod. When we have upgraded to 0.63, to classpath("com.android.tools.build:gradle:3.5.3") and distributionUrl=https://services.gradle.org/distributions/gradle-6.2-all.zip, we cannot use the appbundle.
when we run ./gradlew bundleDevRelease -> we cannot find into the app-dev-release.aab the index.android.bundle. This cause a crash when open the app.
If we run this command : ./gradlew bundleRelease -> it build all variants
app-dev-release.aab -> missing
app-test-release.aab -> index.android.bundle present
app-prod-release.aab -> index.android.bundle present

it seems that the first time not set the index.android.bundle into assets

React Native version:

System:
OS: macOS 10.15.2
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 382.96 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 11.10.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 27, 28, 29
Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.2
System Images: android-19 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-27 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_201 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

1.Create a new project: npx react-native init AppName --template react-native-template-typescript
2. Add to gradle.build :
productFlavors {
prod {
}
dev {
applicationId 'com.appname.dev'
resValue "string", "build_config_package", "com.appname"
}
test {
applicationId 'com.appname.test'
resValue "string", "build_config_package", "com.appname"
}
}
3. run into android folder : ./gradlew clean && ./gradlew bundleDevRelease

Expected Results

Obtain an .aab file into android/build/outputs/bundle/devRelease. when i open the .aab i expect to find the folder base and into the base the folder assets that contain the index.android.bundle.

@react-native-bot react-native-bot added Platform: Android Android applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. labels Jul 16, 2020
@thanakij
Copy link

One more clue here, I find that we have to run ./gradlew bundleRelease twice as "index.android.bundle" will be missing in the first generated AAB. After running the same command again, this time "index.android.bundle" will be included in the final AAB.

@safaiyeh
Copy link
Contributor

safaiyeh commented Aug 24, 2020

Thanks for the issue @lorenzoangelini!

One more clue here, I find that we have to run ./gradlew bundleRelease twice as "index.android.bundle" will be missing in the first generated AAB. After running the same command again, this time "index.android.bundle" will be included in the final AAB.

Hmm are you saying after the second run of ./gradlew bundleRelease it is generated correctly?

@thanakij
Copy link

In a sense, yes. Below is what I have in my release script for Android side. It works well so far.

./gradlew clean
./gradlew bundleRelease; ./gradlew bundleRelease # Fix bug, index.android.bundle is not included in AAB
fastlane android upload

Otherwise, "index.android.bundle" won't be included in the generated AAB. I saw that "index.android.bundle" generation step is invoked but it is simply not included in AAB.

@lorenzoangelini
Copy link
Author

@safaiyeh @thanakij yes it seems that the first time the folder assets with "index.android.bundle" is not present.
Run twice the ./gradlew bundleRelease for me is not a just solution, because the build time is x2.
In my case if i run bundleRelease i get three apps, dev,test and production. Where in dev, it crash when launch the app, because is missing the "index.android.bundle".
The goal is launch for example ./gradlew bundleRelease and obtain the an aab that works, like the previous version of the gradle. I think that is a problem of cli.
I use a monorepo.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 24, 2020
@thanakij
Copy link

I would like to provide my setting below:

react-native: 0.62.2
Gradle: 6.4.1
Gradle Plugin: 4.0.1
proguard: enabled

Hopefully, this would help maintainers fix the issue.

@lorenzoangelini
Copy link
Author

With this i have the issue:
react-native: 0.63.2
com.android.tools.build:gradle:3.5.3
https://services.gradle.org/distributions/gradle-6.2-all.zip

With this version the issue is not present
react-native: 0.63.2
com.android.tools.build:gradle:3.4.2
https://services.gradle.org/distributions/gradle-5.5-all.zip

@patrickkempff
Copy link
Contributor

I have a build with the same problem. The bundle is missing but the images are copied correctly it seems.
Can anyone confirm their images are also present in the drawable folders?

@caseyli
Copy link

caseyli commented Sep 2, 2020

I can confirm that running a double-build (ie. ./gradlew bundleRelease twice) solves the issue. Not obviously a good long term solution, but definitely a hint to what's going on.

react-native: 0.63.2
com.android.tools.build:gradle:3.5.3

@alessioemireni
Copy link

@thanakij with the same gradle configuration and with

def enableProguardInReleaseBuilds = false

the index.android.js is correctly injected in the aab archive without the need to run a double-build.

I haven't reproduce the same behaviour with a new react-native project.

I think that the main problem is when there are multiple dex files as in my project.

@tomoima525
Copy link
Contributor

tomoima525 commented Oct 13, 2020

The same issue happened to me when com.android.tools.build:gradle: was updated to 3.5.3 => 4.1.0 and
https://services.gradle.org/distributions/gradle to 5.5 => 6.5

Seeing from reports from others looks like the issue is related to Gradle

Running assembleXX twice did resolve the issue locally

@evelant
Copy link

evelant commented Oct 13, 2020

I'm running into this as well. In my case I'm attempting to assembleRelease instead of bundleRelease.

Everything is correct in the APK (all assets present) except it's missing the bundle! The bundle gets generated without issue, it's sitting in the correct directory, it just never gets added to the APK for unknown reasons. I've been tearing my hair out all day trying to figure out how/why this is happening.

Unfortunately running assembleRelease twice does not solve the problem.

It's definitely caused by the upgrade to android gradle plugin 4.1. Reverting to 3.6.4 fixes the issue however I need to use 4.1 for other reasons.

@safaiyeh Did you ever get to take a look at this? I think it can be reproduced on any app with multidex by upgrading gradle to 6.5+ and android gradle plugin to 4.1.0+. Do a clean and then assembleRelease and the APK will contain everything except the app bundle which remains in the generated outputs.

@tomoima525
Copy link
Contributor

I have a reproducible project here => https://github.com/tomoima525/android_build_test_rn

@dulmandakh
Copy link
Contributor

dulmandakh commented Oct 14, 2020

@tomoima525 thanks, I'll look into it in next few days

@tomoima525
Copy link
Contributor

I'm running into this as well. In my case I'm attempting to assembleRelease instead of bundleRelease.

Everything is correct in the APK (all assets present) except it's missing the bundle! The bundle gets generated without issue, it's sitting in the correct directory, it just never gets added to the APK for unknown reasons. I've been tearing my hair out all day trying to figure out how/why this is happening.

Unfortunately running assembleRelease twice does not solve the problem.

It's definitely caused by the upgrade to android gradle plugin 4.1. Reverting to 3.6.4 fixes the issue however I need to use 4.1 for other reasons.

@safaiyeh Did you ever get to take a look at this? I think it can be reproduced on any app with multidex by upgrading gradle to 6.5+ and android gradle plugin to 4.1.0+. Do a clean and then assembleRelease and the APK will contain everything except the app bundle which remains in the generated outputs.

Are you running clean before running assembleRelease the second time? If you run clean then the asset bundle file gets removed so it will not be included in the apk/aab file

@evelant
Copy link

evelant commented Oct 14, 2020

@tomoima525 @dulmandakh I found a workaround. It seems to be a gradle task ordering issue. It appears that assets get merged before the bundle gets copied to the intermediate output directory. Adding the following to android/app/build.gradle forces the bundle copy task to happen before merging assets.

//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
        tasks.findAll { task ->
            task.name.startsWith('merge') && task.name.endsWith('Resources')
        }.each { t -> t.dependsOn "copyReleaseBundledJs" }
}

I have little knowledge of gradle so this isn't a great workaround, it doesn't account for different build variants etc but at least it works for basic :app:assembleRelease. I guess gradle or android plugin behavior changed at some point that causes this task ordering issue to crop up. I don't know enough about gradle to track down the actual source but hopefully this gives more knowledgeable people a good clue to go on =)

@tomoima525
Copy link
Contributor

@AndrewMorsillo Amazing, thank you for your input! Your idea does make sense and solves the issue. I dug into react.gradle and just gave a patch. The issue seems resolved by testing it on my reproducible repository.

@alessioemireni
Copy link

alessioemireni commented Oct 15, 2020

@tomoima525 @AndrewMorsillo In my case with Proguard enabled doesn't work. The intermediates/merged_asset is generated before generated/assets.

@tomoima525
Copy link
Contributor

@alessioemireni interesting. I'll check with my reproducible repository https://github.com/tomoima525/android_build_test_rn in my spare time( I turned off proguard in that project because assembleRelease failed with OOM). Can you also check the behavior with the fix I made in #30177 ?

@alessioemireni
Copy link

@tomoima525 yes, I have applied a patch with your fix, but the result is the same.

react-native: 0.62.2
gradle-tool: 6.0.1
gradle-plugin: 3.6.4

I have also increased the gradle plugin version to 4.1+ but the bundle is missing in aab.

@tomoima525
Copy link
Contributor

tomoima525 commented Oct 18, 2020

@alessioemireni your case seems something different. This is reproducible when android gradle plugin is 4.1 and gradle is 6.5.

In fact the issue did not happen with android gradle plugin 3.5.3/ gradle 6.2 on my environment somehow. (which strangely contradict with the original issue, but if you create an app with create-react-native-app it will come with plugin 3.5.3/ gradle 6.2 but the issue is not reproducible)

@tomoima525
Copy link
Contributor

@dulmandakh

I have the reproducible case and fixed case with the fix I made in #30177.
Do you mind reviewing & checking it?

Repository: https://github.com/tomoima525/android_build_test_rn

Reproducible case

To reproduce the issue, run the command below

$ cd android
$ ./gradlew clean :app:assembleRelease // or ./gradlew clean :app:releaseBundle

app-release.apk will be generated but it does not have index.android.bundle build

Fixed case

I added the fix in #30177 . Running the command below will apply the patch to react.gradle and you can see the issue is resolved

$ yarn add_patch
$ cd android
$ ./gradlew clean :app:assembleRelease // or ./gradlew clean :app:releaseBundle

index.android.bundle is generated under assets

Screen Shot 2020-10-17 at 11 28 40 PM

(The script is tested on Mac. If the copying does not work on Linux, try directly copying the react-patch.gradle to node_modules/react-native/react.gradle)

@plowman
Copy link

plowman commented Nov 9, 2020

Huge thanks to @tomoima525 and @AndrewMorsillo for all of your work finding a solution!

I was having a nearly identical issue where doing ./gradlew clean assembleProductionRelease would result in this error: java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. but ONLY when you did a clean. Running the same command again as ./gradlew assembleProductionRelease would work.

For people who don't want to manually patch the node_modules/react-native/react.gradle until React Native does the next release, I've hacked together a solution (based on the work of @tomoima525 and @AndrewMorsillo) that you can drop into your app/build.gradle at the top level:

// This forces the copy task to run before merge resources. This should be removable starting with RN 0.63.4.
project.afterEvaluate {
  def isAndroidLibrary = plugins.hasPlugin("com.android.library")
  def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants
  variants.all { def variant ->
    def targetName = variant.name.capitalize()
    def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
    def assetsCopyTask = tasks.findByName("copy${targetName}BundledJs")
    mergeResourcesTask.dependsOn(assetsCopyTask)
    logger.warn("Making task ${mergeResourcesTask} depend on ${assetsCopyTask}")
  }
}

@nilavassg
Copy link

Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately.

@FelipeLimaDeSouza
Copy link

Huge thanks to @tomoima525 and @AndrewMorsillo for all of your work finding a solution!

I was having a nearly identical issue where doing ./gradlew clean assembleProductionRelease would result in this error: java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release. but ONLY when you did a clean. Running the same command again as ./gradlew assembleProductionRelease would work.

For people who don't want to manually patch the node_modules/react-native/react.gradle until React Native does the next release, I've hacked together a solution (based on the work of @tomoima525 and @AndrewMorsillo) that you can drop into your app/build.gradle at the top level:

// This forces the copy task to run before merge resources. This should be removable starting with RN 0.63.4.
project.afterEvaluate {
  def isAndroidLibrary = plugins.hasPlugin("com.android.library")
  def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants
  variants.all { def variant ->
    def targetName = variant.name.capitalize()
    def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
    def assetsCopyTask = tasks.findByName("copy${targetName}BundledJs")
    mergeResourcesTask.dependsOn(assetsCopyTask)
    logger.warn("Making task ${mergeResourcesTask} depend on ${assetsCopyTask}")
  }
}

In my project assetsCopyTask is null

@plowman
Copy link

plowman commented Nov 18, 2020

Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately.

@nilavassg what command are you running and what error are you seeing?

In my project assetsCopyTask is null

@FelipeLimaDeSouza you can add a line so that mergeResourcesTask.dependsOn(assetsCopyTask) is only called if both mergeResourcesTask and assetsCopyTask are not null.

@FelipeLimaDeSouza
Copy link

Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately.

@nilavassg what command are you running and what error are you seeing?

In my project assetsCopyTask is null

@FelipeLimaDeSouza you can add a line so that mergeResourcesTask.dependsOn(assetsCopyTask) is only called if both mergeResourcesTask and assetsCopyTask are not null.

I did this but it comes null in all commands.

@plowman
Copy link

plowman commented Nov 18, 2020

I did this but it comes null in all commands.

@FelipeLimaDeSouza I see. I'm not an expert at any of this. My only guess is that tasks.findByName("copy${targetName}BundledJs") and tasks.findByName("merge${targetName}Resources") can't find the proper tasks in your environment. Perhaps because the targetName in these cases has different capitalization than what we're expecting? Idk.

If you do this you can find the steps which should be candidates:

# Starting at your root project directory
cd ./android
./gradlew tasks --all | grep -E "^app:merge.+Resources"
# For comparison, here is my output:
# app:mergeInternalDebugAndroidTestResources
# app:mergeInternalDebugResources
# app:mergeInternalReleaseResources
# app:mergeProductionDebugAndroidTestResources
# app:mergeProductionDebugResources
# app:mergeProductionReleaseResources

./gradlew tasks --all | grep -E "^app:copy.+BundledJs"
# For comparison, here is my output:
# app:copyInternalDebugBundledJs - copy bundled JS into InternalDebug.
# app:copyInternalReleaseBundledJs - copy bundled JS into InternalRelease.
# app:copyProductionDebugBundledJs - copy bundled JS into ProductionDebug.
# app:copyProductionReleaseBundledJs - copy bundled JS into ProductionRelease.

@FelipeLimaDeSouza
Copy link

I did this but it comes null in all commands.

@FelipeLimaDeSouza I see. I'm not an expert at any of this. My only guess is that tasks.findByName("copy${targetName}BundledJs") and tasks.findByName("merge${targetName}Resources") can't find the proper tasks in your environment. Perhaps because the targetName in these cases has different capitalization than what we're expecting? Idk.

If you do this you can find the steps which should be candidates:

# Starting at your root project directory
cd ./android
./gradlew tasks --all | grep -E "^app:merge.+Resources"
# For comparison, here is my output:
# app:mergeInternalDebugAndroidTestResources
# app:mergeInternalDebugResources
# app:mergeInternalReleaseResources
# app:mergeProductionDebugAndroidTestResources
# app:mergeProductionDebugResources
# app:mergeProductionReleaseResources

./gradlew tasks --all | grep -E "^app:copy.+BundledJs"
# For comparison, here is my output:
# app:copyInternalDebugBundledJs - copy bundled JS into InternalDebug.
# app:copyInternalReleaseBundledJs - copy bundled JS into InternalRelease.
# app:copyProductionDebugBundledJs - copy bundled JS into ProductionDebug.
# app:copyProductionReleaseBundledJs - copy bundled JS into ProductionRelease.

Even with the task in the task list, it returns null.
I had to run the "bunbleRelease" command twice to work.

@thanakij
Copy link

Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately.

Me too, the solution from @tomoima525 only solves some part of the problem. It is still not working in case of AAB.

I have gone through react.gradle file and investigated the output when running bundleRelease. The remaining issue is because the task copyReleaseBundleJs is executed before bundleReleaseJsAndAssets. In short, the copy task is executed before the actual JS generation task.

Below line will make it works with "bundleRelease" (in addition to "assembleRelease"):

currentAssetsCopyTask.dependsOn(currentBundleTask)

@nilavassg
Copy link

Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately.

@nilavassg what command are you running and what error are you seeing?

./gradlew bundleProdRelease

Also confirmed the same by @thanakij

@FelipeLimaDeSouza
Copy link

Desculpe comentar sobre este assunto novamente. Mas o patch de @plowman funciona apenas para builds de montagem, não, mas para empacotar aab, infelizmente.

Eu também, a solução de @ tomoima525 resolve apenas parte do problema. Ainda não está funcionando no caso de AAB.

Eu examinei o arquivo react.gradle e investiguei a saída ao executar bundleRelease . O problema restante é porque a tarefa copyReleaseBundleJs é executada antes de bundleReleaseJsAndAssets . Resumindo, a tarefa de cópia é executada antes da tarefa real de geração de JS.

A linha abaixo fará com que funcione com "bundleRelease" (além de "assembleRelease"):

currentAssetsCopyTask.dependsOn(currentBundleTask)

Did you change for that?

currentAssetsCopyTask.dependsOn(currentBundleTask)
def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
mergeResourcesTask.dependsOn(currentAssetsCopyTask)

@thanakij
Copy link

Below is what I have:

change

@FelipeLimaDeSouza
Copy link

Below is what I have:

change

Worked for me. Thank you

kelset pushed a commit that referenced this issue Nov 27, 2020
… plugin 4.1.0+/gradle 6.5 (#30177)

Summary:
- This fix resolves #29398
- After updating gradle to 6.5+ and android gradle plugin to 4.1.0+(which is recommended in the latest Android Studio 4.1), Running `:app:assembleRelease` or `:app:bundleRelease` will not contain `index.android.bundle` in Apk/AAB. It will be included when the command executed twice.
<img width="949" alt="Screen Shot 2020-10-17 at 11 32 43 PM" src="https://user-images.githubusercontent.com/6277118/96360808-38165c00-10d5-11eb-8b6e-f098517a24c7.png">

- This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5. `mergeResources` task runs before `currentAssetsCopyTask`(copying the bundle asset file to intermediate output directory) which causes generated Apk/AAB not including the bundle file.
- The fix ensures mergeResources task runs after currentAssetsCopyTask

## Changelog

[Android] [Fixed] - Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0/gradle 6.5

Pull Request resolved: #30177

Test Plan:
- Reproducible repository https://github.com/tomoima525/android_build_test_rn
  -  This project is generated with `create-react-native-app` and updated Gradle version to 6.5 and com.android.tools.build:gradle plugin to 4.1
- Run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => reproduces the issue
- After adding the fix above and run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => The issue is resolved

- Also confirmed the build works properly with android gradle plugin `3.5.3` and `gradle 6.2`(the default value of `create-react-native-app`)

Reviewed By: fkgozali

Differential Revision: D24551605

Pulled By: cpojer

fbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
@techinsider99
Copy link

@thanakij This works!🔥. Thank you.

cristeahub pushed a commit to HyreAS/react-native that referenced this issue Dec 21, 2020
… plugin 4.1.0+/gradle 6.5 (facebook#30177)

Summary:
- This fix resolves facebook#29398
- After updating gradle to 6.5+ and android gradle plugin to 4.1.0+(which is recommended in the latest Android Studio 4.1), Running `:app:assembleRelease` or `:app:bundleRelease` will not contain `index.android.bundle` in Apk/AAB. It will be included when the command executed twice.
<img width="949" alt="Screen Shot 2020-10-17 at 11 32 43 PM" src="https://user-images.githubusercontent.com/6277118/96360808-38165c00-10d5-11eb-8b6e-f098517a24c7.png">

- This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5. `mergeResources` task runs before `currentAssetsCopyTask`(copying the bundle asset file to intermediate output directory) which causes generated Apk/AAB not including the bundle file.
- The fix ensures mergeResources task runs after currentAssetsCopyTask

## Changelog

[Android] [Fixed] - Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0/gradle 6.5

Pull Request resolved: facebook#30177

Test Plan:
- Reproducible repository https://github.com/tomoima525/android_build_test_rn
  -  This project is generated with `create-react-native-app` and updated Gradle version to 6.5 and com.android.tools.build:gradle plugin to 4.1
- Run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => reproduces the issue
- After adding the fix above and run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => The issue is resolved

- Also confirmed the build works properly with android gradle plugin `3.5.3` and `gradle 6.2`(the default value of `create-react-native-app`)

Reviewed By: fkgozali

Differential Revision: D24551605

Pulled By: cpojer

fbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
@ilyagru
Copy link

ilyagru commented Jan 15, 2021

I can't make the .aab work. I just updated my RN version to 0.63.4 which contains the fix but it seems the issue comes from Bitrise (Assemble Release, Export Universal APK, Android Sign, Deploy to Google Play steps) which handle artefacts in an unexpected way but can't be sure...
bitrise-steplib/steps-gradle-runner#72
bitrise-steplib/steps-deploy-to-bitrise-io#93
If anyone has other ideas to look into, please let me know.

Tried with Gradle 3.5.3/6.2 and 4.1.2/6.5.

@cristianoccazinsp
Copy link
Contributor

Experiencing the same issue after migrating gradle from 3.5.3 to 4.1.0 and wrapper from 6.2 to 6.7. Very annoying issue.

Running ./gradlew assembleDevRelease ends up with a missing bundle file. Running it again, bundles it just fine.

@davistsin
Copy link

@tomoima525 @dulmandakh I found a workaround. It seems to be a gradle task ordering issue. It appears that assets get merged before the bundle gets copied to the intermediate output directory. Adding the following to android/app/build.gradle forces the bundle copy task to happen before merging assets.

//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
        tasks.findAll { task ->
            task.name.startsWith('merge') && task.name.endsWith('Resources')
        }.each { t -> t.dependsOn "copyReleaseBundledJs" }
}

I have little knowledge of gradle so this isn't a great workaround, it doesn't account for different build variants etc but at least it works for basic :app:assembleRelease. I guess gradle or android plugin behavior changed at some point that causes this task ordering issue to crop up. I don't know enough about gradle to track down the actual source but hopefully this gives more knowledgeable people a good clue to go on =)

work for me, thanks

@Exilz
Copy link

Exilz commented Oct 7, 2021

I was struggling with this after adding a new build type to gradle. Everything was built properly on the release type, regardless of the flavor.
I couldn't get my new "staging" build type to embed the javascript bundle inside its apk (although it did build it !).

I finally gave up and removed my Staging build type completely. Instead, I created two productFlavors. One for my release app and the other one for the "staging" one.

Both of them are using the default release build type. So my commands are as follow :

  • ./gradlew assembleClientRelease ("client" being my staging flavor)
  • ./gradlew assembleMarketRelease ("market" being my release flavor)

This way, it works without having to find work around or writing weird scripts that handle the bundling part.

Moreover, you're able to set up your signing configuration, different app_name and bundle id at the flavor level. So in my case, I'm not missing on features that the buildTypes would bring.

That said, it looks weird to me that it's still that hard to find a gradle setup that lets you build react native applications when adding a new build type.

@facebook facebook locked as resolved and limited conversation to collaborators Oct 26, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Attention Issues where the author has responded to feedback. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet