Java Question desugar - fix the "invokedynamic requires" error

Erel

B4X founder
Staff member
Licensed User
Longtime User
Some of the new Android libraries use Java 8 features. Android doesn't natively support those features so they must be removed (desugared) at some point.

When you wrap a library that includes such features you need to desugar the wrapped library. This is done with an Android tool named desugar.

It can be downloaded from here: www.b4x.com/android/files/Desugar_deploy.jar
This input of this tool is a jar file and the output is a "desugared" jar. You need to do it once and then use the desugared jar.

The latest version of ExoPlayer depends on 7 AAR packages. Desugaring these packages requires several steps:
- Extract the inner classes.jar from each AAR.
- Desugar it.
- Put it back or remove the original one.

To make things easier I wrote a small B4J app that does the following steps:
- Extracts all classes.jar and merges them to a single jar.
- The classes.jar files are removed from the AAR files.
- The merged jar is desugared.

Go over the code before you use it.
Note that it calls zip info: http://infozip.sourceforge.net/Zip.html#Release
zip.exe is available here: https://www.b4x.com/android/forum/t...r-merged-jar-is-not-a-val.111005/#post-693285
If the classes.jar depend on other libraries then you will need to add references by adding additional --bootclasspath_entry parameters.
 

Attachments

  • B4J-Desugar.zip
    1.5 KB · Views: 1,135
Last edited:

walterf25

Expert
Licensed User
Longtime User
Some of the new Android libraries use Java 8 features. Android doesn't natively support those features so they must be removed (desugared) at some point.

When you wrap a library that includes such features you need to desugar the wrapped library. This is done with an Android tool named desugar.

It can be downloaded from here: www.b4x.com/android/files/Desugar_deploy.jar
This input of this tool is a jar file and the output is a "desugared" jar. You need to do it once and then use the desugared jar.

The latest version of ExoPlayer depends on 7 AAR packages. Desugaring these packages requires several steps:
- Extract the inner classes.jar from each AAR.
- Desugar it.
- Put it back or remove the original one.

To make things easier I wrote a small B4J app that does the following steps:
- Extracts all classes.jar and merges them to a single jar.
- The classes.jar files are removed from the AAR files.
- The merged jar is desugared.

Go over the code before you use it.
Note that it calls zip info: http://infozip.sourceforge.net/Zip.html#Release
If the classes.jar depend on other libraries then you will need to add references by adding additional --bootclasspath_entry parameters.
I'm trying to run this project so that I can desugar around 4 .aar files and i keep getting the following error, I have changed all the necessary paths required for the Desugar_deploy.jar file, the folder where the .aar files are etc. what am i doing wrong?

Error parsing command line: While parsing option --input=Merged.jar: Merged.jar is not a valid path: it does not exist.

Walter
 

walterf25

Expert
Licensed User
Longtime User
The ExtractAndMergeClasses should create a merged.jar file in the temp folder. Do you see it?
It wasn't creating the merger.jar file at first, i had downloaded a newer version of zip.exe, i found an older version of that exe file and it seems to work better now, however I keep getting errors about missing classes, i'm assuming these are classes that the library relies on.

Thanks,
Walter
 

DonManfred

Expert
Licensed User
Longtime User
however I keep getting errors about missing classes
when running the desugar task?
Or when using the desugared files in your project?
In the last you need to included the merged.jar (#AdditionalJar) as it contains the desugared javacode of the AAR files.
 

Randy Younger

Member
Licensed User
When I run the b4J, after changing the paths, and pointing to the old zipe.exe, the app crashes when trying to extract from the .aar files. It never extracts classes.jar. I have tried to unzip them manually and there are no classes.jar files inside of the .aar files.
 
Top