Skip to content

Desugar Task should provide deps / --classpath_entry(s) #2143

Closed

Description

@erikpowa

Steps to Reproduce

  1. Build an app project with some binding library

Expected Behavior

desugar_deploy.jar desugaring .jar with dependencies without exception

Actual Behavior

Desugar entirely skips the --classpath_entry dependencies for .jar (or it's by design? please no) when desugar_deploy.jar gets called, causing failures just like:

1> Exception in thread "main" java.lang.TypeNotPresentException: Type okhttp3.Interceptor not present

Version Information

xa sdk 9.1.0.19

Fast repro + good scenario

xabug.zip

Activity

  1. changed the title [-]CompileToDalvikWithDx should provide deps / --classpath_entry(s) while desugaring[/-] [+]Desugar Task should provide deps / --classpath_entry(s)[/+] on Sep 5, 2018
  2. JonDouglas commented on Sep 5, 2018

    @JonDouglas
    Contributor

    desugar_deploy.jar is deprecated as it was a standalone desugar tool that was integrated into the d8/r8 pipeline, and thus our initial support for desugar does not handle this scenario. We will need to ensure we are accounting for this within our r8 and d8 proposal.

    #2040

    Our source for the desguar task can be found here:

    https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs

    At first glance, it looks like we would need to add this --classpath_entry switch and append the respective .jar file name foreach item. @jonathanpeppers can chime in further on this.

  3. erikpowa commented on Sep 5, 2018

    @erikpowa
    ContributorAuthor

    I just patched the IL in here.
    smy24w1
    tested (with multidex) and it's working

    commandLineBuilder.AppendSwitch("--classpath_entry ");
    commandLineBuilder.AppendFileNameIfNotNull(text);
    

    Won't PR it then if it's deprecated

  4. JonDouglas commented on Sep 5, 2018

    @JonDouglas
    Contributor

    @erikpowa To be more specific, the desguar.jar is going to be deprecated in favor of the desugar step being included in the new dex compiler (d8). I don't believe the new dex compiler has an option to provide this argument. I'd defer to @jonathanpeppers whether he thinks it's worth to PR or not.

  5. jonathanpeppers commented on Sep 7, 2018

    @jonathanpeppers
    Member

    @erikpowa feel free to send a PR!

    I'm trying to follow what you're changing here, but not seeing exactly. There isn't a variable named text in our Desugar MSBuild task.

    Are we missing jar files as --input? https://github.com/xamarin/xamarin-android/blob/f6c3288dd5a7f82c178ef30ad25c11d475f1daf4/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs#L85-L92

    Or do we need to specify --classpath_entry for each jar file in addition to --input?

  6. erikpowa commented on Sep 7, 2018

    @erikpowa
    ContributorAuthor

    @jonathanpeppers sorry, I modified the Xamarin.Android.Build.Tasks.dll with dnSpy, I was lazy to clone/edit/build/push from source, and yes, my repro shows the current standalone desugar fails if there are certain jars that needs it's dependencies as classpath_entry, othwerwise it fails if not passed as argument. (such as twitter-core)

    The hackish way looks like this (just make every --input --classpath_entry aswell):

    foreach (var jar in InputJars) { 
     	var output = Path.Combine (OutputDirectory, BitConverter.ToString (md5.ComputeHash (Encoding.UTF8.GetBytes (jar))) + Path.GetFileName (jar)); 
     	outputs.Add (output); 
     	cmd.AppendSwitch ("--classpath_entry"); 
     	cmd.AppendFileNameIfNotNull (jar); 
     	cmd.AppendSwitch ("--input "); 
     	cmd.AppendFileNameIfNotNull (jar); 
     	cmd.AppendSwitch ("--output "); 
     	cmd.AppendFileNameIfNotNull (output); 
     } 
    
  7. gmoney494 commented on Sep 11, 2018

    @gmoney494

    @erikpowa another way to get past this error without modifiying the dll?

  8. erikpowa commented on Sep 11, 2018

    @erikpowa
    ContributorAuthor

    @gmoney494 don't think so, you can build it XA manually tho, but it's only working >=7.0, something is messing around under api 24

  9. erikpowa commented on Sep 11, 2018

    @erikpowa
    ContributorAuthor

    @gmoney494 or you can make a custom desugar task on jar files that runs before Desugar task and try addig one of these arguments aswell (but it's untested)

  10. ghost locked as resolved and limited conversation to collaborators on Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions