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

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

问题描述

我有一个使用 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 Studio2017ProfessionalMSBuildXamarinAndroidXamarin.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 诊断输出,这表明它使用 Java 8 进行编译:

I did check my Xamarin Diagnostics output, which shows it is using Java 8 to compile:

[I:sdk]:                    Key HKCUSOFTWAREXamarinVisualStudio15.0_8541cfceAndroidJavaSdkDirectory found:
    Path contains jarsigner.exe in in (C:Program FilesJavajdk1.8.0_161).

非常感谢任何帮助!谢谢.

Any help is highly appreciated! Thanks.

推荐答案

使用最新的 Visual Studio 2019 Preview 2.2 并将 <AndroidDexTool>d8</AndroidDexTool> 添加到您的 android 项目的 csproj 中, 每个调试/发布版本一个

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 是谷歌新推出的 dexer,默认开启 Desugar 模式.

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

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

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