Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need clarification for testing BuildConfig.DEBUG and setting build type

In my android application, I'm trying to run two sets of code so I can automatically change an advertising ID when I'm using Android Studio.

One for when I'm debugging in Android Studio, and one for when I build the .apk to upload to the play store.

I've been using if (BuildConfig.DEBUG), but how can I be sure that that will only be true when I'm actually debugging in Android Studio, and when I build the signed .apk it will be set to false? Where should I be configuring Gradle to know what build type to use, or is this automatically done when clicking Run?

Manifest.xml

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        applicationIdSuffix ".debug"
        debuggable true
    }
}
like image 575
Bryan W Avatar asked Sep 12 '25 13:09

Bryan W


1 Answers

When you generate an APK, the last screen will have a dropdown that lets you choose your build type. It defaults to "Release" but you can change it to "Debug."

That's how the APK is made a debug or release APK.

Basically, if you're running the app with the play button in the top right or with Shift+F10, it'll be built as a debug APK. If you generate a signed APK, it'll be a release APK.

like image 68
TheWanderer Avatar answered Sep 14 '25 04:09

TheWanderer