Asked  7 Months ago    Answers:  5   Viewed   49 times

According to Google, I must "deactivate any calls to Log methods in the source code" before publishing my Android app to Google Play. Extract from section 3 of the publication checklist:

Make sure you deactivate logging and disable the debugging option before you build your application for release. You can deactivate logging by removing calls to Log methods in your source files.

My open-source project is large and it is a pain to do it manually every time I release. Additionally, removing a Log line is potentially tricky, for instance:

  Log.d(LOG_TAG, "Something");

If I comment the Log line, then the condition applies to the next line, and chances are load() is not called. Are such situations rare enough that I can decide it should not exist?

So, is there a better source code-level way to do that? Or maybe some clever ProGuard syntax to efficiently but safely remove all Log lines?



I find a far easier solution is to forget all the if checks all over the place and just use ProGuard to strip out any Log.d() or Log.v() method calls when we call our Ant release target.

That way, we always have the debug info being output for regular builds and don't have to make any code changes for release builds. ProGuard can also do multiple passes over the bytecode to remove other undesired statements, empty blocks and can automatically inline short methods where appropriate.

For example, here's a very basic ProGuard config for Android:

-optimizationpasses 5

-keep class * extends
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);

So you would save that to a file, then call ProGuard from Ant, passing in your just-compiled JAR and the Android platform JAR you're using.

See also the examples in the ProGuard manual.

Update (4.5 years later): Nowadays I used Timber for Android logging.

Not only is it a bit nicer than the default Log implementation β€” the log tag is set automatically, and it's easy to log formatted strings and exceptions β€” but you can also specify different logging behaviours at runtime.

In this example, logging statements will only be written to logcat in debug builds of my app:

Timber is set up in my Application onCreate() method:

if (BuildConfig.DEBUG) {
  Timber.plant(new Timber.DebugTree());

Then anywhere else in my code I can log easily:

Timber.d("Downloading URL: %s", url);
try {
  // ...
} catch (IOException ioe) {
  Timber.e(ioe, "Bad things happened!");

See the Timber sample app for a more advanced example, where all log statements are sent to logcat during development and, in production, no debug statements are logged, but errors are silently reported to Crashlytics.

Tuesday, June 1, 2021
answered 7 Months ago

use logcat -f <filename> in order to dump it to a file in the filesystem.
Make sure the filename you're using is in the sdcard, i.e. starts with /sdcard/....

Also, in order to pass arguments to the logcat program, you should pass the exec method an array of strings (and not one string):

String[] cmd = new String[] { "logcat", "-f", "/sdcard/myfilename", "-v", "time", "ActivityManager:W", "myapp:D" };

Finally, if all else fails, use the full path for logcat: /system/bin/logcat instead of just logcat.

Sunday, June 6, 2021
answered 7 Months ago

It's a bug in the proguard.txt file in the versionedparcelable.aar version 1.0.0. This was fixed in version 1.1.0, however, if you're not using libraries that depends on the new version you'll get this warning in Android Studio 3.5.

In version 1.0.0 the proguard.txt file includes the following line:

-keep public class * extends androidx.versionedparcelable.VersionedParcelable

This was fixed in version 1.1.0:

-keep public class * implements androidx.versionedparcelable.VersionedParcelable

To bypass this issue you can force using the latest version by adding the following line to your build.gradle:

implementation "androidx.versionedparcelable:versionedparcelable:1.1.0"
Sunday, August 1, 2021
answered 5 Months ago

setonclicklistner for main layout of your layout file....


<?xml version="1.0" encoding="utf-8"?>
 <!- Your other view->

and set click listener for mainlayout...

 RelativeLayout rlayout = (RelativeLayout) findViewById(;
 rlayout.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {


Tuesday, August 10, 2021
answered 4 Months ago

Ok, after some time I solved my problem.

I copy/paste a default proguard rules configuration ( to my You can find this file and more examples in path-to-your-sdk/tools/proguard/examples.

For more information, read this.

In my build.gradle I chagend:

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner ""


buildTypes {
    release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''


defaultConfig {
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner ""


buildTypes {
     release {
         minifyEnabled true
         proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
         consumerProguardFiles '' //added this line

Thanks for the help!

Wednesday, September 29, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :