Skip to content

Commit

Permalink
[r8] fixes to building with gradle
Browse files Browse the repository at this point in the history
Context: dotnet#2019

Since 4bb4b2e, our builds have been failing on VSTS on macOS and
Windows. Jenkins is green, however.

~~ macOS ~~

Currently getting a failure building `r8` such as:

    2018-10-30T20:19:05.2225960Z   * What went wrong:
    2018-10-30T20:19:05.2227400Z   Could not determine java version from '11.0.1'.

So I believe the problem here is that Java 11 is in `$PATH`, and this
is only a scenario on the VSTS macOS build agents.

It turns out I was able to clean up quite a bit in `r8.targets`:
- We don't need to call `SetEnvironmentVariable`, I was able to set
  `EnvironmentVariables="...;PATH=$(ChromeToolsDirectory)"` and things
  still worked fine.
- We should pass `--stacktrace` to gradle so that we get detailed
  error messages on a failure.

~~ Windows ~~

Currently getting a failure in
`Xamarin.Android.LibraryProjectZip-LibBinding.csproj` such as:

    2018-10-31T14:02:28.8336608Z    .\gradlew assembleDebug --stacktrace --no-daemon
    2018-10-31T14:02:40.7122197Z   NDK is missing a "platforms" directory.
    2018-10-31T14:02:40.7122937Z   If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to C:\Users\dlab14\android-toolchain\sdk\ndk-bundle.
    2018-10-31T14:02:40.7124870Z   If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

It doesn't really make sense to me why this started happening with
d8/r8 support... The `~\android-toolchain\sdk\ndk-bundle` path seems
completely wrong.

However, it looks like we should be setting
`ANDROID_NDK_HOME=$(AndroidNdkDirectory)`. This is the only other
place we are calling `gradle`, so it is somehow *related* to the d8/r8
changes.
  • Loading branch information
jonathanpeppers committed Oct 31, 2018
1 parent 02c07ed commit 41723a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
30 changes: 3 additions & 27 deletions src/r8/r8.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.DownloadUri" />
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable" />
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" TaskName="Xamarin.Android.Tools.BootstrapTasks.UnzipDirectoryChildren" />

<PropertyGroup>
<!--NOTE: we don't want a gradle daemon locking directories on Windows-->
<_GradleArgs>--no-daemon</_GradleArgs>
<_GradleArgs>--stacktrace --no-daemon</_GradleArgs>
<BuildDependsOn>
ResolveReferences;
_BuildR8;
Expand All @@ -20,26 +19,14 @@

<!--
NOTE: depot_tools has an odd requirement of being in PATH
I am also getting some odd failures on Windows, if not specifying namespace for <SetEnvironmentVariable />
-->

<Target Name="_BuildR8">
<PropertyGroup>
<_OriginalPath>$(PATH)</_OriginalPath>
</PropertyGroup>
<Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable
Name="PATH"
Value="$([System.IO.Path]::GetFullPath('$(ChromeToolsDirectory)'))$(PathSeparator)$(_OriginalPath)"
/>
<Exec
Command="python tools\gradle.py d8 r8 $(_GradleArgs)"
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory)"
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);PATH=$(ChromeToolsDirectory)"
WorkingDirectory="..\..\external\r8"
/>
<Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable
Name="PATH"
Value="$(_OriginalPath)"
/>
</Target>

<Target Name="_CopyR8">
Expand All @@ -51,25 +38,14 @@
</Target>

<Target Name="_CleanR8">
<PropertyGroup>
<_OriginalPath>$(PATH)</_OriginalPath>
</PropertyGroup>
<Delete
Files="$(XAInstallPrefix)xbuild\Xamarin\Android\d8.jar;$(XAInstallPrefix)xbuild\Xamarin\Android\r8.jar;"
/>
<Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable
Name="PATH"
Value="$([System.IO.Path]::GetFullPath('$(ChromeToolsDirectory)'))$(PathSeparator)$(_OriginalPath)"
/>
<Exec
Command="python tools\gradle.py clean $(_GradleArgs)"
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory)"
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);PATH=$(ChromeToolsDirectory)"
WorkingDirectory="..\..\external\r8"
/>
<Xamarin.Android.BuildTools.PrepTasks.SetEnvironmentVariable
Name="PATH"
Value="$(_OriginalPath)"
/>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<_Jdk9Modules Condition="$(_JdkVersion.StartsWith ('9'))">JAVA_OPTS="--add-modules java.xml.bind"</_Jdk9Modules>
</PropertyGroup>
<Exec
EnvironmentVariables="ANDROID_HOME=$(AndroidSdkDirectory);JAVA_HOME=$(JavaSdkDirectory)"
EnvironmentVariables="ANDROID_HOME=$(AndroidSdkDirectory);ANDROID_NDK_HOME=$(AndroidNdkDirectory);JAVA_HOME=$(JavaSdkDirectory)"
Command="$(_Jdk9Modules) .\gradlew assembleDebug --stacktrace --no-daemon"
WorkingDirectory="$(MSBuildThisFileDirectory)java\JavaLib"
/>
Expand Down

0 comments on commit 41723a5

Please sign in to comment.