Skip to content

Commit e78a96c

Browse files
cortinicofacebook-github-bot
authored andcommitted
AGP to 8.0.2 (#37019)
Summary: Pull Request resolved: #37019 This bumps the version of AGP to the latest stable. There was a breaking change in how buildConfig are built which I had to handle. This also requires a bump of RNGP to work correctly. Moreover, we now required Java 17 to build Android apps (as that's a AGP requirement). Changelog: [Android] [Changed] - Java to 17 and AGP to 8.0.2 Reviewed By: cipolleschi Differential Revision: D45178748 fbshipit-source-id: f5e331a50983a84fc878f6c2bffcb90f0806c2d6
1 parent cba13bb commit e78a96c

File tree

12 files changed

+35
-17
lines changed

12 files changed

+35
-17
lines changed

.circleci/Dockerfiles/Dockerfile.android

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# and build a Android application that can be used to run the
1515
# tests specified in the scripts/ directory.
1616
#
17-
FROM reactnativecommunity/react-native-android:8.0
17+
FROM reactnativecommunity/react-native-android:9.0
1818

1919
LABEL Description="React Native Android Test Image"
2020
LABEL maintainer="Meta Open Source <[email protected]>"

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ executors:
113113
reactnativeandroid:
114114
<<: *defaults
115115
docker:
116-
- image: reactnativecommunity/react-native-android:8.0
116+
- image: reactnativecommunity/react-native-android:9.0
117117
resource_class: "xlarge"
118118
environment:
119119
- TERM: "dumb"

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
plugins {
99
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
10-
id("com.android.library") version "7.4.2" apply false
11-
id("com.android.application") version "7.4.2" apply false
10+
id("com.android.library") version "8.0.2" apply false
11+
id("com.android.application") version "8.0.2" apply false
1212
id("de.undercouch.download") version "5.0.1" apply false
1313
kotlin("android") version "1.8.0" apply false
1414
}
@@ -30,7 +30,7 @@ version =
3030
group = "com.facebook.react"
3131

3232
val ndkPath by extra(System.getenv("ANDROID_NDK"))
33-
val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION"))
33+
val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION") ?: "23.1.7779620")
3434
val sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString()
3535
val sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString()
3636

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"prettier": "prettier --write \"./**/*.{js,md,yml,ts,tsx}\"",
2828
"format-check": "prettier --list-different \"./**/*.{js,md,yml,ts,tsx}\"",
2929
"update-lock": "npx yarn-deduplicate",
30-
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:8.0",
30+
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:9.0",
3131
"docker-build-android": "docker build -t reactnativeci/android -f .circleci/Dockerfiles/Dockerfile.android .",
3232
"test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh",
3333
"test-android-run-unit": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh",

packages/react-native-gradle-plugin/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
// The KGP/AGP version is defined by React Native Gradle plugin.
3838
// Therefore we specify an implementation dep rather than a compileOnly.
3939
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
40-
implementation("com.android.tools.build:gradle:7.4.2")
40+
implementation("com.android.tools.build:gradle:8.0.2")
4141

4242
implementation("com.google.code.gson:gson:2.8.9")
4343
implementation("com.google.guava:guava:31.0.1-jre")
@@ -55,11 +55,14 @@ dependencies {
5555
}
5656

5757
java {
58+
// We intentionally don't build for Java 17 as users will see a cryptic bytecode version
59+
// error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
60+
// nice message showing that JDK 11 (or 17) is required first
5861
sourceCompatibility = JavaVersion.VERSION_11
5962
targetCompatibility = JavaVersion.VERSION_11
6063
}
6164

62-
kotlin { jvmToolchain(11) }
65+
kotlin { jvmToolchain(17) }
6366

6467
tasks.withType<KotlinCompile> {
6568
kotlinOptions {

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ class ReactPlugin : Plugin<Project> {
8686

8787
private fun checkJvmVersion(project: Project) {
8888
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
89-
if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) {
89+
if ((jvmVersion?.toIntOrNull() ?: 0) <= 16) {
9090
project.logger.error(
9191
"""
9292
9393
********************************************************************************
9494
95-
ERROR: requires JDK11 or higher.
95+
ERROR: requires JDK17 or higher.
9696
Incompatible major version detected: '$jvmVersion'
9797
9898
********************************************************************************

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal object AgpConfiguratorUtils {
2121
val action =
2222
Action<AppliedPlugin> {
2323
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
24+
ext.buildFeatures.buildConfig = true
2425
ext.defaultConfig.buildConfigField(
2526
"boolean", "IS_NEW_ARCHITECTURE_ENABLED", project.isNewArchEnabled.toString())
2627
ext.defaultConfig.buildConfigField(

packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,33 @@ internal object JdkConfiguratorUtils {
1919
/**
2020
* Function that takes care of configuring the JDK toolchain for all the projects projects. As we
2121
* do decide the JDK version based on the AGP version that RNGP brings over, here we can safely
22-
* configure the toolchain to 11.
22+
* configure the toolchain to 17.
2323
*/
2424
fun configureJavaToolChains(input: Project) {
25+
// Check at the app level if react.internal.disableJavaVersionAlignment is set.
2526
if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
2627
return
2728
}
2829
input.rootProject.allprojects { project ->
30+
// Allows every single module to set react.internal.disableJavaVersionAlignment also.
31+
if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
32+
return@allprojects
33+
}
2934
val action =
3035
Action<AppliedPlugin> {
3136
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext
3237
->
33-
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_11
34-
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_11
38+
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
39+
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
3540
}
3641
}
3742
project.pluginManager.withPlugin("com.android.application", action)
3843
project.pluginManager.withPlugin("com.android.library", action)
3944
project.pluginManager.withPlugin("org.jetbrains.kotlin.android") {
40-
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(11)
45+
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
4146
}
4247
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
43-
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(11)
48+
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
4449
}
4550
}
4651
}

packages/react-native/ReactAndroid/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ android {
594594
buildFeatures {
595595
prefab true
596596
prefabPublishing !skipPrefabPublishing
597+
buildConfig true
597598
}
598599

599600
prefab {
@@ -751,6 +752,8 @@ react {
751752
}
752753

753754
kotlin {
755+
// We intentionally don't build on JDK 17 as our tests are broken due to Mockito/PowerMock
756+
// not running well on JDK 17.
754757
jvmToolchain(11)
755758
}
756759

packages/react-native/ReactAndroid/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ GTEST_VERSION=1.12.1
3333

3434
android.useAndroidX=true
3535
android.enableJetifier=true
36+
37+
# We want to have more fine grained control on the Java version for
38+
# ReactAndroid, therefore we disable RGNP Java version alignment mechanism
39+
react.internal.disableJavaVersionAlignment=true

0 commit comments

Comments
 (0)