Fix devDisabledInStaging not working with multiple productFlavors (#30606)
Summary: Fixes https://github.com/facebook/react-native/issues/27052 Since react-native 0.62, the `devDisabledIn${buildType}` syntax has stopped working for apps with multiple `productFlavors`. This PR adds the `disableDevForVariant` lambda to allow dev mode to be disabled for different variants. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Fix devDisabledIn not working with multiple productFlavors Pull Request resolved: https://github.com/facebook/react-native/pull/30606 Test Plan: I added the following log into `react.gradle` and ran the Android build for my app: ``` println("devEnabled: ${targetName}, ${devEnabled}") ``` ``` # build.gradle project.ext.react = [ entryFile: "index.android.js", enableHermes: true, // clean and rebuild if changing bundleInLive: true, disableDevForVariant: { def variant -> variant.name.toLowerCase().contains('release') || variant.name.toLowerCase().contains('live') }, ] ... flavorDimensions 'branding' productFlavors { cve { dimension 'branding' } whce { dimension 'branding' } } ``` Console output: ``` Reading env from: env/cve/live devEnabled: CveDebug, true devEnabled: CveRelease, false devEnabled: CveLive, false devEnabled: WhceDebug, true devEnabled: WhceRelease, false devEnabled: WhceLive, false ``` Reviewed By: cortinico Differential Revision: D31649977 Pulled By: ShikaSD fbshipit-source-id: 520734314f4bca7608b8dca67c7c5ce0be6d31a5
This commit is contained in:
Родитель
64711b0d98
Коммит
055ea9c7b7
|
@ -114,6 +114,14 @@ abstract class ReactExtension @Inject constructor(project: Project) {
|
|||
val devDisabledInVariants: ListProperty<String> =
|
||||
objects.listProperty(String::class.java).convention(emptyList())
|
||||
|
||||
/**
|
||||
* Functional interface to disable dev mode only on specific [BaseVariant] Default: will check
|
||||
* [devDisabledInVariants] or return True for Release variants and False for Debug variants.
|
||||
*/
|
||||
var disableDevForVariant: (BaseVariant) -> Boolean = { variant ->
|
||||
variant.name in devDisabledInVariants.get() || variant.isRelease
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant Name to Boolean map that allows to toggle the bundle command for a specific variant.
|
||||
* Default: {}
|
||||
|
|
|
@ -64,7 +64,7 @@ internal fun Project.configureReactTasks(variant: BaseVariant, config: ReactExte
|
|||
}
|
||||
it.execCommand = execCommand
|
||||
it.bundleCommand = config.bundleCommand.get()
|
||||
it.devEnabled = !(variant.name in config.devDisabledInVariants.get() || isRelease)
|
||||
it.devEnabled = !config.disableDevForVariant(variant)
|
||||
it.entryFile = detectedEntryFile(config)
|
||||
|
||||
val extraArgs = mutableListOf<String>()
|
||||
|
|
|
@ -99,6 +99,12 @@ def hermesFlagsForVariant = config.hermesFlagsForVariant ?: {
|
|||
return hermesFlags
|
||||
}
|
||||
|
||||
// Set disableDevForVariant to a function to configure per variant,
|
||||
// defaults to `devDisabledIn${targetName}` or True for Release variants and False for debug variants
|
||||
def disableDevForVariant = config.disableDevForVariant ?: {
|
||||
def variant -> config."devDisabledIn${variant.name.capitalize()}" || variant.name.toLowerCase().contains("release")
|
||||
}
|
||||
|
||||
// Set deleteDebugFilesForVariant to a function to configure per variant,
|
||||
// defaults to True for Release variants and False for debug variants
|
||||
def deleteDebugFilesForVariant = config.deleteDebugFilesForVariant ?: {
|
||||
|
@ -172,8 +178,7 @@ afterEvaluate {
|
|||
workingDir(reactRoot)
|
||||
|
||||
// Set up dev mode
|
||||
def devEnabled = !(config."devDisabledIn${targetName}"
|
||||
|| targetName.toLowerCase().contains("release"))
|
||||
def devEnabled = !disableDevForVariant(variant)
|
||||
|
||||
def extraArgs = []
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче