build: Bump AGP to 7.1.1 and fix bundle inclusion in release mode (#33057)

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 https://github.com/facebook/react-native/issues/33002
Closes https://github.com/facebook/react-native/issues/33018
Closes https://github.com/facebook/react-native/issues/33046
Potentially fixes https://github.com/facebook/react-native/issues/33029

## Changelog

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

Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Gabriel Donadel Dall'Agnol
2022-02-21 06:23:31 -08:00
committed by Facebook GitHub Bot
parent 235f168574
commit 200488e87c
6 changed files with 28 additions and 15 deletions
+5
View File
@@ -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
@@ -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)
+1 -1
View File
@@ -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
@@ -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)
@@ -143,6 +143,7 @@ def reactNativeArchitectures() {
}
android {
buildToolsVersion = "31.0.0"
compileSdkVersion 31
// Used to override the NDK path & version on internal CI
@@ -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)
+8 -13
View File
@@ -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")
}
}
+1 -1
View File
@@ -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