-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix applyAppPlugin being accessed too early in the React App Gradle P…
…lugin (#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
- Loading branch information
1 parent
dfe42d6
commit 79e72e0
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactPluginTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react | ||
|
||
import com.android.build.gradle.AppExtension | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class ReactPluginTest { | ||
|
||
@Test | ||
fun reactPlugin_withApplyAppPluginSetToTrue_addsARelevantTask() { | ||
val project = ProjectBuilder.builder().build() | ||
project.plugins.apply("com.android.application") | ||
project.plugins.apply("com.facebook.react") | ||
|
||
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } | ||
project.extensions.getByType(ReactExtension::class.java).apply { | ||
applyAppPlugin.set(true) | ||
cliPath.set(".") | ||
} | ||
|
||
// We check if the App Plugin si applied by finding one of the added task. | ||
assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isNotEmpty()) | ||
} | ||
|
||
@Test | ||
fun reactPlugin_withApplyAppPluginSetToFalse_doesNotApplyTheAppPlugin() { | ||
val project = ProjectBuilder.builder().build() | ||
project.plugins.apply("com.android.application") | ||
project.plugins.apply("com.facebook.react") | ||
|
||
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } | ||
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) } | ||
|
||
assertTrue(project.getTasksByName("bundleDebugJsAndAssets", false).isEmpty()) | ||
} | ||
|
||
@Test | ||
fun reactPlugin_withApplyAppPluginSetToFalse_codegenPluginIsApplied() { | ||
val project = ProjectBuilder.builder().build() | ||
project.plugins.apply("com.android.application") | ||
project.plugins.apply("com.facebook.react") | ||
|
||
project.extensions.getByType(AppExtension::class.java).apply { compileSdkVersion(30) } | ||
project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) } | ||
|
||
assertTrue(project.getTasksByName("buildCodegenCLI", false).isNotEmpty()) | ||
} | ||
} |