AGP to 8.0.2 (#37019)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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: 0f302e1f2f2ee56bd3566202fbb5ef67c9b220db
This commit is contained in:
Nicola Corti 2023-06-20 08:00:05 -07:00 committed by Facebook GitHub Bot
parent cba13bb7bf
commit 9f7dddf1ac
12 changed files with 35 additions and 17 deletions

View File

@ -14,7 +14,7 @@
# and build a Android application that can be used to run the
# tests specified in the scripts/ directory.
#
FROM reactnativecommunity/react-native-android:8.0
FROM reactnativecommunity/react-native-android:9.0
LABEL Description="React Native Android Test Image"
LABEL maintainer="Meta Open Source <opensource@meta.com>"

View File

@ -113,7 +113,7 @@ executors:
reactnativeandroid:
<<: *defaults
docker:
- image: reactnativecommunity/react-native-android:8.0
- image: reactnativecommunity/react-native-android:9.0
resource_class: "xlarge"
environment:
- TERM: "dumb"

View File

@ -7,8 +7,8 @@
plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("com.android.library") version "7.4.2" apply false
id("com.android.application") version "7.4.2" apply false
id("com.android.library") version "8.0.2" apply false
id("com.android.application") version "8.0.2" apply false
id("de.undercouch.download") version "5.0.1" apply false
kotlin("android") version "1.8.0" apply false
}
@ -30,7 +30,7 @@ version =
group = "com.facebook.react"
val ndkPath by extra(System.getenv("ANDROID_NDK"))
val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION"))
val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION") ?: "23.1.7779620")
val sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString()
val sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString()

View File

@ -27,7 +27,7 @@
"prettier": "prettier --write \"./**/*.{js,md,yml,ts,tsx}\"",
"format-check": "prettier --list-different \"./**/*.{js,md,yml,ts,tsx}\"",
"update-lock": "npx yarn-deduplicate",
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:8.0",
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:9.0",
"docker-build-android": "docker build -t reactnativeci/android -f .circleci/Dockerfiles/Dockerfile.android .",
"test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh",
"test-android-run-unit": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh",

View File

@ -37,7 +37,7 @@ dependencies {
// The KGP/AGP version is defined by React Native Gradle plugin.
// Therefore we specify an implementation dep rather than a compileOnly.
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
implementation("com.android.tools.build:gradle:7.4.2")
implementation("com.android.tools.build:gradle:8.0.2")
implementation("com.google.code.gson:gson:2.8.9")
implementation("com.google.guava:guava:31.0.1-jre")
@ -55,11 +55,14 @@ dependencies {
}
java {
// We intentionally don't build for Java 17 as users will see a cryptic bytecode version
// error first. Instead we produce a Java 11-compatible Gradle Plugin, so that AGP can print their
// nice message showing that JDK 11 (or 17) is required first
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlin { jvmToolchain(11) }
kotlin { jvmToolchain(17) }
tasks.withType<KotlinCompile> {
kotlinOptions {

View File

@ -86,13 +86,13 @@ class ReactPlugin : Plugin<Project> {
private fun checkJvmVersion(project: Project) {
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) {
if ((jvmVersion?.toIntOrNull() ?: 0) <= 16) {
project.logger.error(
"""
********************************************************************************
ERROR: requires JDK11 or higher.
ERROR: requires JDK17 or higher.
Incompatible major version detected: '$jvmVersion'
********************************************************************************

View File

@ -21,6 +21,7 @@ internal object AgpConfiguratorUtils {
val action =
Action<AppliedPlugin> {
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
ext.buildFeatures.buildConfig = true
ext.defaultConfig.buildConfigField(
"boolean", "IS_NEW_ARCHITECTURE_ENABLED", project.isNewArchEnabled.toString())
ext.defaultConfig.buildConfigField(

View File

@ -19,28 +19,33 @@ internal object JdkConfiguratorUtils {
/**
* Function that takes care of configuring the JDK toolchain for all the projects projects. As we
* do decide the JDK version based on the AGP version that RNGP brings over, here we can safely
* configure the toolchain to 11.
* configure the toolchain to 17.
*/
fun configureJavaToolChains(input: Project) {
// Check at the app level if react.internal.disableJavaVersionAlignment is set.
if (input.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
return
}
input.rootProject.allprojects { project ->
// Allows every single module to set react.internal.disableJavaVersionAlignment also.
if (project.hasProperty(INTERNAL_DISABLE_JAVA_VERSION_ALIGNMENT)) {
return@allprojects
}
val action =
Action<AppliedPlugin> {
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext
->
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_11
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_11
ext.compileOptions.sourceCompatibility = JavaVersion.VERSION_17
ext.compileOptions.targetCompatibility = JavaVersion.VERSION_17
}
}
project.pluginManager.withPlugin("com.android.application", action)
project.pluginManager.withPlugin("com.android.library", action)
project.pluginManager.withPlugin("org.jetbrains.kotlin.android") {
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(11)
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
}
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(11)
project.extensions.getByType(KotlinTopLevelExtension::class.java).jvmToolchain(17)
}
}
}

View File

@ -594,6 +594,7 @@ android {
buildFeatures {
prefab true
prefabPublishing !skipPrefabPublishing
buildConfig true
}
prefab {
@ -751,6 +752,8 @@ react {
}
kotlin {
// We intentionally don't build on JDK 17 as our tests are broken due to Mockito/PowerMock
// not running well on JDK 17.
jvmToolchain(11)
}

View File

@ -33,3 +33,7 @@ GTEST_VERSION=1.12.1
android.useAndroidX=true
android.enableJetifier=true
# We want to have more fine grained control on the Java version for
# ReactAndroid, therefore we disable RGNP Java version alignment mechanism
react.internal.disableJavaVersionAlignment=true

View File

@ -202,6 +202,8 @@ android {
}
kotlin {
// We intentionally don't build on JDK 17 to keep this version aligned with
// the JVM toolchain of :ReactAndroid
jvmToolchain(11)
}

View File

@ -11,8 +11,8 @@
// their settings.gradle.kts file.
// More on this here: https://reactnative.dev/contributing/how-to-build-from-source
plugins {
id("com.android.library") version "7.4.2" apply false
id("com.android.application") version "7.4.2" apply false
id("com.android.library") version "8.0.2" apply false
id("com.android.application") version "8.0.2" apply false
id("de.undercouch.download") version "5.0.1" apply false
kotlin("android") version "1.8.0" apply false
}