Skip to content

Commit

Permalink
build: Bump AGP to 7.1.1 and fix bundle inclusion in release mode (fa…
Browse files Browse the repository at this point in the history
…cebook#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 facebook#33002
Closes facebook#33018
Closes facebook#33046
Potentially fixes facebook#33029

## Changelog

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

Pull Request resolved: facebook#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

0 comments on commit 200488e

Please sign in to comment.