0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
rxj
  • 39
  • 1
  • 11
  • If this library is open source you could try to create your own version of that library in where you will remove all calls to log4j – Alexander Kulyakhtin May 18 '16 at 15:13
  • The library in question states that it is licensed under LGPL, and the author does provide source. Can I make these changes? I am planning on publishing the app on Google play with the possibility of monetization. – rxj May 18 '16 at 15:17
  • You can make the changes for yourself to make sure log4j is out of the way. If yes you will consider further, I don't remember what LGPL wants maybe you will have to add author's name somewhere – Alexander Kulyakhtin May 18 '16 at 15:22

2 Answers2

0

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

See if you can get those two together.

JimmyB
  • 12,101
  • 2
  • 28
  • 44
  • Thank you, I have been trying to figure out what to do with the file since you posted your answer, but I am at a loss. I understand that you wanted me to figure it out for my self but I have already spent too much time on this problem and I posted to SO as a last resort in hopes of a straight answer. Do I have to build the library my self and somehow provide the properties file? Or do I put the file somewhere in my project and let gradle know about it? You seem to know what to do and I would reallly appreciate a little more detailed answer. – rxj May 18 '16 at 15:48
  • Well, I don't know any more than you. Having one more look, it seems that the lib is trying to [load the config file](https://sourceforge.net/p/gpxparser/code/HEAD/tree/trunk/GPXParser/src/org/alternativevision/gpx/log/FacadeLogger.java#l72) and, if that file is not there, should be falling back to a no-op logger. So I'd think that it actually should run when there's no `gpxparser.properties`. – JimmyB May 18 '16 at 16:07
0

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.

Community
  • 1
  • 1
Robert
  • 39,162
  • 17
  • 99
  • 152