From 200488e87cf4bc355e03c78cd814b97b23452117 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Mon, 21 Feb 2022 06:14:17 -0800 Subject: [PATCH] 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 --- ReactAndroid/build.gradle | 5 +++++ build.gradle.kts | 2 +- .../com/facebook/react/TaskConfiguration.kt | 2 ++ packages/rn-tester/android/app/build.gradle | 11 ++++++++++ react.gradle | 21 +++++++------------ template/android/build.gradle | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 6067a8802178c7..291c8fc6bb7478 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -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) diff --git a/build.gradle.kts b/build.gradle.kts index 5d38d5a7afda93..8f839467045ec4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt index 4165d85845887a..d5acc99a2cd60e 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt @@ -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) diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 07e581e9ba4cbf..f40f0a6b63f885 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -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) diff --git a/react.gradle b/react.gradle index 4c6a5151343a97..a309c70f4b2906 100644 --- a/react.gradle +++ b/react.gradle @@ -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") } } diff --git a/template/android/build.gradle b/template/android/build.gradle index 3300863fdcdb16..5e77be4eaf4c98 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -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