Skip to content

Commit

Permalink
Fix devDisabledInStaging not working with multiple productFlavors (#3…
Browse files Browse the repository at this point in the history
…0606)

Summary:
Fixes #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: #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
  • Loading branch information
geraintwhite authored and facebook-github-bot committed Oct 25, 2021
1 parent 64711b0 commit 055ea9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down
9 changes: 7 additions & 2 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?: {
Expand Down Expand Up @@ -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 = []

Expand Down

0 comments on commit 055ea9c

Please sign in to comment.