Skip to content

Commit

Permalink
build: Bump AGP to 7.1.1 and fix bundle inclusion in release mode (#3…
Browse files Browse the repository at this point in the history
…3057)

Summary:
Upgrade Android Gradle to 7.1.0 on template and fix a bug where the bundle was not getting included when building the app in release mode

Closes #33002
Closes #33018
Closes #33046
Potentially fixes #33029

## Changelog

[Android] [Changed] - Bump AGP to 7.1.0 and fix bundle inclusion in release mode

Pull Request resolved: #33057

Test Plan:
1. Run `./scripts/test-manual-e2e.sh`
2. Select `A new RN app using the template` and `Android`
3. Test app on the emulator
4. Open Android studio build the app using release variant
4. Check the release apk using Android studio "Analyze APK" tool and ensure the bundle is included

![image](https://user-images.githubusercontent.com/11707729/152700410-3bcb80b0-35b6-4bdc-bf57-98a42a29e5a6.png)

Reviewed By: ShikaSD

Differential Revision: D34076884

Pulled By: cortinico

fbshipit-source-id: da4392af37e08e22dbcafba38476fd712141474a
  • Loading branch information
gabrieldonadel authored and facebook-github-bot committed Feb 21, 2022
1 parent 235f168 commit 200488e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ task androidSourcesJar(type: Jar) {
}

android {
buildToolsVersion = "31.0.0"
compileSdkVersion 31

// Used to override the NDK path & version on internal CI
Expand Down Expand Up @@ -418,6 +419,10 @@ afterEvaluate {

// Needed as some of the native sources needs to be downloaded
// before configureNdkBuildDebug could be executed.
reactNativeArchitectures().each { architecture ->
tasks.named("configureNdkBuildDebug[${architecture}]") { dependsOn(preBuild) }
tasks.named("configureNdkBuildRelease[${architecture}]") { dependsOn(preBuild) }
}
configureNdkBuildDebug.dependsOn(preBuild)
configureNdkBuildRelease.dependsOn(preBuild)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}
dependencies {
val kotlin_version: String by project
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.android.tools.build:gradle:7.1.1")
classpath("de.undercouch:gradle-download-task:5.0.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
// NOTE: Do not place your application dependencies here; they belong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactExte
it.into(jsBundleDirConfigValue.get())
} else {
it.into(mergeAssetsTask.map { mergeFoldersTask -> mergeFoldersTask.outputDir.get() })
// Workaround for Android Gradle Plugin 7.1 asset directory
it.into("$buildDir/intermediates/assets/${variant.name}/merge${targetName}Assets")
}

it.dependsOn(mergeAssetsTask)
Expand Down
11 changes: 11 additions & 0 deletions packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def reactNativeArchitectures() {
}

android {
buildToolsVersion = "31.0.0"
compileSdkVersion 31

// Used to override the NDK path & version on internal CI
Expand Down Expand Up @@ -298,6 +299,16 @@ if (enableCodegen) {
}

afterEvaluate {
reactNativeArchitectures().each { architecture ->
tasks.named("configureNdkBuildDebug[${architecture}]") {
dependsOn("preHermesDebugBuild")
dependsOn("preJscDebugBuild")
}
tasks.named("configureNdkBuildRelease[${architecture}]") {
dependsOn("preHermesReleaseBuild")
dependsOn("preJscReleaseBuild")
}
}
configureNdkBuildRelease.dependsOn(packageReactReleaseNdkLibs)
preHermesReleaseBuild.dependsOn(packageReactReleaseNdkLibs)
preJscReleaseBuild.dependsOn(packageReactReleaseNdkLibs)
Expand Down
21 changes: 8 additions & 13 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,24 @@ afterEvaluate {
group = "react"
description = "copy bundled JS into ${targetName}."

from(jsBundleDir)
if (config."jsBundleDir${targetName}") {
from(jsBundleDir)
into(file(config."jsBundleDir${targetName}"))
} else {
into ("$buildDir/intermediates")
if (isAndroidLibrary) {
into ("library_assets/${variant.name}/out") {
from(jsBundleDir)
}
into ("library_assets/${variant.name}/out")
} else {
into ("assets/${targetPath}") {
from(jsBundleDir)
}
into ("assets/${targetPath}")

// Workaround for Android Gradle Plugin 3.2+ new asset directory
into ("merged_assets/${variant.name}/merge${targetName}Assets/out") {
from(jsBundleDir)
}
into ("merged_assets/${variant.name}/merge${targetName}Assets/out")

// Workaround for Android Gradle Plugin 3.4+ new asset directory
into ("merged_assets/${variant.name}/out") {
from(jsBundleDir)
}
into ("merged_assets/${variant.name}/out")

// Workaround for Android Gradle Plugin 7.1 asset directory
into("$buildDir/intermediates/assets/${variant.name}/merge${targetName}Assets")
}
}

Expand Down
2 changes: 1 addition & 1 deletion template/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
classpath("com.android.tools.build:gradle:7.1.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
// NOTE: Do not place your application dependencies here; they belong
Expand Down

8 comments on commit 200488e

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this fix is not included in the latest release of RN 0.68 and the react.gradle file is different. I had to take it from the master repo in order to fix the problem. Could you please publish this fix in the released react-native version on NPM?

Thank you!

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this fix is not included in the latest release of RN 0.68 and the react.gradle file is different. I had to take it from the master repo in order to fix the problem. Could you please publish this fix in the released react-native version on NPM?

Thank you!

@cortinico
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @marf
This fix will land in 0.69 together with the bump for AGP 7.1
If you're on RN 0.68, you should stick to AGP 7.0.x

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cortinico thank you for the info.
I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work. It took me several hours to figure out why it was not working having followed the upgrading suggestions line by line.

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cortinico thank you for the info.
I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work. It took me several hours to figure out why it was not working having followed the upgrading suggestions line by line.

@cortinico
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work

Can you please link to where this is being suggested?

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work

Can you please link to where this is being suggested?

I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work

Can you please link to where this is being suggested?

Sorry my mistake, I must have not read it correctly! Now I have seen 7.0.X both in the migration guide and also in the upgrade helper tool!

Thank you again for the support!

@marf
Copy link

@marf marf commented on 200488e Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work

Can you please link to where this is being suggested?

I suggest the team update the upgrade helper guide because it suggests updating to 7.1 in the upgrading guide even though it does not work

Can you please link to where this is being suggested?

Sorry, my mistake! I must have not read it correctly! Now I have seen 7.0.X both in the migration guide and also in the upgrade helper tool!

Thank you again for the support!

Please sign in to comment.