Compilation error while while binding aar library with java 8 (jdk 1.8.0)

Hi, first post on the forum and I am quite new to Xamarin

I am trying to create a binding for an .aar package and currently I an hitting my head against the brick wall.

I have managed to get the binding project to compile and with out errors, but when I try to use the binding project the broject that is to use the bindings do not compile and it is generating some strange error messages that I can not figure out after traversing the xamarin forum and fambeling around on google.

What I have been doing so far:
1. Set up a binding project.
2. Included tha .aar file and other .jar dependencies.
3. Set the build action for the .aar and .jar to LibraryProjectZip and EmbeddedReferenceJar respectively.
4. Built the project (Everything OK except from some warnings, that acording to the internett should be fine)
5. Included the binding project into an ampty android project and compiled
6. This resultet in a the following error:

With desuggar disabled:

>COMPILETODALVIK : PARSE error : 
2>  InvokeDynamic not supported
2>  ...while preparsing cst 0041 at offset 0000012c
2>  ...while parsing com/movesense/mds/internal/connectivity/BleManager.class
2>  1 error; aborting
2>
2>Build FAILED.
  1. After searching around found out that I might need to desugar the project adding the desuggaring in the bining project did not seem to have any effect so I added it to the android project instead and got another error (see The longer error message below).

With desugar enabled:

_CompileToDalvikWithDx:
2>  C:\Program Files\Java\jdk1.8.0_144\\bin\java.exe -Xmx1G -jar "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\desugar_deploy.jar" --bootclasspath_entry C:\android-sdk\platforms\android-27\android.jar --min_sdk_version 26 --input obj\\Debug\MonoAndroid81\android\bin\classes --output obj\\Debug\MonoAndroid81\android\bin\desugared\__app_classes__.jar --input "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.1\mono.android.jar" --output obj\\Debug\MonoAndroid81\android\bin\desugared\A5-58-5A-79-3B-AC-78-58-0A-63-E8-BE-BE-29-95-DEmono.android.jar --input obj\\Debug\MonoAndroid81\lp\0\jl\__reference__rxandroidble-1.3.4.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\9A-2F-35-3C-38-11-CC-A3-D8-A7-1C-07-19-89-02-6B__reference__rxandroidble-1.3.4.jar --input obj\\Debug\MonoAndroid81\lp\0\jl\__reference__rxjava-1.3.3.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\45-E9-A6-BA-7B-7D-75-7C-28-4A-EB-00-1C-01-94-AE__reference__rxjava-1.3.3.jar --input obj\\Debug\MonoAndroid81\lp\0\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\46-B9-ED-38-7B-09-21-BF-CD-48-33-C8-13-BB-D3-04classes.jar --input obj\\Debug\MonoAndroid81\lp\10\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\DE-45-41-3C-A3-F8-4B-52-80-BF-0E-45-50-BC-AC-27classes.jar --input obj\\Debug\MonoAndroid81\lp\11\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\9B-1A-D3-32-26-95-C4-66-D6-86-11-1E-A3-E7-16-F4classes.jar --input obj\\Debug\MonoAndroid81\lp\12\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\34-04-27-AE-DB-CD-60-74-2A-DA-54-0D-AF-08-8D-C4classes.jar --input obj\\Debug\MonoAndroid81\lp\13\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\42-34-49-C3-FE-C0-6D-E8-92-12-4A-D4-B5-E3-04-64classes.jar --input obj\\Debug\MonoAndroid81\lp\14\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\0B-5D-38-99-73-87-AA-E4-97-C7-02-C5-7C-2E-A5-7Cclasses.jar --input obj\\Debug\MonoAndroid81\lp\15\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\F0-C6-38-C8-5B-6B-35-E6-61-65-4C-21-98-C9-DD-15classes.jar --input obj\\Debug\MonoAndroid81\lp\16\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\72-4F-8A-B8-0E-5E-59-E8-52-7A-A7-36-9D-6B-6E-71classes.jar --input obj\\Debug\MonoAndroid81\lp\17\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\BC-9B-31-B0-B4-46-6A-88-F4-F8-57-91-D2-C6-64-D4classes.jar --input obj\\Debug\MonoAndroid81\lp\3\jl\arch-core-common.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\41-C6-A9-36-86-56-64-6B-57-7C-F8-DB-F1-7A-DA-77arch-core-common.jar --input obj\\Debug\MonoAndroid81\lp\4\jl\arch-lifecycle-common.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\C8-75-E2-F1-4B-B6-7D-C8-27-10-82-5E-D4-49-E2-1Farch-lifecycle-common.jar --input obj\\Debug\MonoAndroid81\lp\5\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\C7-78-59-5A-85-54-4A-61-C0-B9-51-B8-AB-C6-FD-6Bclasses.jar --input obj\\Debug\MonoAndroid81\lp\6\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\6D-64-24-C5-71-D4-42-AE-01-1E-85-07-32-C6-93-84classes.jar --input obj\\Debug\MonoAndroid81\lp\8\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\C6-C8-DA-D5-67-B5-FA-9D-A0-C9-99-2B-71-F1-6B-73classes.jar --input obj\\Debug\MonoAndroid81\lp\9\jl\bin\classes.jar --output obj\\Debug\MonoAndroid81\android\bin\desugared\39-EE-EC-9A-30-86-CE-DE-F6-6D-D1-75-26-24-78-B2classes.jar 
2>  Exception in thread "main" java.lang.TypeNotPresentException: Type rx.functions.Func1 not present
2>      at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:85)
2>      at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:63)
2>      at sun.invoke.util.BytecodeDescriptor.parseMethod(BytecodeDescriptor.java:41)
2>      at java.lang.invoke.MethodType.fromMethodDescriptorString(MethodType.java:1067)
2>      at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:399)
2>      at org.objectweb.asm.ClassReader.a(Unknown Source)
2>      at org.objectweb.asm.ClassReader.b(Unknown Source)
2>      at org.objectweb.asm.ClassReader.accept(Unknown Source)
2>      at org.objectweb.asm.ClassReader.accept(Unknown Source)
2>      at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:401)
2>      at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326)
2>      at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280)
2>      at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:584)
2>  Caused by: java.lang.ClassNotFoundException: Class rx.functions.Func1 not found
2>      at com.google.devtools.build.android.desugar.HeaderClassLoader.findClass(HeaderClassLoader.java:53)
2>      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
2>      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
2>      at sun.invoke.util.BytecodeDescriptor.parseSig(BytecodeDescriptor.java:83)
2>      ... 12 more
  1. This is the place where I am currently stuck.

