Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android compile error #16

Closed
tapir opened this issue Jan 8, 2019 · 10 comments
Closed

Android compile error #16

tapir opened this issue Jan 8, 2019 · 10 comments

Comments

@tapir
Copy link

tapir commented Jan 8, 2019

Although I can work with ipaddress outside of an android project, when I'm trying in one I get this error

ipaddress-5.0.1.jar: D8: Illegal class file: Class module-info is missing a super type.

Any ideas?

@seancfoley
Copy link
Owner

seancfoley commented Jan 8, 2019

The module-info is used only with Java 9 and up for the new "Jigsaw" module feature added with Java 9:
https://www.oracle.com/corporate/features/understanding-java-9-modules.html

I added that file only for those who wished to use Java 9 modules. Using modules is somewhat optional (you can choose to put everything in the default module).

AFAIK Android does not yet support Java 9, but does support most, if not all, of Java 8. Certainly, it sounds like your android version does not support Java 9 modules.
https://stackoverflow.com/questions/47627499/does-android-studio-3-support-java-9-for-android-development-if-so-what-featur

So you can just delete that source file module-info.java, and you can delete the compiled file module-info.class, it doesn't need to be there when not using modules.

@seancfoley
Copy link
Owner

Perhaps I will add another jar file that does not have module-info inside. In reality the file should be ignored when not using modules but I guess your android environment is not ignoring it. You can just use any zip-file tool (winzip, gzip, winrar, zip, etc) to remove the module-info class file from your jar file (a jar file is actually a zip file).

@tapir
Copy link
Author

tapir commented Jan 8, 2019 via email

@seancfoley
Copy link
Owner

OK, seems you are not the first to encounter this.
Azure/azure-iot-sdk-java#302
Fazecast/jSerialComm#128
Azure/azure-iot-sdk-java#313
JodaOrg/joda-money#94
Leanplum/Leanplum-Android-SDK#251

Not sure if anyone found a nice solution in any of those other issues.

I'll have to give this a little thought.

@seancfoley
Copy link
Owner

seancfoley commented Jan 9, 2019

@tapir Strangely, there appear to be no simple solution from any of Maven, Android Studio, Java, or Gradle, although eventually Android Studio will likely have some kind of fix.

From what I can tell, what others have done:

  1. put separate jar on maven just for android, which seems like a lot of extra overhead just to delete a single small file

  2. there appears to be a jarjar tool some have used, such as in that fazecast bug above Android studio build failed Fazecast/jSerialComm#128 (comment)
    and here https://stackoverflow.com/questions/44913406/exclude-one-class-file-in-gradle-android-studio
    This appears to be the tool: https://github.com/shevek/jarjar
    Looks like you would need something like this:

     dependencies {
     	// Use jarjar.repackage in place of a dependency notation.
     	compile jarjar.repackage {
     		from 'com.github.seancfoley:ipaddress:5.0.1'
    
     		classDelete "module-info"
     	}
     }
    

Not sure if you would need "module-info" or "module-info.class"

There is a complete example build file here: https://github.com/shevek/jarjar/blob/master/jarjar-gradle/example/build.gradle
Can you try this second option?

@seancfoley seancfoley reopened this Jan 9, 2019
@tapir
Copy link
Author

tapir commented Jan 9, 2019

looks like a good solution to me. thanks

@seancfoley
Copy link
Owner

@tapir Have you tried it? If and when you try it, can you let me know if it works?

@tapir
Copy link
Author

tapir commented Jan 9, 2019

Sorry it took a while. Most of the time I've spent went to solve how to apply gradle plugins. TL,DR: It works.
I consider this issue solved.

@tapir tapir closed this as completed Jan 9, 2019
@seancfoley
Copy link
Owner

@tapir Great! Good to know it works. Also, keep in mind Android Studio will almost certainly have its own fix eventually.

@seancfoley
Copy link
Owner

This appears to have been fixed in Android Studio 3.3

Processing module-info.class during desugaring analysis caused failures with the message java.lang.IllegalArgumentException: Type without superclass: module-info. This file is now filtered out during desugaring analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants