1

The below code is my config for remove Logcat in debug mode using Proguard follow some post here, here, here but it not work. My Logcat is still display.
What do I do wrong here?
Another question is I see some person suggest another way for remove log is create a custom LogcatUtils class like this, or use Timber so I wonder if Proguard can remove Logcat or not ?
I still prefer remove Logcat completely because I think it may reduce the APK size.
Any help or suggestion would be appreciated.

My build.grade

 buildTypes {
    debug {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }

proguard-rules.pro

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

Activity code

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        for(int i = 0; i < 20; i++) {
            Log.d("TAG", "hehe");
        }
    }
}

I have tested it on emulator with Build Variant = debug DEMO PROJECT: https://drive.google.com/file/d/0B_poNaia6t8kSTRMV2cxUjlaSDA/view?usp=sharing

Community
  • 1
  • 1
Linh
  • 57,942
  • 23
  • 262
  • 279

1 Answers1

2

Try adding debuggable configuration

debug {
  minifyEnabled true
  debuggable false //add this to remove logcat
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
arjun
  • 3,514
  • 4
  • 27
  • 48
  • thank you. but I have test and Logcat still display :(. if you want to see the demo project, please check https://drive.google.com/file/d/0B_poNaia6t8kSTRMV2cxUjlaSDA/view?usp=sharing – Linh Mar 01 '17 at 07:14
  • you have zipped the project with build folder which makes the file too big to download. can u just post the `build.gradle` file alone – arjun Mar 01 '17 at 07:19
  • it just 28Mbs. my demo project is really simple don't contains any specific part. if you can not download you can create one then test. I think you will face the problem like me – Linh Mar 01 '17 at 07:21
  • Just take it as a suggestion, whenever you zip an android project make sure you delete the `build` folders – arjun Mar 01 '17 at 07:22
  • https://drive.google.com/file/d/0B_poNaia6t8kSTRMV2cxUjlaSDA/view?usp=sharing thank you for you suggestion. I have delete build update the project – Linh Mar 01 '17 at 07:24
  • I have tested your project. It works as expected. My guess is you are creating a release build and testing that. create a debug build by pressing `shift+F10` in Androidstudio – arjun Mar 01 '17 at 07:31
  • it's really strange, sometime I see the logcat display and sometime I don't see it. I will try to verify then notify you later. thank you so much for your help – Linh Mar 01 '17 at 07:54