简体   繁体   English

如何使用没有log4j依赖关系的Android库?

[英]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. 我正在JellyBean设备上开发应用程序,并且喜欢Android Studio的新即时运行功能。 Using it on a JellyBean device, however, requires a non-multidexed app. 但是,在JellyBean设备上使用它需要一个非多重应用程序。 I have managed to cut down the dex size by removing a few dependencies. 我设法通过删除一些依赖项来减少了dex的大小。

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. 问题是我真的想省略log4j库,这是使我超出dex限制的库,但是我需要使用另一个库(gpxParser)来调用log4j并在运行时因此错误而崩溃。

Caused by: java.lang.NoClassDefFoundError: org.apache.log4j.Logger 造成原因:java.lang.NoClassDefFoundError:org.apache.log4j.Logger

I have tried some Proguard nowarns but to no avail. 我已经尝试了一些Proguard nowarns,但无济于事。 The app runs just fine without log4j included until I hit a call from the library that uses it. 在没有包含log4j的情况下,该应用程序运行良好,直到我从使用它的库中打了一个电话。 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 . 有一个文件gpxparser.properties和一个类AndroidLogger

See if you can get those two together. 看看是否可以将两者结合在一起。

You can configure Proguard to remove calls to logging frameworks such as Log4j. 您可以配置Proguard以删除对Log4j等日志记录框架的调用。 As Proguard operates on byte code level it doesn't matter if you have the source code of the library or not. 由于Proguard在字节码级别上运行,因此是否具有该库的源代码都没有关系。

use the assumenosideeffects of Proguard to mark classes and methods that you assume can be removed without any negative side effects. 使用assumenosideeffects Proguard的的标记,你可以假设没有任何负面影响被移除的类和方法。

There is an example on Stackoverflow for the Android Log system: Removing Log call using proguard 关于Android Log系统,Stackoverflow上有一个示例: 使用proguard删除Log调用

You can adapt this example and change it to match org.apache.log4j.Logger and other classes from log4j instead. 您可以改编此示例并将其更改为匹配org.apache.log4j.Logger和log4j中的其他类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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