Skip to content

Commit fb6222b

Browse files
committed
Use AndroidSdkResolver.GetJavaSdkPath () to get Jdk Path
Context: https://dev.azure.com/devdiv/DevDiv/_build/results?buildId=4518058&view=logs&j=8100f0f7-e86c-5b6e-6a78-6808e1478ee9&t=b2ff00a9-cb72-5405-b714-ea139eccf107&l=482 Failed CheckSignApk(True,False) [27 ms] Error Message: System.InvalidOperationException : Could not determine Java SDK location. Please provide `javaSdkPath`. Stack Trace: at Xamarin.Android.Tools.AndroidSdkInfo..ctor(Action`2 logger, String androidSdkPath, String androidNdkPath, String javaSdkPath) in /agent/_work/1/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs:line 25 at Xamarin.Android.Build.Tests.PackagingTest.CheckSignApk(Boolean useApkSigner, Boolean perAbiApk) in /agent/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs:line 366 The new Ubuntu test machines do not have JAVA_HOME set (or any other fallback mechanism for locating the JDK). When creating a new instance of AndroidSdkInfo we should pass the JDK value used by the tests. In other cases, we can avoid creating an AndroidSdkInfo object entirely as it was only being used to get a JDK path.
1 parent 8ea42ea commit fb6222b

File tree

9 files changed

+19
-22
lines changed

9 files changed

+19
-22
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:pack-linux@ecfa7c781965d3fd4ea0b91c19f56a004a809a50
1+
xamarin/monodroid:main@ea2f34ad3acd4b32487fd55bb663d76d85774b1a
22
mono/mono:2020-02@c66141a8c7ba2566c578c2dd012b2b723e006213

build-tools/automation/azure-pipelines.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ stages:
451451
parameters:
452452
version: $(DotNetCoreVersion)
453453

454+
- task: NuGetAuthenticate@0
455+
displayName: authenticate with azure artifacts
456+
inputs:
457+
forceReinstallCredentialProvider: true
458+
454459
- script: >
455460
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF &&
456461
echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list &&
@@ -462,11 +467,6 @@ stages:
462467
inputs:
463468
versionSpec: 5.x
464469

465-
- task: NuGetAuthenticate@0
466-
displayName: authenticate with azure artifacts
467-
inputs:
468-
forceReinstallCredentialProvider: true
469-
470470
- script: make prepare-external-git-dependencies PREPARE_CI=1 CONFIGURATION=$(XA.Build.Configuration)
471471
workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-android
472472
displayName: make prepare-external-git-dependencies
@@ -498,6 +498,10 @@ stages:
498498
artifactName: nupkg-linux
499499
targetPath: $(System.DefaultWorkingDirectory)/xamarin-android/bin/Build$(XA.Build.Configuration)/nupkg-linux
500500

501+
- script: dotnet tool update apkdiff -g
502+
displayName: install apkdiff dotnet tool
503+
continueOnError: true
504+
501505
- template: yaml-templates/run-nunit-tests.yaml
502506
parameters:
503507
useDotNet: true

