Reputation: 372
I have an android library project that uses Java 8 features, i.e. via
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
When binding the output AAR to Xamarin.Android, the binding project compiles fine. However, when trying to use the binding project in a Xamarin.Android application project, I am getting the following error:
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2>COMPILETODALVIK : Uncaught translation error : com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
2> java.lang.RuntimeException: Translation has been interrupted
2> at com.android.dx.command.dexer.Main.processAllFiles(Main.java:615)
2> at com.android.dx.command.dexer.Main.runMultiDex(Main.java:368)
2> at com.android.dx.command.dexer.Main.runDx(Main.java:289)
2> at com.android.dx.command.dexer.Main.main(Main.java:247)
2> at com.android.dx.command.Main.main(Main.java:94)
2> Caused by: java.lang.InterruptedException: Too many errors
2> at com.android.dx.command.dexer.Main.processAllFiles(Main.java:607)
2> ... 4 more
2>D:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2096,3): error : java.lang.RuntimeException : Translation has been interrupted
========== Build: 1 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
With some googling, it seems to be related to Java 8 feature. I do use a number of new Java 8 features in the native android library. Is this not supported on Xamarin.Android yet?
I did check my Xamarin Diagnostics output, which shows it is using Java 8 to compile:
[I:sdk]: Key HKCU\SOFTWARE\Xamarin\VisualStudio\15.0_8541cfce\Android\JavaSdkDirectory found:
Path contains jarsigner.exe in \bin (C:\Program Files\Java\jdk1.8.0_161).
Any help is highly appreciated! Thanks.
Upvotes: 5
Views: 1747
Reputation: 717
Use the latest Visual Studio 2019 Preview 2.2 and add <AndroidDexTool>d8</AndroidDexTool>
into the csproj of your android project, one for each Debug/Release build
D8 is the new dexer made by google and it enable Desugar mode by default.
Upvotes: 3