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

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

Open
todesignandconquer opened this issue Mar 17, 2020 · 6 comments
Labels
bug Something isn't working good first issue Good for newcomers platform: android Affects Android question Further information is requested

Comments

@todesignandconquer
Copy link

todesignandconquer commented Mar 17, 2020

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 todesignandconquer changed the title Could not find BuildConfig class error when attempting to assembleRelease Enabling ProGuard results in "Could not find BuildConfig class" error when attempting to assembleRelease Mar 17, 2020
@youngjuning
Copy link
Contributor

youngjuning commented May 8, 2020

try cd android && ./gradlew app:assembleRelease

@csath
Copy link
Owner

csath commented Jun 17, 2020

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 csath added the good first issue Good for newcomers label Jun 22, 2020
@AdamLee321
Copy link

AdamLee321 commented Sep 14, 2020

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
Copy link

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

@yogendrajs
Copy link

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?

@prometheas
Copy link
Collaborator

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 prometheas added bug Something isn't working platform: android Affects Android question Further information is requested labels Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers platform: android Affects Android question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants