Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I keep BuildConfig in ProGuard?

I've met several proguard examples with these lines:

# Keep the BuildConfig
-keep class com.example.BuildConfig { *; }

I've run app with and without this line (of course, with my package) and haven't found any differences. I've also looked in generated/.../BuildConfig.java and there are no changes too.

What for do I need to keep my BuildConfig in ProGuard?

Thanks!

like image 584
NonGrate Avatar asked Apr 25 '16 11:04

NonGrate


People also ask

What is BuildConfig in Android?

What is BuildConfig? Gradle generates a BuildConfig class that contains static configuration constants that are specific to the build at build time. The class includes default fields such as debug and flavor, but you can override them with build.

What is BuildConfig DEBUG?

In recent versions of the Android Developer Tools (ADT) for Eclipse, there's a class called BuildConfig which is automatically generated by the build. This class is updated automatically by Android's build system (like the R class), and it contains a static final boolean called DEBUG, which is normally set to true.

What is BuildConfig Java?

There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.

What is keep in ProGuard?

-keep disables all of ProGuard's goodness. No shrinking, no obfuscation; not for classes, not for members. In real use cases, you can let ProGuard do at least some of it's work.


1 Answers

BuildConfig contains a number of useful values that are set at compile time. Specifically these:

boolean DEBUG – if the build is debuggable.
int VERSION_CODE
String VERSION_NAME
String APPLICATION_ID
String BUILD_TYPE – name of the build type, e.g. "release"
String FLAVOR – name of the flavor, e.g. "paidapp"

You can also set your own config values, e.g. different urls for testing and production, and retrieve them from the BuildConfig file instead of maintaining your own Config.java file. This can be done by adding buildConfigFields to your gradle buildTypes like so:

buildTypes {
    debug {
        buildConfigField "boolean", "SOME_VAR", "true"
    }
    release {
        buildConfigField "boolean", "SOME_VAR", "false"
    }
}

So to answer your question, as far as I know you don't have to keep the file, but it's good practice to do so and to use it for your config needs.

like image 84
Qw4z1 Avatar answered Oct 03 '22 18:10

Qw4z1