I'm 99% shure that the "missing" function that visual studio is complaining about is pressent, as it is in the dependency .jar and doing some java decompiling shows that it is infact there.

After a long time of debugging this, I think there is something wrong with how Xamarin is desugaring the project, could this be true? Or more possible have I done something stupid?

I will upload my project to github shortly so that it is easier to reproduce on your machine.

Any help moving this forward would be greatly apriciated.

My system is as follows:

Microsoft Visual Studio Community 2017 
Version 15.8.8
VisualStudio.15.Release/15.8.8+28010.2048
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Community

Visual C++ 2017   00369-60000-00001-AA548
Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package   8.13.10627.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.8.05085.0
ASP.NET and Web Tools 2017

C# Tools   2.9.0-beta8-63208-01
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.1.49 (remotes/origin/[email protected])
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

MLGen Package Extension   1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio   4.11.11-pre (8fb558f)
Support for debugging Mono processes with Visual Studio.

Multilingual App Toolkit   4.0
Multilingual App Toolkit helps you localize your Windows Store app by providing file management, pseudo and machine translation, translation editor, and build integration. http:[//]aka.ms/matinstall

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http:[//]docs.nuget.org/.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools   15.8.20822.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   2.9.0-beta8-63208-01
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5   15.8.0.0.  Commit Hash: 55a3dc3231c95c77f81ee53f7d29152029da7408.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Universal Windows Apps   15.0.28010.2046
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   4.11.0.776 ([email protected])
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.15.9 (d000f568b)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   1.1.116 (9619170)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   9.0.0.19 (HEAD/a8a3b0ec7)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   12.0.0.15 (84552a4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Answers

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai

    @MortenL

    Which .AAR package are you using? Could you share it?
    Have you read the following tutorial?
    https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar

  • MortenLMortenL Member ✭✭

    @BillyLiu Thank you for the reply

    Yes the package is this one
    https:[//]bitbucket.org/suunto/movesense-mobile-lib/src/master/android/Movesense/

    Yes, I have followed that guide to no avail.

    I think there might be something wrong with how Xamarin.Android desugars java 8 features to Java 7.

    And that the latest build from here:
    https:[//]jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-builds-master/

    Might solve the problem.

    I have also tried to bind the following project by first creating a .aar file and then bind it with the same result. The solution that time was to add:

    compileOptions{
    
       sourceCompatibility JavaVersion.VERSION_1_7
    
       targetCompatibility JavaVersion.VERSION_1_7
    
    }
    

    To the gradle.build file before exporting to .aar

Sign In or Register to comment.