当从命令行MSBUILD调用时,Xamarin将Java版本调整为1.7

时间:2016-11-23 08:52:27

标签: xamarin msbuild

我在Visual Studio中设置了JDK 1.8 Path,我可以编译Android 7.0。申请没有任何问题。 enter image description here

为了自动构建签名的APK,我还有一个PS1脚本,它应该使用命令行MSBUILD编译同一个应用程序。我将JAVA_HOME,JDK_HOME设置为JDK 1.8。但是MSBUILD仍然使用JDK 1.7。我收到错误“不支持的类版本号52 ......”

从命令行调用MSBUILD时,有没有办法设置JDK位置?

更令人困惑的是,这台机器上的默认Java版本是1.8(如果我输入java -version,我得到JDK 1.8.0_111。)

更新 当使用详细登录执行构建时,我可以确认Xamarin看到JDK 1.8

ResolveSdksTask Outputs:
    AndroidApiLevel: 25
    AndroidApiLevelName: 25
    AndroidNdkPath: D:\Users\milan\Documents\Android\ndk\android-ndk-r10e
    AndroidSdkBuildToolsPath: D:\Utilities\android-sdk\build-tools\25.0.0
    AndroidSdkBuildToolsBinPath: D:\Utilities\android-sdk\build-tools\25.0.0
    AndroidSdkPath: D:\Utilities\android-sdk
    JavaSdkPath: C:\Program Files\Java\jdk1.8.0_111
    MonoAndroidBinPath: C:\Program Files (x86)\MSBuild\Xamarin\Android
    MonoAndroidToolsPath: C:\Program Files (x86)\MSBuild\Xamarin\Android
    MonoAndroidIncludePath: 
    TargetFrameworkVersion: v7.0
    ZipAlignPath: D:\Utilities\android-sdk\build-tools\25.0.0
    SupportedApiLevel: 24
    AndroidSequencePointsMode: None
   Found Android SDK. API levels: 10, 15, 19, 21, 22, 23, 24

但后来在任务“AdjustJavacVersionArguments”中将Javac版本更改为1.7:

Task "AdjustJavacVersionArguments"
  ToolPath: C:\Program Files\Java\jdk1.8.0_111\\bin
  ToolExe: javac.exe
  EnableProguard: False
  EnableMultiDex: True
  Javac TargetVersion adjusted to: 1.7
  Javac SourceVersion adjusted to: 1.7
Done executing task "AdjustJavacVersionArguments".

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

这看起来像是一系列问题。

1)由于API 24(Android 7.0)不支持JDK 1.7,Multidex无法创建主列表。

$_COOKIE

还相关:Xamarin.Android Proguard - Unsupported class version number 52.0

2)CREATEMULTIDEXMAINDEXCLASSLIST : error : Can't read [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\mono.android.jar] (Can't process class [android/app/ActivityTracker.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7))) [D:\src\anqueto\trunk\que\mikonboard.que.androidClient\mikonboard.que.androidClient.csproj] 正在调整到JDK 1.7(因此你仍然安装了它)。

这是反编译的任务:

javac

它在这些行上看起来似乎没有 public class AdjustJavacVersionArguments : ToolTask { [Required] public new string ToolPath { get; set; } public bool EnableProguard { get; set; } public bool EnableMultiDex { get; set; } [Output] public string TargetVersion { get; set; } [Output] public string SourceVersion { get; set; } protected override string ToolName { get { return !OS.IsWindows ? "javac" : "javac.exe"; } } public override bool Execute() { this.Log.LogDebugMessage("ToolPath: {0}", (object) this.ToolPath); this.Log.LogDebugMessage("ToolExe: {0}", (object) this.ToolExe); this.Log.LogDebugMessage("EnableProguard: {0}", (object) this.EnableProguard); this.Log.LogDebugMessage("EnableMultiDex: {0}", (object) this.EnableMultiDex); if (!this.EnableProguard && !this.EnableMultiDex) return true; Process process = Process.Start(new ProcessStartInfo(Path.Combine(this.ToolPath, this.ToolExe ?? this.ToolName), "-version") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }); process.WaitForExit(); string str1 = process.StandardError.ReadLine(); if (!str1.StartsWith("javac ") || !str1.Substring(6).StartsWith("1.8")) return true; string str2 = "1.7"; this.SourceVersion = str2; this.TargetVersion = str2; this.Log.LogDebugMessage("Javac TargetVersion adjusted to: {0}", (object) this.TargetVersion); this.Log.LogDebugMessage("Javac SourceVersion adjusted to: {0}", (object) this.SourceVersion); return true; } protected override string GenerateFullPathToTool() { return Path.Combine(this.ToolPath, this.ToolExe); } }

return true;

因此它会调整为string str1 = process.StandardError.ReadLine(); if (!str1.StartsWith("javac ") || !str1.Substring(6).StartsWith("1.8")) return true;

1.7

我想说卸载JDK 1.7可能最简单,只安装了JDK 1.8,看看是否可以解决您的问题。

否则,请尝试确保项目和JDK位于同一驱动器上。您的string str2 = "1.7"; this.SourceVersion = str2; this.TargetVersion = str2; this.Log.LogDebugMessage("Javac TargetVersion adjusted to: {0}", (object) this.TargetVersion); this.Log.LogDebugMessage("Javac SourceVersion adjusted to: {0}", (object) this.SourceVersion); return true; 驱动器上似乎都有点点碎片。我会将所有开发工具保存在一个驱动器上。