13

I have a couple of imported jars that have this error in Eclipse when the project builds:

[2011-04-08 16:31:48 - MokbeeAndroid] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(net.sf.antcontrib.logic.ForEach$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

Now, I didn't really care at first, because there were no errors. But I've now added Apache Sanselan, which has the same problem. Other Apache jars also do this, and not just once per jar, but once per class-that-has-an-inner-class, which makes every build pump out a monstrous console log. Worse, each warning seems to slow the Eclipse build process, and eventually Eclipse just crashes due to a memory overflow error. It's at the point where I can't build anything, even straight after my computer starts up.

The solution would seem to be to recompile the source (open-source and all), but none of it can be recompiled in anything but Maven, which, after doing so to no avail, I suspect is causing the problem in the first place.

I don't care about the results of the warning, just that Eclipse doesn't spend all it's memory on telling me about it. So, is there a way I can either remove the problem, or make Eclipse stop slowing down on it (skipping that check, maybe)?

AlbeyAmakiir
  • 2,217
  • 6
  • 25
  • 48

2 Answers2

8

This was causing me a lot of pain with the android-maven-plugin and other libraries that included commons-logging. It was blocking my build. What made it worse is that some libraries were included transitively, so simply using <exclude> would not work. With a little hint from another post, I determined I could keep out the offending library altogether with something like this:

    <!-- prevent commons-logging from being included by the Google HTTP client 
        dependencies -->
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
        <scope>provided</scope>
    </dependency>
Community
  • 1
  • 1
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • related issue: http://code.google.com/p/maven-android-plugin/issues/detail?id=214 My problem is I couldn't solve it with the method you used, Garret. I'm still investigating. It seems to be that the robolectric dependency is causing this somehow ... – Karussell Jan 31 '12 at 20:20
  • thank you so much! my specific problem was that I had forgotten to mark robolectric as scope test -> it pulls a couple of dependencies that cause this error commons-logging among them! – Yashima Oct 25 '12 at 15:07
1

If you recompile the source of the libraries in Maven, you may need to update the Java version within the POMs to 1.6 (or whatever Java version you're using for your project). Just from looking at Sanselan, I note it specifically has 1.4 as the version.

artbristol
  • 32,010
  • 5
  • 70
  • 103
  • Ah, excellent. That was exactly it. Thanks. It's a bit bizarre, though. You'd think Apache would be using the latest Java version. – AlbeyAmakiir Apr 10 '11 at 22:59
  • 1
    Unfortunately, I can't actually accept this answer any more, as recompiling the classes totally defeats the purpose of having Maven, and I can no longer get away with doing this. – AlbeyAmakiir Sep 26 '13 at 05:06
  • @AlbeyAmakiir Sorry to hear you're still having trouble. It's painful to recompile - but you should only need to do this for a limited number of dependencies. Are you using a repo such as Nexus to store the recompiled versions? – artbristol Sep 26 '13 at 08:48