Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android variant release not working #223

Closed
sodaoud opened this issue Feb 9, 2018 · 10 comments
Closed

Android variant release not working #223

sodaoud opened this issue Feb 9, 2018 · 10 comments

Comments

@sodaoud
Copy link

sodaoud commented Feb 9, 2018

I have a project with multiple flavors the build.gradle file looks like this

project.ext.envConfigFiles = [
        flavorx: ".env.flavorx",
        flavory: ".env.flavory",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

android {
    ...
    productFlavors {
        flavorx {
            applicationId 'flavor.x'
            resValue "string", "build_config_package", "default.package.name"
        }
        flavory {
        }
    }
}

in the debug mode everything works fine, and each flavor get its specific config.

but in release mode the .env file is not loaded and I get empty values, even though this line appears in the terminal

Reading env from: .env.flavorx

I also tried this starting the build using this command
ENVFILE=.env.flavorx ./gradlew assembleFlavorxRelease
and the result is similar

any suggestions ?

@sodaoud sodaoud changed the title Android multi flavors evironment n Android variant release not working Feb 9, 2018
@sodaoud
Copy link
Author

sodaoud commented Feb 10, 2018

It was just a proguard issue. Resolved by adding this line to proguard-rules :

-keep class default.package.name.BuildConfig { *; }

@sodaoud sodaoud closed this as completed Feb 10, 2018
@YarekTyshchenko
Copy link

@sodaoud does default.package.name get somehow magically substituted?

@muhammadsr
Copy link

@YarekTyshchenko mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

@vitorreis
Copy link

I am having the same issue, but even after configuring everything as in the docs, it just don't work here :(

I see that even generates the resource xml file with the correct values in the output folder, but on react native code the Config object is completely empty

@frankiewiczkamil
Copy link

frankiewiczkamil commented Oct 25, 2018

Same situation like @vitorreis mentioned: run-android (not release mode), generated.xml contains my env values, but object in runtime is empty... For ios it works fine.
Did anyone solve this already...?

@vitorreis
Copy link

@frankiewiczkamil I couldn't get it working, so in the end I used the library: https://github.com/zetachang/react-native-dotenv

@krystofbe
Copy link

I've had the same problem, setting proguard-rules didn't help, because I had proguard already disabled.

what helped was setting a fixed build_config_package in android/app/build.gradle

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}

hope this helps

@mcanobbio
Copy link

I changed the original applicationId from the app and also the package name in the manifest and both are the same and the @sodaoud solution works for me thanks a lot.

@cassmtnr
Copy link

cassmtnr commented Apr 5, 2019

I really don't get the build_config_package string there... is this exactly word or should I use the env string I set?

.env:
APP_ID=com.appname.here

resValue "string", "build_config_package", project.env.get("APP_ID")

or

resValue "string", "APP_ID", project.env.get("APP_ID")

@pedrorosarioo
Copy link

I've had the same problem. Solved by @krystofbe solution. Remember to remove resValue of your productFlavors config, and set it only in defaultConfig. Otherwise, it will get overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants