Skip to content

Commit 9bcaf83

Browse files
cortinicofacebook-github-bot
authored andcommitted
AGP to 8.0.2
Summary: 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 Differential Revision: D45178748 fbshipit-source-id: c3209f5d79bc5fa57d49e3ddc55047af644016e0
1 parent 71936fc commit 9bcaf83

File tree

9 files changed

+34
-14
lines changed

9 files changed

+34
-14
lines changed

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

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

Lines changed: 7 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")
@@ -59,7 +59,12 @@ java {
5959
targetCompatibility = JavaVersion.VERSION_11
6060
}
6161

62-
kotlin { jvmToolchain(11) }
62+
kotlin {
63+
// We intentionally don't build on JDK 17 as users will see a cryptic bytecode version
64+
// error first. Instead we produce a JDK 11 Gradle Plugin, so that AGP can print their
65+
// nice message showing
66+
jvmToolchain(11)
67+
}
6368

6469
tasks.withType<KotlinCompile> {
6570
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
@@ -567,6 +567,7 @@ android {
567567
buildFeatures {
568568
prefab true
569569
prefabPublishing !skipPrefabPublishing
570+
buildConfig true
570571
}
571572

572573
prefab {
@@ -721,6 +722,8 @@ react {
721722
}
722723

723724
kotlin {
725+
// We intentionally don't build on JDK 17 as our tests are broken due to Mockito/PowerMock
726+
// not running well on JDK 17.
724727
jvmToolchain(11)
725728
}
726729

packages/react-native/ReactAndroid/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ LIBEVENT_VERSION=2.1.12
3232

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

packages/react-native/ReactAndroid/hermes-engine/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ android {
202202
}
203203

204204
kotlin {
205+
// We intentionally don't build on JDK 17 to keep this version aligned with
206+
// the JVM toolchain of :ReactAndroid
205207
jvmToolchain(11)
206208
}
207209

packages/react-native/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// their settings.gradle.kts file.
1212
// More on this here: https://reactnative.dev/contributing/how-to-build-from-source
1313
plugins {
14-
id("com.android.library") version "7.4.2" apply false
15-
id("com.android.application") version "7.4.2" apply false
14+
id("com.android.library") version "8.0.2" apply false
15+
id("com.android.application") version "8.0.2" apply false
1616
id("de.undercouch.download") version "5.0.1" apply false
1717
kotlin("android") version "1.8.0" apply false
1818
}

0 commit comments

Comments
 (0)