question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react.gradle does not support custom release build types (name not including "release")

See original GitHub issue

Description

We have several Android release build types, defined in our android/app/build.gradle. They have other names than Release, of course. Like “Staging”.

The problem with react.gradle is that it has multiple checks for isRelease that only consider the target name, like here: https://github.com/facebook/react-native/blob/164e133a98fade1c0f7577476e411bf9f6c2b7ca/react.gradle#L330

As a consequence of this, Hermes sourcemaps are not built for these release variants, as hermesFlagsDebug is used, not hermesFlagsRelease: https://github.com/facebook/react-native/blob/164e133a98fade1c0f7577476e411bf9f6c2b7ca/react.gradle#L189

Maybe one could instead use "config.bundleIn${targetName}" and/or config."devDisabledIn${targetName}" to check if a target is a release variant?

React Native version:

0.63.4

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Add another buildType block to android/app/build.gradle called “Staging”. Something like this:
            initWith(buildTypes.release)
            applicationIdSuffix ".staging"
            matchingFallbacks = ['release']
        }
  1. Configure Staging for release in project.ext.react:
project.ext.react = [
    devDisabledInRelease : true,
    bundleInRelease      : true,
    devDisabledInStaging : true,
    bundleInStaging      : true,
  1. Add some logging to node_modules/react-native/react.gradle to check the evaluation of isRelease
def isRelease = targetName.toLowerCase().contains("release")
+println "isRelease? ${isRelease}"
  1. Build the app with gradle and check the logs
cd android
./gradlew assembleStaging

Expected Results

I expect other release variants to also be treated as the one called Release.

Snack, code example, screenshot, or link to a repository:

Simplified and redacted. We use Yarn Workspaces (monorepo) so paths might look weird.

android/app/build.gradle:

project.ext.react = [
    root                 : "../..",
    cliPath              : "../../node_modules/react-native/cli.js",
    bundleConfig         : "metro.config.js",
    composeSourceMapsPath: "../../node_modules/react-native/scripts/compose-source-maps.js",
    hermesCommand        : "../../../../node_modules/hermes-engine/%OS-BIN%/hermesc",
    entryFile            : "index.ts",
    enableHermes: true,  // clean and rebuild if changing

    environmentForRelease: "prod",
    devDisabledInRelease : true,
    bundleInRelease      : true,
    environmentForStaging: "staging",
    devDisabledInStaging : true,
    bundleInStaging      : true,
]
buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
        }
        staging {
            initWith(buildTypes.release)
            applicationIdSuffix ".staging"
            matchingFallbacks = ['release']
        }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
draperunnercommented, Jan 25, 2021

If this is a valid approach, I would happily submit a PR

-def isRelease = targetName.toLowerCase().contains("release")
+def isRelease = targetName.toLowerCase().contains("release") || config."devDisabledIn${targetName}" && config."bundleIn${targetName}"
2reactions
dincengincancommented, Jan 20, 2022

@draperunner You saved my day!

We have a react native project within a monorepo. I was having a lot of issues with the wrong node/modules path of hermes and compose-source-maps while building the app.

If there is anyone having issues with monorepo project while building the app, you can configure the paths as below:

composeSourceMapsPath: "../../node_modules/react-native/scripts/compose-source-maps.js",
hermesCommand        : "../../../../node_modules/hermes-engine/%OS-BIN%/hermesc",

Thanks a lot again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native build fails on building a new build type other ...
I have modified my build.gradle to add a staging environment. I am not sure why this is happening as my debug and release...
Read more >
Configure build variants | Android Developers
Once the sync completes, Gradle automatically creates build variants based on your build types and product flavors and names them according to < ......
Read more >
Upgrading your build from Gradle 7.x to the latest
Type safe Kotlin DSL accessors generation for precompiled script plugins does not fail the build by default if a plugin requested in such...
Read more >
Bundling React Native during Android release builds
Make sure gradle.properties does not include org.gradle.configureondemand=true as that will make release build skip bundling JS and assets into the APK.
Read more >
Prerequisites for Applications - React Native
React Native released the support for the New Architecture with the ... the AGP version should be updated inside the top-level build.gradle ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found