Java Question desugar - fix the "invokedynamic requires" error

Discussion in 'Libraries developers questions' started by Erel, Jul 2, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed 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.
     

    Attached Files:

    Last edited: Nov 6, 2019
    jmon, walterf25, analizer3816 and 2 others like this.
  2. Alberto Iglesias

    Alberto Iglesias Well-Known Member Licensed User

    This working fine for my next library! Thank you!
     
    Erel likes this.
  3. walterf25

    walterf25 Well-Known Member Licensed User

    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?

    Walter
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The ExtractAndMergeClasses should create a merged.jar file in the temp folder. Do you see it?
     
    walterf25 likes this.
  5. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  6. DonManfred

    DonManfred Expert Licensed User

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice