Skip to content

Commit a7ff02b

Browse files
committed
Come up with an alternate way for java-interop.jar path detection
Context: https://xamarinhq.slack.com/archives/C03CEGRUW/p1568076852178100 Using `$(MSBuildExtensionsPath)` didn't work, as it just took the "first" path, which isn't valid, resulting in attempts to use: /Library/Frameworks/Mono.framework/Versions/6.0.0/lib/mono/xbuild/Xamarin/Android/java-interop.jar which does not exist.
1 parent 7e377dc commit a7ff02b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

build-tools/scripts/Jar.targets

+14-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,20 @@
1111
<JavaCPath Condition=" '$(JavaCPath)' == '' ">$(JavaSdkDirectory)\bin\javac</JavaCPath>
1212
</PropertyGroup>
1313
</Target>
14+
<Target Name="_GetJavaInteropJarPath">
15+
<PropertyGroup>
16+
<_JIJar_InTree>$([System.IO.Path]::GetFullPath ('$(XAInstallPrefix)'))\xbuild\Xamarin\Android\java-interop.jar</_JIJar_InTree>
17+
<_JIJar_System Condition=" '$(_XamarinAndroidMSBuildDirectory)' != '' ">$(_XamarinAndroidMSBuildDirectory)\java-interop.jar</_JIJar_System>
18+
<_JavaInteropJarPath Condition=" Exists($(_JIJar_InTree)) ">$(_JIJar_InTree)</_JavaInteropJarPath>
19+
<_JavaInteropJarPath Condition=" '$(_JavaInteropJarPath)' == '' ">$(_JIJar_System)</_JavaInteropJarPath>
20+
</PropertyGroup>
21+
<Error
22+
Condition=" '$(_JavaInteropJarPath)' == '' "
23+
Text="Could not determine path to `java-interop.jar`."
24+
/>
25+
</Target>
1426
<Target Name="BuildTestJarFile"
15-
DependsOnTargets="_GetJavacVersions"
27+
DependsOnTargets="_GetJavacVersions;_GetJavaInteropJarPath"
1628
Inputs="@(TestJarEntry)"
1729
Outputs="%(TestJarEntry.OutputFile)">
1830
<ItemGroup>
@@ -26,11 +38,7 @@
2638
<_Targets>-source $(_JavacSourceVersion) -target $(_JavacTargetVersion)</_Targets>
2739
<_DestDir>$(IntermediateOutputPath)__CreateTestJarFile-bin</_DestDir>
2840
<_AndroidJar>-bootclasspath "$(AndroidSdkDirectory)\platforms\android-$(_AndroidApiLevelName)\android.jar"</_AndroidJar>
29-
<_JIJar_InTree>$([System.IO.Path]::GetFullPath ('$(XAInstallPrefix)'))\xbuild\Xamarin\Android\java-interop.jar</_JIJar_InTree>
30-
<_JIJar_System>$(MSBuildExtensionsPath)\Xamarin\Android\java-interop.jar</_JIJar_System>
31-
<_JIJar Condition=" Exists ($(_JIJar_InTree)) ">$(_JIJar_InTree)</_JIJar>
32-
<_JIJar Condition=" '$(_JIJar)' == '' ">$(_JIJar_System)</_JIJar>
33-
<_CP>-cp "$(_JIJar)"</_CP>
41+
<_CP>-cp "$(_JavaInteropJarPath)"</_CP>
3442
</PropertyGroup>
3543
<MakeDir Directories="$(_DestDir)" />
3644
<Exec Command="$(_Javac) $(_Targets) -d &quot;$(_DestDir)&quot; $(_AndroidJar) $(_CP) @(_JavacSource->'&quot;%(Identity)&quot;', ' ')" />

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props.in

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<AndroidSdkToolsVersion Condition="'$(AndroidSdkToolsVersion)' == ''">26.1.1</AndroidSdkToolsVersion>
2020
<AndroidNdkVersion Condition="'$(AndroidNdkVersion)' == ''">16.1</AndroidNdkVersion>
2121
<BundleToolVersion Condition="'$(BundleToolVersion)' == ''">@BUNDLETOOL_VERSION@</BundleToolVersion>
22+
<_XamarinAndroidMSBuildDirectory>$(MSBuildThisFileDirectory)</_XamarinAndroidMSBuildDirectory>
2223

2324
<!-- Enable nuget package conflict resolution -->
2425
<ResolveAssemblyConflicts>true</ResolveAssemblyConflicts>

0 commit comments

Comments
 (0)