Java绑定项目中的Xamarin.Android是否可以使用Java 8功能? [英] Is Java 8 features available for Xamarin.Android in Java binding project?

查看:103
本文介绍了Java绑定项目中的Xamarin.Android是否可以使用Java 8功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Java 8功能的android库项目,即通过

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
}

将输出AAR绑定到Xamarin.Android时,绑定项目可以正常编译.但是,当尝试在Xamarin.Android应用程序项目中使用绑定项目时,出现以下错误:

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 ==========

通过一些谷歌搜索,它似乎与Java 8功能有关.我确实在本机android库中使用了许多Java 8新功能.Xamarin.Android尚不支持此功能吗?

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?

我确实检查了Xamarin Diagnostics的输出,表明它正在使用Java 8进行编译:

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.

推荐答案

使用最新的Visual Studio 2019 Preview 2.2并将< AndroidDexTool> d8</AndroidDexTool> 添加到android项目的csproj中,用于每个Debug/Release版本

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是Google制造的新dexer,默认情况下它启用Desugar模式.

D8 is the new dexer made by google and it enable Desugar mode by default.

这篇关于Java绑定项目中的Xamarin.Android是否可以使用Java 8功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