src/Xamarin.Android.Build.Tasks/Microsoft.NET.Workload.Android/WorkloadManifest.in.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"kind": "sdk",
1717
"version": "@SDK_PACK_VERSION@",
1818
"alias-to": {
19-
"linux-x64": "Microsoft.Android.Sdk.linux-x64",
2019
"osx-x64": "Microsoft.Android.Sdk.osx-x64",
2120
"win-x64": "Microsoft.Android.Sdk.win-x64",
2221
"linux-x64": "Microsoft.Android.Sdk.linux-x64"

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner, [Values(true,
361361
string keyfile = Path.Combine (Root, "temp", TestName, "release.keystore");
362362
if (File.Exists (keyfile))
363363
File.Delete (keyfile);
364-
var androidSdk = new AndroidSdkInfo ((level, message) => {
365-
}, AndroidSdkPath, AndroidNdkPath);
366-
string keyToolPath = Path.Combine (androidSdk.JavaSdkPath, "bin");
364+
string keyToolPath = Path.Combine (AndroidSdkResolver.GetJavaSdkPath (), "bin");
367365
var engine = new MockBuildEngine (Console.Out);
368366
string pass = "Cy(nBW~j.&@B-!R_aq7/syzFR!S$4]7R%i6)R!";
369367
string alias = "release store";

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/KeyToolTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public void Setup()
2626
{
2727
engine = new MockBuildEngine (TestContext.Out, errors = new List<BuildErrorEventArgs> (), warnings = new List<BuildWarningEventArgs> (), messages = new List<BuildMessageEventArgs> ());
2828
temp = Path.GetTempFileName ();
29-
30-
var androidSdk = new AndroidSdkInfo ((level, message) => {
31-
if (level == TraceLevel.Error)
32-
Assert.Fail (message);
33-
}, AndroidSdkPath, AndroidNdkPath);
34-
keyToolPath = Path.Combine (androidSdk.JavaSdkPath, "bin");
29+
keyToolPath = Path.Combine (AndroidSdkResolver.GetJavaSdkPath (), "bin");
3530
}
3631

3732
[TearDown]

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/NdkUtilTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void TestNdkUtil ()
3333
using (var builder = new Builder ()) {
3434
var ndkDir = AndroidNdkPath;
3535
var sdkDir = AndroidSdkPath;
36-
MonoAndroidHelper.AndroidSdk = new AndroidSdkInfo ((arg1, arg2) => { }, sdkDir, ndkDir);
36+
MonoAndroidHelper.AndroidSdk = new AndroidSdkInfo ((arg1, arg2) => { }, sdkDir, ndkDir, AndroidSdkResolver.GetJavaSdkPath ());
3737
NdkUtil.Init (log, ndkDir);
3838
var platforms = NdkUtil.GetSupportedPlatforms (log, ndkDir);
3939
Assert.AreNotEqual (0, platforms.Count (), "No platforms found");

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/EnvironmentHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using NUnit.Framework;
1010
using Xamarin.Android.Tasks;
1111
using Xamarin.Android.Tools;
12+
using Xamarin.ProjectTools;
1213

1314
namespace Xamarin.Android.Build.Tests
1415
{
@@ -339,7 +340,7 @@ public static List<string> GatherEnvironmentFiles (string outputDirectoryRoot, s
339340
public static void AssertValidEnvironmentSharedLibrary (string outputDirectoryRoot, string sdkDirectory, string ndkDirectory, string supportedAbis)
340341
{
341342
NdkUtil.Init (ndkDirectory);
342-
MonoAndroidHelper.AndroidSdk = new AndroidSdkInfo ((arg1, arg2) => {}, sdkDirectory, ndkDirectory);
343+
MonoAndroidHelper.AndroidSdk = new AndroidSdkInfo ((arg1, arg2) => {}, sdkDirectory, ndkDirectory, AndroidSdkResolver.GetJavaSdkPath ());
343344

344345
AndroidTargetArch arch;
345346

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/JarContentBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public JarContentBuilder ()
3232

3333
var sdkPath = AndroidSdkResolver.GetAndroidSdkPath ();
3434
var ndkPath = AndroidSdkResolver.GetAndroidNdkPath ();
35-
var androidSdk = new AndroidSdkInfo (logger, androidSdkPath: sdkPath, androidNdkPath: ndkPath);
36-
JavacFullPath = Path.Combine (androidSdk.JavaSdkPath, "bin", "javac");
37-
JarFullPath = Path.Combine (androidSdk.JavaSdkPath, "bin", "jar");
35+
var jdkPath = AndroidSdkResolver.GetJavaSdkPath ();
36+
JavacFullPath = Path.Combine (jdkPath, "bin", "javac");
37+
JarFullPath = Path.Combine (jdkPath, "bin", "jar");
3838
}
3939

4040
public override byte [] Build ()

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Utilities/DexUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static void DexDump (DataReceivedEventHandler handler, string dexFile, string an
110110
if (l == TraceLevel.Error) {
111111
throw new Exception (m);
112112
}
113-
}, androidSdkDirectory);
113+
}, androidSdkDirectory, javaSdkPath: AndroidSdkResolver.GetJavaSdkPath ());
114114
var buildToolsPath = androidSdk.GetBuildToolsPaths ().FirstOrDefault ();
115115
if (string.IsNullOrEmpty (buildToolsPath)) {
116116
throw new Exception ($"Unable to find build-tools in `{androidSdkDirectory}`!");

0 commit comments

Comments
 (0)