react-native-config-reader icon indicating copy to clipboard operation
react-native-config-reader copied to clipboard

Enabling ProGuard results in "Could not find BuildConfig class" error when attempting to assembleRelease

Open todesignandconquer opened this issue 4 years ago • 6 comments

React Native: 61 Android: AndroidX

There seems to be an issue with assembling for release when using ProGuard:

android() {
...
    buildTypes {
        debug {
            buildConfigField "String", "FOO", "\"bar\""
        }
        release {
            buildConfigField "String", "FOO", "\"baz\""
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
...
}

In short, attempting to build via ./gradlew assembleRelease -x bundleReleaseJsAndAssets builds the project just fine, but it results in RN Config Reader throwing the following error:

ReactNative: RNConfigReader: Could not find BuildConfig class

The app assembles and works just fine using assembleDebug. All of the build variant BuildConfig files are properly automatically generated with the correct values.

import Config from 'react-native-config-reader'

export default class Root extends React.Component<void, void> {
    constructor(props: any) {
        super(props)

        console.log('Config', JSON.stringify(Config))
    }
}

Config returns null.

Any suggestions?

todesignandconquer avatar Mar 17 '20 23:03 todesignandconquer

try cd android && ./gradlew app:assembleRelease

youngjuning avatar May 08 '20 02:05 youngjuning

Seems it renames the BuildConfig Java class in ProGuard minification process.

@todesignandconquer Can you try adding this line to your android/app/proguard-rules.pro -keep class com.yourNewPackage.BuildConfig { *; }

Please note that com.yourNewPackage should be replaced with your package name.

This should hopefully resolve your issue.

csath avatar Jun 17 '20 18:06 csath

I am having the same issue I upgraded from RN 0.59.10 to RN 0.61.5 and now RNConfigReader is null works on iOS fine just an Android issue. I tried the above solution but it didn't work. Any other help with this would be much appreciated.

The version of the library I am using is: "react-native-config-reader": "^4.1.1"

AdamLee321 avatar Sep 14 '20 10:09 AdamLee321

Update: The issue is definitely with this library as I installed another and everything works fine now.

AdamLee321 avatar Sep 14 '20 11:09 AdamLee321

Update: The issue is definitely with this library as I installed another and everything works fine now.

@AdamLee321 which one did you install that fixes this?

yogendrajs avatar Nov 03 '21 13:11 yogendrajs

Hey, everyone. I wanted to introduce myself as a new maintainer for this project. More information about circumstances is available in my closing comment on #41, so please have a look there for some important information.

That said, I'm just checking in on some existing issues and seeing if they're still relevant, as well as exploring how to proceed.

prometheas avatar Feb 02 '22 17:02 prometheas