首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java绑定项目中的Xamarin.Android可以使用Java 8特性吗?

Java绑定项目中的Xamarin.Android可以使用Java 8特性吗?
EN

Stack Overflow用户
提问于 2018-01-31 00:23:05
回答 1查看 1.7K关注 0票数 5

我有一个android库项目,它使用Java 8特性,即

代码语言:javascript
复制
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

当将输出AAR绑定到Xamarin.Android时,绑定项目编译得很好。但是,当试图在Xamarin.Android应用程序项目中使用绑定项目时,我会得到以下错误:

代码语言:javascript
复制
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上还不支持吗?

我确实检查了我的Xamarin诊断输出,它显示它正在使用Java 8编译:

代码语言:javascript
复制
[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).

任何帮助都是非常感谢的!谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-11 16:29:55

使用最新的VisualStudio2019预览2.2,并将<AndroidDexTool>d8</AndroidDexTool>添加到android项目的csproj中,每个调试/发布版本构建一个

D8是谷歌新推出的dexer,它默认启用Desugar模式。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48532610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档