简体   繁体   中英

Is there a way to log filenames in release build using timber for android?

I just started using timber for logging on android, we are trying to add filenames/class-names to log message. I was able to add filenames in debug build using debug tree, but I'm not finding a way to add filenames in the release tree. Is there a possibility to add the filename in the release tree with R8 enabled?

Okay use it like this: Define a TAG variable with your class name in your whole classes as:

private static final String TAG = "Your class name";

then pass your TAG:

Timber.tag(TAG).d("Error %s!", error);

As described here there are several ways to go about this.

For release builds

When you generate an actual release build of the app that you intend to publish on the Play Store you also get a mapping.txt for every release artifact. Upload this file (be careful - every build generates a new file, so you must use the exact file that was generated with your artifact) and Google will deobfuscate crash logs in the Google Play Console for you.

You also have the option to use the retrace command line tool to translate logs you receive from this build yourself using mapping.txt .

For non-release builds/internal testing

Since you will not be releasing this artifact to the world it is possibly acceptable to break your own code obfuscation. You can use rules in the proguard-rules.pro file to keep relevant information during R8 shrinking.

Check the docs for all relevant parameters. Especially useful are -dontobfuscate , -keeppackagenames and -keepattributes (with params like SourceFile and LineNumberTable ).

Remember that changes in shrinking and obfuscating code can break thinks like reflection and resource lookup when you do these manually. So make sure your obfuscated release build works as expected after fiddling with these parameters.

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