Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29452

Setting process.env variable from Android Studio flavors

$
0
0

I want to be able to access a variable in my metro.config.js.

On iOS this can be achieved by adding a User Defined variable in the Build Settings tab. This is accessible with process.env.MY_VAR. The value of MY_VAR can be changed depending on which target is being built.

How can I achieve the same for Android using product flavours?

Here is my current setup

    flavorDimensions "apps"
    productFlavors {
        free {
            dimension "apps"
        }
        paid {
            dimension "apps"
        }
    }

Execution Steps

When running iOS, I can see from the logs that the project gets built before the Packager starts

info Found Xcode workspace "foo.xcworkspace"
info Building (using "xcodebuild -workspace foo.xcworkspace -configuration Debug -scheme foo -destination id=CE408502-CD8C-4467-AE3D-295081CAF132 -derivedDataPath build/foo") <-- Build
▸ Running script '[CP-User] Config codegen'▸ Compiling ReactNativeConfig.m
▸ Building library libreact-native-config.a
▸ Running script 'Upload Debug Symbols to Sentry'▸ Running script 'Start Packager              <-- Metro starts here

However, the packager starts before my gradle build task executes

info Starting JS server...                    <-- Metro starts here
info Installing the app...
> Configure project :app
Reading env from: .env
> Task :app:installFreeDebug                  <-- Build

Viewing all articles
Browse latest Browse all 29452

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>