Skip to content

Commit 79e72e0

Browse files
cortinicofacebook-github-bot
authored andcommitted
Fix applyAppPlugin being accessed too early in the React App Gradle Plugin (#32420)
Summary: Pull Request resolved: #32420 While working on the NDK AGP Apis, I realized the the `applyAppPlugin` is accessed too early inside the Gradle plugin. Specifically is accessed once the plugin is applied, and the extension is not configured afterwards. This means that the extension is always set the default values. I'm fixing it moving it inside the `project.afterEvaluate` that was already need to access the variant informations. Changelog: [Internal] [Changed] - Fix applyAppPlugin being accessed too early in the React App Gradle Plugin Reviewed By: ShikaSD Differential Revision: D31652984 fbshipit-source-id: e7ead3f8acb24372bf953fd90ad2a5dfbbeeeec0
1 parent dfe42d6 commit 79e72e0

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

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
@@ -27,8 +27,8 @@ class ReactPlugin : Plugin<Project> {
2727
}
2828

2929
private fun applyAppPlugin(project: Project, config: ReactExtension) {
30-
if (config.applyAppPlugin.getOrElse(false)) {
31-
project.afterEvaluate {
30+
project.afterEvaluate {
31+
if (config.applyAppPlugin.getOrElse(false)) {
3232
val androidConfiguration = project.extensions.getByType(BaseExtension::class.java)
3333
project.configureDevPorts(androidConfiguration)
3434

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react
9+
10+
import com.android.build.gradle.AppExtension
11+
import org.gradle.testfixtures.ProjectBuilder
12+
import org.junit.Assert.assertTrue
13+
import org.junit.Test
14+
15+
class ReactPluginTest {
16+
17+
@Test
18+
fun reactPlugin_withApplyAppPluginSetToTrue_addsARelevantTask() {
19+
val project = ProjectBuilder.builder().build()
20+
project.plugins.apply("com.android.application")
21+
project.plugins.apply("com.facebook.react")
22+
23+
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
24+
project.extensions.getByType(ReactExtension::class.java).apply {
25+
applyAppPlugin.set(true)
26+
cliPath.set(".")
27+
}
28+
29+
// We check if the App Plugin si applied by finding one of the added task.
30+
assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isNotEmpty())
31+
}
32+
33+
@Test
34+
fun reactPlugin_withApplyAppPluginSetToFalse_doesNotApplyTheAppPlugin() {
35+
val project = ProjectBuilder.builder().build()
36+
project.plugins.apply("com.android.application")
37+
project.plugins.apply("com.facebook.react")
38+
39+
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
40+
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) }
41+
42+
assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isEmpty())
43+
}
44+
45+
@Test
46+
fun reactPlugin_withApplyAppPluginSetToFalse_codegenPluginIsApplied() {
47+
val project = ProjectBuilder.builder().build()
48+
project.plugins.apply("com.android.application")
49+
project.plugins.apply("com.facebook.react")
50+
51+
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) }
52+
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) }
53+
54+
assertTrue(project.getTasksByName("buildCodegenCLI", false).isNotEmpty())
55+
}
56+
}

0 commit comments

Comments
 (0)