Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiating debug and production build of an Android app

I recently started learning about Android app development. It's also my first experience with the Java language.

There are some debugging tools that I want to incorporate into my app development in a form of Java package dependency. For obvious reasons, I would like to include it only for debug builds.

In iOS, we can use build configuration to link with debugging libraries only for debug builds, and use macros to remove parts of code that deals with debugging. This makes it really easy to switch between debug and production builds. Anyway to achieve the same for Android?

So far, the closest I got is using Maven profiles to overwrite properties files, which gets loaded by the application, but this requires that the debugging libraries are still imported.


To clarify my question, here is what I want to do: I built a library that will let you browse the SQLite database on your browser. It's really useful for debugging purposes, but I don't want to ship my app with the library.

Another purpose is to use HockeyApp. HockeyApp provides two features: Update notification, and crash reporting. I need three different builds for this to work:

  • Production: Crash reporting On, Update notification Off
  • Beta: Both On
  • Debug: Both Off
like image 941
Barum Rho Avatar asked Mar 29 '13 02:03

Barum Rho


People also ask

What is production build in android?

There are two different types of android framework build (the entire system image) user (aka production) and userdebug. All standard device maker release their device with "user" build. Userdebug is meant for development and typically only built for in-house use.

What is the difference between release and debug in Android Studio?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

How do you check if APK is debug or release programmatically?

There are different way to check if the application is build using debug or release certificate, but the following way seems best to me. According to the info in Android documentation Signing Your Application, debug key contain following subject distinguished name: "CN=Android Debug,O=Android,C=US".

What is the difference between production build and debug build?

They both have the same app ID but are signed with a different signature. If you want to switch between production and debug it means uninstallations in between. You should always have the production build of your app installed and not uninstall it to run debug.

What is debug mode in Android Studio?

An Android app will execute in debug mode in the development environment, i.e. while running in the Android Studio Integrated Development Environment (IDE). The app will execute in release mode when installed from Google Play. In release mode any debug logging, StrictMode, and the debugging option must be disabled.

How to debug new build types in Android Studio?

Usually, you can just select the default "debug" variant that's included in every Android Studio project (even though it's not visible in the build.gradle file). But if you define new build types that should be debuggable, you must add `debuggable true` to the build type:

Should I leave the Android debuggable attribute out of the manifest?

Now if android:debuggable is explicitly set then Studio will display a warning: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one It's best to leave out the android:debuggable attribute from the manifest.


1 Answers

In the manifest's <application>, you can set the debuggable attribute. Eclipse does this for you automatically if you omit the attribute. Debug builds have debuggable=true, well exported builds have debuggable=false.

This affects Log.d, and you can conditionally check in code using the following:

boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
like image 89
323go Avatar answered Oct 05 '22 23:10

323go