1

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?

Francis Bacon
  • 4,080
  • 1
  • 37
  • 48

2 Answers2

1

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()

ruby6221
  • 228
  • 1
  • 7
0

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.

avalerio
  • 2,072
  • 1
  • 12
  • 11
  • the apk is debug apk, but the aar I used in libs folder is release build aar, which build. gradle should I check? – Francis Bacon Dec 21 '21 at 01:53
  • Your library as the app in debug won't stop the logs. – avalerio Dec 21 '21 at 01:58
  • I want to print the log in the library, and the library is now release build. Now I set the `android:debuggable="true"` in dist/SampleApp/app/src/main/AndroidManifest.xml. But it still does not print any log. Did you try that way and can confirm it works? – Francis Bacon Dec 21 '21 at 02:51
  • Francis has the right answer though, for security reasons when you release your app, turn it off.. – Rishabh Ritweek Dec 21 '21 at 03:51