简体   繁体   中英

How to disable debug messages in android project?

we have a big project cant delete lot of debug messages and project is in release stage.we want to disable all debug messages in our projects.the debug message format is

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("Gajanand", "onCreate: just check");
}

i tried with

Android:debuggable="false"

but its not working and also tried to change build variant to release but getting many errors not able to build project .please any help

You could use the following proguard-rule in order to ignore all Debug and Verbose Logs in a release:

# ignore all Debug and Verbose Logs in a release
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}

So you dont have to "disable" all your Logs manually - they get just obfuscated.

In order to apply this proguard rule you have to use the optimization function of proguard by modifying your gradle file:

buildTypes {
    release {
        shrinkResources false
        minifyEnabled true
        zipAlignEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
                'proguard-rules.pro'
        signingConfig signingConfigs.config
        proguardFile '/<your-custom-file>/app/proguard-rules.pro'
        debuggable false
    }
}

Also have a look in the proguard manual: https://www.guardsquare.com/en/proguard/manual/usage

For my project I was able to get rid of the debug messages with the following.

  1. First I went to the proguard-rules.pro file that should be near your build.gradle file. In that file I added:

    -assumenosideeffects class android.util.Log { public static * d(...); }

  2. Then I went to the build.gradle file and added:

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

For more info go here .

you can do the hard way and use remplace " Ctr + shift + r " and remplace all the "log." by " // " to put in comment all the log request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM