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

Binding Project - Error with Desugaring #1639

Closed
eclipsed4utoo opened this issue May 3, 2018 · 9 comments
Closed

Binding Project - Error with Desugaring #1639

eclipsed4utoo opened this issue May 3, 2018 · 9 comments

Comments

@eclipsed4utoo
Copy link

I am attempting to write a binding for a third-party library. That library makes use of Java 8 features. Because of this, I have to use desugaring.

I seem to be running into an issue with desugaring, and I'm not sure where I am going wrong. Without desugaring, I get 4 build errors about missing java features. When I enable desugaring, I get one build error.

Error: java.lang.TypeNotPresentException : Type io.reactivex.functions.Action not present

The third-party library does use rxjava2, and the Action type is in the .jar(used JD-GUI to look in the jar).

I've done tons of searching and having been able to figure out what is going on or how to fix it. I'm hoping somebody with Xamarin could help.

Steps to Reproduce

  1. Build the attached solution
  2. See build error
    BindingTest.zip

Expected Behavior

Android project should build.

Actual Behavior

Android project does not build.

Version Information

=== Visual Studio Community 2017 for Mac ===

Version 7.4.3 (build 10)
Installation UUID: cb04a5a4-cb32-4108-987e-e5123c1b9a67
Runtime:
Mono 5.8.1.0 (2017-10/6bf3922f3fd) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 508010000

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.0.5
2.0.0
1.1.1
1.0.4
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
2.1.4
2.0.0
1.0.3
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.Mac ===

Version: 4.2.1.29 (Visual Studio Community)

=== Xamarin.iOS ===

Version: 11.9.1.24 (Visual Studio Community)
Hash: f62de472
Branch: xcode9.3
Build date: 2018-03-29 19:30:53-0400

=== Xamarin.Android ===

Version: 8.2.0.16 (Visual Studio Community)
Android SDK: /Users/ralford/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.2 (API level 17)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 704030010
Git revision: 5af3e98549653fcc5335896ccc296343d08f31bb
Build date: 2018-04-12 12:32:07-04
Xamarin addins: fadb82fb0fe2668cb7789f8b524aec6fb8568ee7
Build lane: monodevelop-lion-d15-6

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
Mon Nov 13 21:56:25 PST 2017
root:xnu-3789.72.11~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1

Log File

@jonathanpeppers
Copy link
Member

jonathanpeppers commented May 16, 2018

So I'm able to repro on 15.7 stable with the sample project, here is the log of interest:

Desugar
    Assembly = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll
    CommandLineArguments = C:\Program Files\Java\jdk1.8.0_161\\bin\java.exe -Xmx2G -jar "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\desugar_deploy.jar" --bootclasspath_entry "C:\Program Files (x86)\Android\android-sdk\platforms\android-26\android.jar" --min_sdk_version 21 --input obj\Debug\android\bin\classes --output obj\Debug\android\bin\desugared\__app_classes__.jar --input "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.0\mono.android.jar" --output obj\Debug\android\bin\desugared\77-62-E1-E3-1A-D6-EA-45-47-2E-9C-5C-61-78-9E-E7mono.android.jar --input "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\android-support-multidex.jar" --output obj\Debug\android\bin\desugared\2F-53-0B-D0-E6-E5-2A-6B-5A-6B-75-57-54-21-CF-8Fandroid-support-multidex.jar --input obj\Debug\lp\1\jl\domain-300.06-SNAPSHOT.jar --output obj\Debug\android\bin\desugared\DF-CE-93-F2-0E-90-E6-A7-70-3B-51-88-11-DD-CD-2Ddomain-300.06-SNAPSHOT.jar --input obj\Debug\lp\1\jl\__reference__reactive-streams-1.0.0.jar --output obj\Debug\android\bin\desugared\19-D5-F0-F4-3D-78-93-FC-C9-43-F5-B5-4A-00-AD-3D__reference__reactive-streams-1.0.0.jar --input obj\Debug\lp\1\jl\__reference__relinker.jar --output obj\Debug\android\bin\desugared\10-60-63-20-4B-35-75-2E-2D-11-E0-5D-1D-8E-FA-8A__reference__relinker.jar --input obj\Debug\lp\1\jl\__reference__rxjava-2.1.2.jar --output obj\Debug\android\bin\desugared\57-AA-40-5E-AA-41-DD-E4-9C-85-FC-E0-41-C7-F9-57__reference__rxjava-2.1.2.jar --input obj\Debug\lp\11\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\FD-70-42-3A-EA-8A-B4-59-60-36-15-EF-BD-D4-F2-9Bclasses.jar --input obj\Debug\lp\13\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\2A-7B-42-63-D3-6D-84-71-30-6C-F3-22-08-11-CA-E6classes.jar --input obj\Debug\lp\14\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\CF-0C-BF-9D-32-8E-4D-42-BC-7C-E8-D8-BE-B4-4D-E9classes.jar --input obj\Debug\lp\15\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\12-60-4C-C5-E0-34-5A-EE-57-A0-6A-E6-FC-4C-D0-73classes.jar --input obj\Debug\lp\16\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\43-16-60-E0-50-3D-04-45-33-41-93-B6-C2-14-39-6Dclasses.jar --input obj\Debug\lp\17\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\3B-61-87-37-4C-58-0A-5C-E8-3B-C3-68-8D-D1-AA-5Fclasses.jar --input obj\Debug\lp\18\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\9C-48-94-B4-DC-79-7E-F6-FD-89-E3-8C-10-77-10-99classes.jar --input obj\Debug\lp\19\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\04-5E-10-66-2D-35-4B-A6-DC-30-C2-B4-B4-66-4B-F3classes.jar --input obj\Debug\lp\20\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\31-17-D5-8D-76-07-ED-09-CC-59-14-DE-78-4C-38-BBclasses.jar --input obj\Debug\lp\21\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\55-B9-E2-70-65-E4-02-3D-B1-4F-84-A5-CB-60-5B-B5classes.jar --input obj\Debug\lp\22\jl\bin\classes.jar --output obj\Debug\android\bin\desugared\62-90-F1-87-76-DF-19-A8-9F-6F-B1-F5-7F-8C-5E-1Eclasses.jar --input obj\Debug\lp\23\jl\classes.jar --output obj\Debug\android\bin\desugared\F7-D7-E2-2E-12-15-E3-03-2A-07-81-5A-8C-F3-A5-19classes.jar --input obj\Debug\lp\24\jl\classes.jar --output obj\Debug\android\bin\desugared\63-E7-7F-E6-43-ED-01-E5-5B-47-18-D1-91-71-5F-F5classes.jar --input obj\Debug\lp\25\jl\classes.jar --output obj\Debug\android\bin\desugared\CC-86-6F-29-25-7D-77-D6-10-49-A9-2A-91-F8-48-BCclasses.jar --input obj\Debug\lp\26\jl\classes.jar --output obj\Debug\android\bin\desugared\C5-29-A1-37-E8-A8-CA-8B-3E-8C-24-DB-EA-10-93-6Bclasses.jar --input obj\Debug\lp\27\jl\classes.jar --output obj\Debug\android\bin\desugared\91-A0-68-0D-33-25-B8-8F-75-13-B3-67-80-27-5F-3Bclasses.jar 
    Parameters
        JavaPlatformJarPath = C:\Program Files (x86)\Android\android-sdk\platforms\android-26\android.jar
        DesugarJarPath = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\desugar_deploy.jar
        ToolPath = C:\Program Files\Java\jdk1.8.0_161\\bin
        JavaMaximumHeapSize = 2G
        InputClassesDirectory = obj\Debug\android\bin\classes
        InputJars
            C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.0\mono.android.jar
            C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\android-support-multidex.jar
            obj\Debug\lp\1\jl\domain-300.06-SNAPSHOT.jar
            obj\Debug\lp\1\jl\__reference__reactive-streams-1.0.0.jar
            obj\Debug\lp\1\jl\__reference__relinker.jar
            obj\Debug\lp\1\jl\__reference__rxjava-2.1.2.jar
            obj\Debug\lp\11\jl\bin\classes.jar
            obj\Debug\lp\13\jl\bin\classes.jar
            obj\Debug\lp\14\jl\bin\classes.jar
            obj\Debug\lp\15\jl\bin\classes.jar
            obj\Debug\lp\16\jl\bin\classes.jar
            obj\Debug\lp\17\jl\bin\classes.jar
            obj\Debug\lp\18\jl\bin\classes.jar
            obj\Debug\lp\19\jl\bin\classes.jar
            obj\Debug\lp\20\jl\bin\classes.jar
            obj\Debug\lp\21\jl\bin\classes.jar
            obj\Debug\lp\22\jl\bin\classes.jar
            obj\Debug\lp\23\jl\classes.jar
            obj\Debug\lp\24\jl\classes.jar
            obj\Debug\lp\25\jl\classes.jar
            obj\Debug\lp\26\jl\classes.jar
            obj\Debug\lp\27\jl\classes.jar
        ManifestFile = obj\Debug\android\AndroidManifest.xml
        OutputDirectory = obj\Debug\android\bin\desugared
     Desugar Task
       JavaPlatformJarPath: 
       DesugarJarPath: 
       DesugarExtraArguments: 
       ManifestFile: 
       OutputDirectory: 
       InputClassesDirectory: 
       InputJars: 
         C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.0\mono.android.jar
         C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\android-support-multidex.jar
         obj\Debug\lp\1\jl\domain-300.06-SNAPSHOT.jar
         obj\Debug\lp\1\jl\__reference__reactive-streams-1.0.0.jar
         obj\Debug\lp\1\jl\__reference__relinker.jar
         obj\Debug\lp\1\jl\__reference__rxjava-2.1.2.jar
         obj\Debug\lp\11\jl\bin\classes.jar
         obj\Debug\lp\13\jl\bin\classes.jar
         obj\Debug\lp\14\jl\bin\classes.jar
         obj\Debug\lp\15\jl\bin\classes.jar
         obj\Debug\lp\16\jl\bin\classes.jar
         obj\Debug\lp\17\jl\bin\classes.jar
         obj\Debug\lp\18\jl\bin\classes.jar
         obj\Debug\lp\19\jl\bin\classes.jar
         obj\Debug\lp\20\jl\bin\classes.jar
         obj\Debug\lp\21\jl\bin\classes.jar
         obj\Debug\lp\22\jl\bin\classes.jar
         obj\Debug\lp\23\jl\classes.jar
         obj\Debug\lp\24\jl\classes.jar
         obj\Debug\lp\25\jl\classes.jar
         obj\Debug\lp\26\jl\classes.jar
         obj\Debug\lp\27\jl\classes.jar
       OutputJars: 
         obj\Debug\android\bin\desugared\77-62-E1-E3-1A-D6-EA-45-47-2E-9C-5C-61-78-9E-E7mono.android.jar
         obj\Debug\android\bin\desugared\2F-53-0B-D0-E6-E5-2A-6B-5A-6B-75-57-54-21-CF-8Fandroid-support-multidex.jar
         obj\Debug\android\bin\desugared\DF-CE-93-F2-0E-90-E6-A7-70-3B-51-88-11-DD-CD-2Ddomain-300.06-SNAPSHOT.jar
         obj\Debug\android\bin\desugared\19-D5-F0-F4-3D-78-93-FC-C9-43-F5-B5-4A-00-AD-3D__reference__reactive-streams-1.0.0.jar
         obj\Debug\android\bin\desugared\10-60-63-20-4B-35-75-2E-2D-11-E0-5D-1D-8E-FA-8A__reference__relinker.jar
         obj\Debug\android\bin\desugared\57-AA-40-5E-AA-41-DD-E4-9C-85-FC-E0-41-C7-F9-57__reference__rxjava-2.1.2.jar
         obj\Debug\android\bin\desugared\FD-70-42-3A-EA-8A-B4-59-60-36-15-EF-BD-D4-F2-9Bclasses.jar
         obj\Debug\android\bin\desugared\2A-7B-42-63-D3-6D-84-71-30-6C-F3-22-08-11-CA-E6classes.jar
         obj\Debug\android\bin\desugared\CF-0C-BF-9D-32-8E-4D-42-BC-7C-E8-D8-BE-B4-4D-E9classes.jar
         obj\Debug\android\bin\desugared\12-60-4C-C5-E0-34-5A-EE-57-A0-6A-E6-FC-4C-D0-73classes.jar
         obj\Debug\android\bin\desugared\43-16-60-E0-50-3D-04-45-33-41-93-B6-C2-14-39-6Dclasses.jar
         obj\Debug\android\bin\desugared\3B-61-87-37-4C-58-0A-5C-E8-3B-C3-68-8D-D1-AA-5Fclasses.jar
         obj\Debug\android\bin\desugared\9C-48-94-B4-DC-79-7E-F6-FD-89-E3-8C-10-77-10-99classes.jar
         obj\Debug\android\bin\desugared\04-5E-10-66-2D-35-4B-A6-DC-30-C2-B4-B4-66-4B-F3classes.jar
         obj\Debug\android\bin\desugared\31-17-D5-8D-76-07-ED-09-CC-59-14-DE-78-4C-38-BBclasses.jar
         obj\Debug\android\bin\desugared\55-B9-E2-70-65-E4-02-3D-B1-4F-84-A5-CB-60-5B-B5classes.jar
         obj\Debug\android\bin\desugared\62-90-F1-87-76-DF-19-A8-9F-6F-B1-F5-7F-8C-5E-1Eclasses.jar
         obj\Debug\android\bin\desugared\F7-D7-E2-2E-12-15-E3-03-2A-07-81-5A-8C-F3-A5-19classes.jar
         obj\Debug\android\bin\desugared\63-E7-7F-E6-43-ED-01-E5-5B-47-18-D1-91-71-5F-F5classes.jar
         obj\Debug\android\bin\desugared\CC-86-6F-29-25-7D-77-D6-10-49-A9-2A-91-F8-48-BCclasses.jar
         obj\Debug\android\bin\desugared\C5-29-A1-37-E8-A8-CA-8B-3E-8C-24-DB-EA-10-93-6Bclasses.jar
         obj\Debug\android\bin\desugared\91-A0-68-0D-33-25-B8-8F-75-13-B3-67-80-27-5F-3Bclasses.jar
     Exception in thread "main" java.lang.TypeNotPresentException: Type io.reactivex.functions.Action not present
     	at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
     	at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63)
     	at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
     	at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
     	at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:399)
     	at org.objectweb.asm.ClassReader.a(Unknown Source)
     	at org.objectweb.asm.ClassReader.b(Unknown Source)
     	at org.objectweb.asm.ClassReader.accept(Unknown Source)
     	at org.objectweb.asm.ClassReader.accept(Unknown Source)
     	at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:401)
     	at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326)
     	at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280)
     	at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:584)
     Caused by: java.lang.ClassNotFoundException: Class io.reactivex.functions.Action not found
     	at com.google.devtools.build.android.desugar.HeaderClassLoader.findClass(HeaderClassLoader.java:53)
     	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     	at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:83)
     	... 12 more
    Errors
        C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2172,3): java.lang.TypeNotPresentException :  Type io.reactivex.functions.Action not present [C:\Users\myuser\Downloads\BindingTest\BindingTest\Sample.Android\Sample.Android.csproj]
    OutputItems
        _DesugaredJars
            obj\Debug\android\bin\desugared\77-62-E1-E3-1A-D6-EA-45-47-2E-9C-5C-61-78-9E-E7mono.android.jar
            obj\Debug\android\bin\desugared\2F-53-0B-D0-E6-E5-2A-6B-5A-6B-75-57-54-21-CF-8Fandroid-support-multidex.jar
            obj\Debug\android\bin\desugared\DF-CE-93-F2-0E-90-E6-A7-70-3B-51-88-11-DD-CD-2Ddomain-300.06-SNAPSHOT.jar
            obj\Debug\android\bin\desugared\19-D5-F0-F4-3D-78-93-FC-C9-43-F5-B5-4A-00-AD-3D__reference__reactive-streams-1.0.0.jar
            obj\Debug\android\bin\desugared\10-60-63-20-4B-35-75-2E-2D-11-E0-5D-1D-8E-FA-8A__reference__relinker.jar
            obj\Debug\android\bin\desugared\57-AA-40-5E-AA-41-DD-E4-9C-85-FC-E0-41-C7-F9-57__reference__rxjava-2.1.2.jar
            obj\Debug\android\bin\desugared\FD-70-42-3A-EA-8A-B4-59-60-36-15-EF-BD-D4-F2-9Bclasses.jar
            obj\Debug\android\bin\desugared\2A-7B-42-63-D3-6D-84-71-30-6C-F3-22-08-11-CA-E6classes.jar
            obj\Debug\android\bin\desugared\CF-0C-BF-9D-32-8E-4D-42-BC-7C-E8-D8-BE-B4-4D-E9classes.jar
            obj\Debug\android\bin\desugared\12-60-4C-C5-E0-34-5A-EE-57-A0-6A-E6-FC-4C-D0-73classes.jar
            obj\Debug\android\bin\desugared\43-16-60-E0-50-3D-04-45-33-41-93-B6-C2-14-39-6Dclasses.jar
            obj\Debug\android\bin\desugared\3B-61-87-37-4C-58-0A-5C-E8-3B-C3-68-8D-D1-AA-5Fclasses.jar
            obj\Debug\android\bin\desugared\9C-48-94-B4-DC-79-7E-F6-FD-89-E3-8C-10-77-10-99classes.jar
            obj\Debug\android\bin\desugared\04-5E-10-66-2D-35-4B-A6-DC-30-C2-B4-B4-66-4B-F3classes.jar
            obj\Debug\android\bin\desugared\31-17-D5-8D-76-07-ED-09-CC-59-14-DE-78-4C-38-BBclasses.jar
            obj\Debug\android\bin\desugared\55-B9-E2-70-65-E4-02-3D-B1-4F-84-A5-CB-60-5B-B5classes.jar
            obj\Debug\android\bin\desugared\62-90-F1-87-76-DF-19-A8-9F-6F-B1-F5-7F-8C-5E-1Eclasses.jar
            obj\Debug\android\bin\desugared\F7-D7-E2-2E-12-15-E3-03-2A-07-81-5A-8C-F3-A5-19classes.jar
            obj\Debug\android\bin\desugared\63-E7-7F-E6-43-ED-01-E5-5B-47-18-D1-91-71-5F-F5classes.jar
            obj\Debug\android\bin\desugared\CC-86-6F-29-25-7D-77-D6-10-49-A9-2A-91-F8-48-BCclasses.jar
            obj\Debug\android\bin\desugared\C5-29-A1-37-E8-A8-CA-8B-3E-8C-24-DB-EA-10-93-6Bclasses.jar
            obj\Debug\android\bin\desugared\91-A0-68-0D-33-25-B8-8F-75-13-B3-67-80-27-5F-3Bclasses.jar

When I decompile obj\Debug\lp\1\jl\__reference__rxjava-2.1.2.jar, it appears to have the class it's complaining about:
image

@atsushieno do you see anything here?

@atsushieno
Copy link
Contributor

Those Java libraries are included in the project as EmbeddedReferenceJar, which is wrong. If they have to be packaged in the apk, they have to be EmbeddedJar (for *.jar) and LibraryProjectZip (for *.aar) for each.

@atsushieno
Copy link
Contributor

I was trying to get it working, with the command like:

/usr/bin/java -Xmx2G -jar /devel/lib/xamarin.android/xbuild/Xamarin/Android/desugar_deploy.jar --bootclasspath_entry /home/atsushi/android-sdk-linux/platforms/android-27/android.jar --min_sdk_version 21 --input obj/Debug/android/bin/classes --output obj/Debug/android/bin/desugared/__app_classes__.jar --input /devel/lib/mono/xbuild-frameworks/MonoAndroid/v8.1/mono.android.jar --output obj/Debug/android/bin/desugared/1E-8B-99-7F-0F-D2-0E-E8-39-96-9C-83-1B-18-2C-BAmono.android.jar --input /devel/lib/xamarin.android/xbuild/Xamarin/Android/android-support-multidex.jar --output obj/Debug/android/bin/desugared/63-95-DA-C7-A0-FE-20-EB-AC-91-52-FE-AA-8E-1F-F6android-support-multidex.jar --input obj/Debug/lp/1/jl/__reference__reactive-streams-1.0.0.jar --output obj/Debug/android/bin/desugared/0C-CE-28-D3-EB-DC-7D-6D-24-AC-3E-17-44-3F-30-28__reference__reactive-streams-1.0.0.jar --input obj/Debug/lp/1/jl/__reference__relinker.jar --output obj/Debug/android/bin/desugared/53-2C-24-F2-36-B6-66-5A-F8-BA-E4-B0-08-F5-E2-22__reference__relinker.jar --input obj/Debug/lp/1/jl/__reference__rxjava-2.1.2.jar --output obj/Debug/android/bin/desugared/FC-94-20-F0-B4-73-7E-C4-35-86-DC-42-C2-BB-71-CA__reference__rxjava-2.1.2.jar --input obj/Debug/lp/1/jl/domain-300.06-SNAPSHOT.jar --output obj/Debug/android/bin/desugared/82-24-AA-F0-54-D8-2B-4D-2A-71-0B-A1-16-FC-80-FCdomain-300.06-SNAPSHOT.jar

but even desugar_deploy.jar built from https://github.com/bazelbuild/bazel/tree/master/src/tools/android/java/com/google/devtools/build/android/desugar (build instruction can be found at https://github.com/webrtc-uwp/chromium-third_party/tree/master/bazel/desugar) results in the same.

Removing the last two options make it pass, which means desugar fails to resolve those types in rxjava2 jars.

At this state I can only think of issues in desugar itself.

@eclipsed4utoo
Copy link
Author

@atsushieno Does this mean I need to report an issue with bazel instead?

Thanks for looking into the issue.

@erikpowa
Copy link
Contributor

erikpowa commented Sep 5, 2018

@atsushieno it's XA sided bug see

@atsushieno
Copy link
Contributor

(I believe either @jonathanpeppers or @dellis1972 works on those kind of issues nowadays after I left the team.)

@gmoney494
Copy link

@jonathanpeppers @atsushieno
I also have a similar issue but with a different class in the io.reactivex namespace. However, i ingest via the nuget package by Naxam. This suffices my dependency requirement for the native Aar im trying to bind.

Any easy solution or workaround for the time being or do i have to wait for a new release?

jonathanpeppers pushed a commit that referenced this issue Sep 21, 2018
Fixes: #2143
Context: #1639

Xamarin.Android's current implementation of desugar runs a command
such as:

    java -jar desugar_deploy.jar 
        --bootclasspath_entry ~\android-toolchain\sdk\platforms\android-28\android.jar 
        --min_sdk_version 11 
        --classpath_entry xamarin-android\bin\Debug\lib\xamarin.android\xbuild-frameworks\MonoAndroid\v9.0\mono.android.jar 
        --input Lambda.jar 
        --output obj\Debug\android\bin\desugared\14-57-25-90-94-EE-16-09-B8-68-88-BC-9D-FC-6C-89Lambda.jar

However, certain jars are failing with messages such as:

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

Or another example:

    Error: java.lang.TypeNotPresentException : Type io.reactivex.functions.Action not present

The first fix here is to add the `--classpath_entry` flag for every
`--input`, for some reason `Desugar` is not treating `--input` jars as
classpath entries?

Next, we expanded on the `BuildTest.Desugar` test using a complicated
set of Java libraries from Maven central:

    proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okio-1.13.0.jar") {
        WebContent = "http://central.maven.org/maven2/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar"
    });
    proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okhttp-3.8.0.jar") {
        WebContent = "http://central.maven.org/maven2/com/squareup/okhttp3/okhttp/3.8.0/okhttp-3.8.0.jar"
    });
    proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "retrofit-2.3.0.jar") {
        WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/retrofit/2.3.0/retrofit-2.3.0.jar"
    });
    proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "converter-gson-2.3.0.jar") {
        WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/converter-gson/2.3.0/converter-gson-2.3.0.jar"
    });
    proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "gson-2.7.jar") {
        WebContent = "http://central.maven.org/maven2/com/google/code/gson/gson/2.7/gson-2.7.jar"
    });
    proj.OtherBuildItems.Add (new BuildItem ("AndroidAarLibrary", "twitter-core-3.3.0.aar") {
        WebContent = "http://repo.spring.io/libs-release/com/twitter/sdk/android/twitter-core/3.3.0/twitter-core-3.3.0.aar",
    });

