Skip to content

Commit efe674f

Browse files
committed
[Xamarin.Android.Build.Tasks] Null Reference Exceoption when getting android.jar
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=60324 If a android.jar file does NOT exist for a target platform we should raise a normal error. But we currently throw a null reference exception. `TryGetPlatformDirectoryFromApiLevel` can return null, this is by design. So we need to handle that in the places where its used. And return a reasonable error message if we do get a null back.
1 parent 6687dac commit efe674f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public override bool Execute ()
6969
}
7070

7171
platform = GetTargetSdkVersion (platform, target_sdk);
72-
JavaPlatformJarPath = Path.Combine (MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions), "android.jar");
72+
var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions);
73+
JavaPlatformJarPath = Path.Combine (platformPath ?? MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform), "android.jar");
7374

7475
if (!File.Exists (JavaPlatformJarPath)) {
7576
Log.LogError ("Could not find android.jar for API Level {0}. " +

src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public override bool Execute ()
6868
}
6969

7070
// Ensure that the user has the platform they are targeting installed
71-
var jarpath = Path.Combine (MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (AndroidApiLevel, MonoAndroidHelper.SupportedVersions), "android.jar");
71+
var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (AndroidApiLevel, MonoAndroidHelper.SupportedVersions);
72+
var jarpath = Path.Combine (platformPath ?? MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (AndroidApiLevel), "android.jar");
7273

7374
if (!File.Exists (jarpath)) {
7475
Log.LogError ("Could not find android.jar for API Level {0}. This means the Android SDK platform for API Level {0} is not installed. Either install it in the Android SDK Manager, or change your Android Bindings project to target an API version that is installed. ({1} missing.)", AndroidApiLevel, jarpath);

0 commit comments

Comments
 (0)