Home > database >  How to print log inside release aar
How to print log inside release aar

Time:12-22

I want to build an apk and inside it I need to use release aar inside it. The aar must be release build since I need to shrink and obfuscate it.

But I would like to print the log for network log to see if my obfuscation will not bother the request payload.

I tried to use System.out.println, but I could not see any log from aar.

Any suggestions?

CodePudding user response:

You should be able to turn it on in the manifest/build.gradle. Enable LogCat on Release Build in Android Studio

There have been a few changes to it over the years so you may have to look at more than the accepted answer.

You can also use this library https://github.com/tony19/logback-android

It can create log files on the device, that you can open and inspect.

CodePudding user response:

You can use gradle build config field to enable/disable log print.
Default value for Gradle buildConfigField boolean used across flavors
First create a log wrapper function with a boolean parameter, true means enable log print. And then you can create an init funtcion for your aar, in which you can set log enable parameter.
Meanwhile define a build config field in your app.gradle:

 debug {
        buildConfigField "boolean", "ENABLE_LOG", "true"
    }
 release {
        buildConfigField "boolean", "ENABLE_LOG", "false"
    }

Then just call aar.init(BuildConfig.ENABLE_LOG) on Application.oncreate()

  • Related