Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ org.gradle.caching=true

android.useAndroidX=true

# Those 2 properties are needed to make our project compatible with
# AGP 9.0.0 for the time being. Ideally we should not opt-out of
# builtInKotlin and newDsl once AGP 9.0.0 hits stable.
# More on this: https://developer.android.com/build/releases/agp-preview#android-gradle-plugin-built-in-kotlin
android.builtInKotlin=false
android.newDsl=false
Comment on lines -7 to -12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we good removing those?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. After removing those and bumping to AGP v9.2.1 - there were build issues that have already been fixed as part of this PR, so we should be good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet


# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
Expand Down
2 changes: 1 addition & 1 deletion packages/gradle-plugin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.12.0"
agp = "9.2.1"
gson = "2.8.9"
guava = "31.0.1-jre"
javapoet = "1.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class ReactPlugin : Plugin<Project> {
}

// Library Only Configuration
configureBuildConfigFieldsForLibraries(project)
configureNamespaceForLibraries(project)
project.pluginManager.withPlugin("com.android.library") {
configureBuildConfigFieldsForLibraries(project)
configureNamespaceForLibraries(project)
configureCodegen(project, extension, rootExtension, isLibrary = true)
}
}
Expand Down Expand Up @@ -222,12 +222,12 @@ class ReactPlugin : Plugin<Project> {
if (isLibrary) {
project.extensions.getByType(LibraryAndroidComponentsExtension::class.java).finalizeDsl { ext
->
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.path)
}
} else {
project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java).finalizeDsl {
ext ->
ext.sourceSets.getByName("main").java.srcDir(generatedSrcDir.get().dir("java").asFile)
ext.sourceSets.getByName("main").java.directories.add(generatedSrcDir.get().dir("java").asFile.path)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package com.facebook.react.utils

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.LibraryExtension
import com.facebook.react.ReactExtension
import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
Expand All @@ -18,7 +17,6 @@ import java.net.Inet4Address
import java.net.NetworkInterface
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.plus
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.plugins.AppliedPlugin
Expand Down Expand Up @@ -77,14 +75,12 @@ internal object AgpConfiguratorUtils {
project.pluginManager.withPlugin("com.android.library", action)
}

fun configureBuildConfigFieldsForLibraries(appProject: Project) {
appProject.rootProject.allprojects { subproject ->
subproject.pluginManager.withPlugin("com.android.library") {
subproject.extensions
.getByType(LibraryAndroidComponentsExtension::class.java)
.finalizeDsl { ext -> ext.buildFeatures.buildConfig = true }
fun configureBuildConfigFieldsForLibraries(project: Project) {
project.extensions
.getByType(LibraryAndroidComponentsExtension::class.java)
.finalizeDsl { ext ->
ext.buildFeatures.buildConfig = true
}
}
}

fun configureDevServerLocation(project: Project) {
Expand All @@ -111,27 +107,22 @@ internal object AgpConfiguratorUtils {
project.pluginManager.withPlugin("com.android.library", action)
}

fun configureNamespaceForLibraries(appProject: Project) {
appProject.rootProject.allprojects { subproject ->
subproject.pluginManager.withPlugin("com.android.library") {
subproject.extensions
.getByType(LibraryAndroidComponentsExtension::class.java)
.finalizeDsl { ext ->
if (ext.namespace == null) {
val android = subproject.extensions.getByType(LibraryExtension::class.java)
val manifestFile = android.sourceSets.getByName("main").manifest.srcFile

manifestFile
.takeIf { it.exists() }
?.let { file ->
getPackageNameFromManifest(file)?.let { packageName ->
ext.namespace = packageName
}
}
fun configureNamespaceForLibraries(project: Project) {
project.extensions
.getByType(LibraryAndroidComponentsExtension::class.java)
.finalizeDsl { ext ->
if (ext.namespace == null) {
val manifestFile =
project.layout.projectDirectory.file("src/main/AndroidManifest.xml").asFile
manifestFile
.takeIf { it.exists() }
?.let { file ->
getPackageNameFromManifest(file)?.let { packageName ->
ext.namespace = packageName
}
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
plugins {
id("com.facebook.react")
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
Expand Down
29 changes: 15 additions & 14 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ plugins {
id("com.facebook.react")
alias(libs.plugins.android.library)
alias(libs.plugins.download)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ktfmt)
}

Expand Down Expand Up @@ -611,19 +610,19 @@ android {
":packages:react-native:ReactAndroid:hermes-engine:preBuild"
)

sourceSets.getByName("main") {
res.setSrcDirs(
listOf(
"src/main/res/devsupport",
"src/main/res/shell",
"src/main/res/views/alert",
"src/main/res/views/modal",
"src/main/res/views/uimanager",
"src/main/res/views/view",
)
)
java.exclude("com/facebook/react/processing")
java.exclude("com/facebook/react/module/processing")
sourceSets {
named("main") {
res.directories.addAll(
listOf(
"src/main/res/devsupport",
"src/main/res/shell",
"src/main/res/views/alert",
"src/main/res/views/modal",
"src/main/res/views/uimanager",
"src/main/res/views/view",
)
)
}
}

lint {
Expand Down Expand Up @@ -714,6 +713,8 @@ dependencies {
// Therefore hermes-engine is a compileOnly dependencies.
compileOnly(project(":packages:react-native:ReactAndroid:hermes-engine"))

implementation(libs.androidx.collection)

testImplementation(libs.junit)
testImplementation(libs.assertj)
testImplementation(libs.mockito)
Expand Down
13 changes: 10 additions & 3 deletions packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,16 @@ android {
}
}

sourceSets.getByName("main") {
manifest.srcFile("$hermesDir/android/hermes/src/main/AndroidManifest.xml")
java.srcDirs("$hermesDir/lib/Platform/Intl/java", "$hermesDir/lib/Platform/Unicode/java")
sourceSets {
named("main") {
manifest.srcFile("$hermesDir/android/hermes/src/main/AndroidManifest.xml")
java.directories.addAll(
listOf(
"$hermesDir/lib/Platform/Intl/java",
"$hermesDir/lib/Platform/Unicode/java",
)
)
}
}

buildFeatures {
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ compileSdk = "36"
buildTools = "36.0.0"
ndkVersion = "27.1.12297006"
# Dependencies versions
agp = "8.12.0"
agp = "9.2.1"
androidx-annotation = "1.6.0"
androidx-appcompat = "1.7.0"
androidx-autofill = "1.3.0"
androidx-collection = "1.4.0"
androidx-benchmark-macro-junit4 = "1.3.3"
androidx-profileinstaller = "1.4.1"
androidx-swiperefreshlayout = "1.1.0"
Expand Down Expand Up @@ -56,6 +57,7 @@ androidx-annotation = { module = "androidx.annotation:annotation", version.ref =
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-appcompat-resources = { module = "androidx.appcompat:appcompat-resources", version.ref = "androidx-appcompat" }
androidx-autofill = { module = "androidx.autofill:autofill", version.ref = "androidx-autofill" }
androidx-collection = { module = "androidx.collection:collection", version.ref = "androidx-collection" }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for ReactAndroid to compile successfully. If not provided, we face the following error:

Image

androidx-benchmark-macro-junit4 = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidx-benchmark-macro-junit4" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" }
Expand Down
1 change: 0 additions & 1 deletion packages/rn-tester/android/app/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
}

android {
Expand Down
20 changes: 11 additions & 9 deletions packages/rn-tester/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.facebook.react")
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

val reactNativeDirPath = "$rootDir/packages/react-native"
Expand Down Expand Up @@ -135,15 +134,18 @@ android {
}
sourceSets.named("main") {
// SampleTurboModule.
java.srcDirs(
"$reactNativeDirPath/ReactCommon/react/nativemodule/samples/platform/android",
)
res.setSrcDirs(
listOf(
"src/main/res",
"src/main/public_res",
)
kotlin.directories.add(
"$reactNativeDirPath/ReactCommon/react/nativemodule/samples/platform/android"
)
res.directories.apply {
clear() // Mimics setSrcDirs by wiping out the defaults
addAll(
listOf(
"src/main/res",
"src/main/public_res"
)
)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions private/helloworld/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ reactNativeArchitectures=arm64-v8a
newArchEnabled=true
hermesEnabled=true
edgeToEdgeEnabled=false

# Opt out of built-in kotlin and new DSL behavior that ships with AGP 9.
# Starting from AGP 10.x these opt outs will be removed.
android.builtInKotlin=false
android.newDsl=false
Comment on lines +17 to +18
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabling the opt-outs for hello-world to match the behavior of template

Loading