From 8e8e18be5e83a057ccb0efa678960d139573c0ec Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 20 Oct 2022 12:46:27 -0700 Subject: [PATCH] RNGP - Remove unused applyAppPlugin Summary: This is part of a series of tasks to make the React Native Gradle Plugin (RNGP) variant-aware. Here I'm removing the `applyAppPlugin` property which was never used. The new logic will apply the App Plugin if the `com.android.application` plugin is found. I've also removed the corresponding tests. New one will follow afterwards Changelog: [Internal] [Changed] - RNGP - Remove unused applyAppPlugin Reviewed By: cipolleschi Differential Revision: D40547689 fbshipit-source-id: ce1089498a586a43cb5e07950767c2c4b51b4597 --- .../com/facebook/react/ReactExtension.kt | 6 -- .../kotlin/com/facebook/react/ReactPlugin.kt | 18 +++--- .../com/facebook/react/ReactPluginTest.kt | 56 ------------------- packages/rn-tester/android/app/build.gradle | 1 - 4 files changed, 9 insertions(+), 72 deletions(-) delete mode 100644 packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactPluginTest.kt diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt index 44f0e6b9933..848434a1b58 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt @@ -22,12 +22,6 @@ abstract class ReactExtension @Inject constructor(project: Project) { private val objects = project.objects - /** - * Whether the React App plugin should apply its logic or not. Set it to false if you're still - * relying on `react.gradle` to configure your build. Default: false - */ - val applyAppPlugin: Property = objects.property(Boolean::class.java).convention(false) - /** * The path to the root of your project. This is the path to where the `package.json` lives. All * the CLI commands will be invoked from this folder as working directory. diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 81a708ff045..f51a3dd8fa3 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -40,14 +40,14 @@ class ReactPlugin : Plugin { if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) { project.logger.error( """ - + ******************************************************************************** - + ERROR: requires JDK11 or higher. Incompatible major version detected: '$jvmVersion' - + ******************************************************************************** - + """ .trimIndent()) exitProcess(1) @@ -55,11 +55,11 @@ class ReactPlugin : Plugin { } private fun applyAppPlugin(project: Project, config: ReactExtension) { - configureReactNativeNdk(project, config) - configureBuildConfigFields(project) - configureDevPorts(project) - project.afterEvaluate { - if (config.applyAppPlugin.getOrElse(false)) { + project.pluginManager.withPlugin("com.android.application") { + configureReactNativeNdk(project, config) + configureBuildConfigFields(project) + configureDevPorts(project) + project.afterEvaluate { val isAndroidLibrary = project.plugins.hasPlugin("com.android.library") val variants = if (isAndroidLibrary) { diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactPluginTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactPluginTest.kt deleted file mode 100644 index 39caba83bfa..00000000000 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/ReactPluginTest.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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(31) } - 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(31) } - 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(31) } - project.extensions.getByType(ReactExtension::class.java).apply { applyAppPlugin.set(false) } - - assertTrue(project.getTasksByName("buildCodegenCLI", false).isNotEmpty()) - } -} diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 2fe27d3fa0c..e80589e004d 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -76,7 +76,6 @@ plugins { */ react { - applyAppPlugin = true cliPath = "../../../../cli.js" bundleAssetName = "RNTesterApp.android.bundle" entryFile = file("../../js/RNTesterApp.android.js")