This was working, as long as you had `android:minSdkVersion="24"` in
your `AndroidManifest.xml`. This wasn't ideal if you wanted to run
your app on older API levels...

Luckily, another command line switched solved this problem:

    //Added to the Desugar MSBuild task
    if (minApiVersion < 24) {
        cmd.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes ");
    }

What a crazy name for a flag! Documented by `desugar` as:

    --[no]desugar_try_with_resources_omit_runtime_classes (a boolean; default: "false")
        Omits the runtime classes necessary to support try-with-resources from the
        output. This property has effect only if --
        desugar_try_with_resources_if_needed is used.
    --min_sdk_version (an integer; default: "1")
        Minimum targeted sdk version.  If >= 24, enables default methods in
        interfaces.

This makes sense that something would happen at API level 24...

Once doing this, the `Desugar` test passes without modifying
`minSdkVersion`.

The expanded `Desugar` test will also greatly help with our D8/R8
implementation
(#2040).

This complex set of Java dependencies from Maven will be useful.
@sgong-pdftron
Copy link

Any update on this issue? Or workaround?

@jonathanpeppers
Copy link
Member

I retested this with VS 2019 16.1.1. I had to update Plugin.CurrentActivity to latest, not sure why.

It looks like d8/r8 can handle the desugaring just fine now:

> msbuild BindingTest.sln /p:AndroidDexTool=d8

image

You can add <AndroidDexTool>d8</AndroidDexTool> to your .csproj file.

@eclipsed4utoo closing this for now. Let us know if d8 solves the problem for you!

@ghost ghost locked as resolved and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants