简体   繁体   中英

How to use an Android library without log4j dependency?

I am developing an app on a JellyBean device and I love the new Instant run feature of Android studio. Using it on a JellyBean device, however, requires a non-multidexed app. I have managed to cut down the dex size by removing a few dependencies.

The problem is that I would really like to ommit log4j library, which is the one that takes me over the dex limit, but I need to use another library(gpxParser) which makes calls to log4j and crashes with this error during runtime.

Caused by: java.lang.NoClassDefFoundError: org.apache.log4j.Logger

I have tried some Proguard nowarns but to no avail. The app runs just fine without log4j included until I hit a call from the library that uses it. I have searched all over the internet but I can´t find any way to do this.

There's a file gpxparser.properties , and a class AndroidLogger .

See if you can get those two together.

You can configure Proguard to remove calls to logging frameworks such as Log4j. As Proguard operates on byte code level it doesn't matter if you have the source code of the library or not.

use the assumenosideeffects of Proguard to mark classes and methods that you assume can be removed without any negative side effects.

There is an example on Stackoverflow for the Android Log system: Removing Log call using proguard

You can adapt this example and change it to match org.apache.log4j.Logger and other classes from log4j instead.

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