Skip to content

Commit

Permalink
Merge branch 'master' of github.com:xamarin/xamarin-android into mono…
Browse files Browse the repository at this point in the history
…-2018-02
  • Loading branch information
luhenry committed Apr 24, 2018
2 parents bbe0a2d + 4a85391 commit a770051
Show file tree
Hide file tree
Showing 25 changed files with 224 additions and 100 deletions.
12 changes: 6 additions & 6 deletions Documentation/building/unix-instructions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Building Xamarin.Android on Linux and macOS

Building Xamarin.Android on Linux and macOS relies on GNU make and
MSBuild via the `xbuild` command (within Mono). MSBuild via `msbuild`
can also be used by setting the `$(MSBUILD)` make variable to `msbuild`.
MSBuild via the `msbuild` command (within Mono). MSBuild via `xbuild`
can also be used by setting the `$(MSBUILD)` make variable to `xbuild`.

# Building Xamarin.Android

Expand Down Expand Up @@ -240,7 +240,7 @@ history.
The various Mono runtimes -- over *20* of them (!) -- all store object code
within `src/mono-runtimes/obj/$(Configuration)/TARGET`.

If you change sources within `external/mono`, a top-level `make`/`xbuild`
If you change sources within `external/mono`, a top-level `make`/`msbuild`
invocation may not rebuild those mono native binaries. To explicitly rebuild
*all* Mono runtimes, you must do two things:

Expand All @@ -256,7 +256,7 @@ an "intermediate" commit in order to trigger a rebuild.)
The `ForceBuild` target can be executed as:

# Build and install all runtimes
$ xbuild /t:ForceBuild src/mono-runtimes/mono-runtimes.csproj
$ msbuild /t:ForceBuild src/mono-runtimes/mono-runtimes.csproj

The `ForceBuild` target will build mono for *all* configured architectures,
then invoke the `_InstallRuntimes` target when all the mono's have finished
Expand All @@ -279,7 +279,7 @@ For example, to rebuild Mono for armeabi-v7a:
$ make -C src/mono-runtimes/obj/Debug/armeabi-v7a

# This updates bin/$(Configuration)/lib/xamarin.android/xbuild/Xamarin/Android/lib/armeabi-v7a/libmonosgen-2.0.so
$ xbuild /t:_InstallRuntimes src/mono-runtimes/mono-runtimes.csproj
$ msbuild /t:_InstallRuntimes src/mono-runtimes/mono-runtimes.csproj


# How do I rebuild BCL assemblies?
Expand All @@ -300,5 +300,5 @@ Once the assemblies have been rebuilt, they can be copied into the appropriate
Xamarin.Android SDK directory by using the `_InstallBcl` target:

# This updates bin/$(Configuration)/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/ASSEMBLY.dll
$ xbuild src/mono-runtimes/mono-runtimes.csproj /t:_InstallBcl
$ msbuild src/mono-runtimes/mono-runtimes.csproj /t:_InstallBcl

12 changes: 12 additions & 0 deletions Documentation/guides/messages/apt0000.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Compiler Error/Warning APT0000

This message indicates that `aapt` (Android Asset Packaging Tool) reported an error or warning. `aapt` is part of the Android SDK and is used internally by Xamarin.Android to process and compile resources into binary assets. Learn more about `aapt` and Android resources from the [Android documentation](https://developer.android.com/guide/topics/resources/accessing-resources.html).

Errors reported by `aapt` are very much outside of Xamarin.Android's control, so a general error code of `APT0000` is used reporting the exact message coming from `aapt`.

A few common messages include:
- `error APT0000: res\drawable\image (1).png: Invalid file name: must contain only [a-z0-9_.]`
- `error APT0000: Resource entry resource_name is already defined.`
- `error APT0000: No resource found that matches the given name (at 'resource_name' with value '@string/foo').`
- `error APT0000: invalid resource directory name: obj\Debug\dir with spaces "dir with spaces".`
- `warning APT0000: warning: string 'resource_name' has no default translation.`
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export LINUX_DISTRO_RELEASE := $(shell lsb_release -r -s || true)
prepare:: linux-prepare
endif # $(OS_NAME)=Linux

prepare:: prepare-msbuild
prepare:: prepare-paths prepare-msbuild

linux-prepare::
BINFMT_MISC_TROUBLE="cli win" \
Expand Down Expand Up @@ -128,6 +128,18 @@ include tests/api-compatibility/api-compatibility.mk

topdir := $(shell pwd)


XA_BUILD_PATHS_OUT = $(CONFIGURATIONS:%=bin/Test%/XABuildPaths.cs)

prepare-paths: $(XA_BUILD_PATHS_OUT)

$(XA_BUILD_PATHS_OUT): bin/Test%/XABuildPaths.cs: build-tools/scripts/XABuildPaths.cs.in
mkdir -p $(shell dirname $@)
sed -e 's;@CONFIGURATION@;$*;g' \
-e 's;@TOP_DIRECTORY@;$(topdir);g' < $< > $@
cat $@


# Usage: $(call CALL_CREATE_THIRD_PARTY_NOTICES,configuration,path,licenseType,includeExternalDeps,includeBuildDeps)
define CREATE_THIRD_PARTY_NOTICES
$(MSBUILD) $(MSBUILD_FLAGS) $(_MSBUILD_ARGS) \
Expand Down
2 changes: 1 addition & 1 deletion build-tools/api-xml-adjuster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ANDROID_JAR = $(ANDROID_SDK_PATH)/platforms/android-$(LEVEL)/android.jar

DOCS_DIR_CUR_LEVEL = $(DOCS_DIR)/docs-api-$(LEVEL)

XBUILD = JAVA_INTEROP_PATH=$(JAVA_INTEROP_PATH) xbuild
XBUILD = JAVA_INTEROP_PATH=$(JAVA_INTEROP_PATH) msbuild

all:
for level in $(API_LEVELS) ; do \
Expand Down
2 changes: 1 addition & 1 deletion build-tools/debian-metadata/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/xamarin/xamarin-android

Package: xamarin.android-oss
Architecture: amd64
Depends: mono-xbuild (>= 5.2), java8-sdk, ${misc:Depends}, ${shlibs:Depends}
Depends: msbuild, java8-sdk, ${misc:Depends}, ${shlibs:Depends}
Description: Xamarin.Android libraries and runtime (host component)
The best way to build native Android apps.
.
Expand Down
8 changes: 7 additions & 1 deletion build-tools/scripts/PrepareWindows.targets
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
DestinationFile="$(_TopDir)\Configuration.OperatingSystem.props"
Replacements="@JAVA_HOME@=$(_JavaSdkDirectory)"
/>
<MakeDir Directories="$(_TopDir)\bin\Test$(Configuration)" />
<ReplaceFileContents
SourceFile="$(MSBuildThisFileDirectory)XABuildPaths.cs.in"
DestinationFile="$(_TopDir)\bin\Test$(Configuration)\XABuildPaths.cs"
Replacements="@TOP_DIRECTORY@=$(_TopDir);@CONFIGURATION@=$(Configuration)"
/>
<MSBuild
Projects="$(_TopDir)\build-tools\ThirdPartyNotices\ThirdPartyNotices.csproj"
Properties="ThirdPartyNoticeFile=$(_TopDir)\ThirdPartyNotices.txt;ThirdPartyNoticeLicenseType=foundation"
Expand All @@ -43,4 +49,4 @@
Properties="ThirdPartyNoticeFile=$(_TopDir)\bin\$(Configuration)\lib\xamarin.android\ThirdPartyNotices.txt;ThirdPartyNoticeLicenseType=microsoft-oss;TpnIncludeExternalDependencies=True"
/>
</Target>
</Project>
</Project>
39 changes: 31 additions & 8 deletions build-tools/scripts/RunTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,47 @@
<Target Name="RunNUnitTests">
<SetEnvironmentVariable Name="USE_MSBUILD" Value="0" Condition=" '$(USE_MSBUILD)' == '' " />
<Exec
Command="$(_NUnit) $(NUNIT_EXTRA) %(_TestAssembly.Identity) $(_Test) --result=&quot;TestResult-%(Filename).xml;format=nunit2&quot; --output=&quot;bin\Test$(Configuration)\TestOutput-%(Filename).txt&quot;"
Command="$(_NUnit) $(NUNIT_EXTRA) %(_TestAssembly.Identity) $(_Test) --labels=All --result=&quot;TestResult-%(Filename).xml;format=nunit2&quot; --output=&quot;bin\Test$(Configuration)\TestOutput-%(Filename).txt&quot;"
WorkingDirectory="$(_TopDir)"
ContinueOnError="ErrorAndContinue"
/>
<ItemGroup>
<_RenameTestCasesGlob Include="$(_TopDir)\TestResult-*Tests.xml" />
<_RenameNUnitTestCasesGlob Include="$(_TopDir)\TestResult-*Tests.xml" />
</ItemGroup>
<PropertyGroup>
<_RenamedTestCases>@(_RenameTestCasesGlob)</_RenamedTestCases>
<_RenamedTestCases>@(_RenameNUnitTestCasesGlob)</_RenamedTestCases>
</PropertyGroup>
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(MSBuildThisFileDirectory)TestApks.targets"
Targets="RenameTestCases"
Properties="Configuration=$(Configuration);RenameTestCasesGlob=$(_RenamedTestCases)"
/>
</Target>
<Target Name="RunJavaInteropTests">
<MSBuild Projects="$(JavaInteropSourceDirectory)\Java.Interop.sln" Condition=" '$(HostOS)' == 'Windows' " />
<MSBuild
Condition=" '$(HostOS)' == 'Windows' "
ContinueOnError="ErrorAndContinue"
Projects="$(JavaInteropSourceDirectory)\Java.Interop.sln"
/>
<Exec
Command ="make -C &quot;$(JavaInteropSourceDirectory)&quot; CONFIGURATION=$(Configuration) all"
Condition=" '$(HostOS)' != 'Windows' "
/>
<SetEnvironmentVariable Name="ANDROID_SDK_PATH" Value="$(AndroidSdkFullPath)" />
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(JavaInteropSourceDirectory)\build-tools\scripts\RunNUnitTests.targets"
Properties="AndroidSdkDirectory=$(AndroidSdkDirectory)"
/>
<ItemGroup>
<_RenameTestCasesGlob Include="$(JavaInteropSourceDirectory)\TestResult-*Tests.xml" />
<_RenameJITestCasesGlob Include="$(JavaInteropSourceDirectory)\TestResult-*Tests.xml" />
</ItemGroup>
<PropertyGroup>
<_RenamedTestCases>@(_RenameTestCasesGlob)</_RenamedTestCases>
<_RenamedTestCases>@(_RenameJITestCasesGlob)</_RenamedTestCases>
</PropertyGroup>
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(MSBuildThisFileDirectory)TestApks.targets"
Targets="RenameTestCases"
Properties="Configuration=$(Configuration);RenameTestCasesGlob=$(_RenamedTestCases)"
Expand All @@ -72,16 +79,32 @@
</Target>
<Target Name="RunApkTests">
<Exec Command="$(_XABuild) %(_ApkTestProject.Identity) /t:SignAndroidPackage $(_XABuildProperties)" />
<MSBuild Projects="$(_TopDir)\tests\RunApkTests.targets" />
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(_TopDir)\tests\RunApkTests.targets"
/>
<Exec
Command="$(_XABuild) %(_ApkTestProjectAot.Identity) /t:SignAndroidPackage $(_XABuildProperties) /p:AotAssemblies=True"
Condition=" '$(Configuration)' == 'Release' "
/>
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(_TopDir)\tests\RunApkTests.targets"
Condition=" '$(Configuration)' == 'Release' "
Properties="AotAssemblies=True"
/>
</Target>
<Target Name="RunAllTests" DependsOnTargets="RunNUnitTests;RunJavaInteropTests;RunApkTests" />
<ItemGroup>
<_RunTestTarget Include="RunNUnitTests" />
<_RunTestTarget Include="RunJavaInteropTests" />
<_RunTestTarget Include="RunApkTests" />
</ItemGroup>
<Target Name="RunAllTests">
<MSBuild
ContinueOnError="ErrorAndContinue"
Projects="$(MSBuildThisFileDirectory)RunTests.targets"
RunEachTargetSeparately="True"
Targets="@(_RunTestTarget)"
/>
</Target>
</Project>
2 changes: 2 additions & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
ContinueOnError="True"
Command="kill -KILL $(_EmuPid)"
/>
</Target>
<Target Name="ReportComponentFailures">
<Error
Condition="'@(_FailedComponent)' != ''"
Text="Execution of the following components did not complete successfully: @(_FailedComponent->'%(Identity)', ', ')"
Expand Down
17 changes: 17 additions & 0 deletions build-tools/scripts/XABuildPaths.cs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.IO;

namespace Xamarin.Android.Build
{
public static class Paths
{
public const string Configuration = "@CONFIGURATION@";
public const string TopDirectory = @"@TOP_DIRECTORY@";

public static readonly string PrefixDirectory = Path.Combine (TopDirectory, "bin", Configuration);
public static readonly string BinDirectory = Path.Combine (PrefixDirectory, "bin");
public static readonly string XABuildScript = Path.Combine (BinDirectory, "xabuild");
public static readonly string XABuildExe = Path.Combine (BinDirectory, "xabuild.exe");
public static readonly string TestOutputDirectory = Path.Combine (TopDirectory, "bin", "Test@CONFIGURATION@");
}
}
4 changes: 2 additions & 2 deletions build-tools/scripts/msbuild.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# $(MSBUILD): The MSBuild program to use. Defaults to `xbuild` unless overridden.
# $(MSBUILD_FLAGS): Additional MSBuild flags; contains $(CONFIGURATION), $(V), $(MSBUILD_ARGS).

MSBUILD = xbuild
MSBUILD = msbuild
MSBUILD_FLAGS = /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS)

ifeq ($(OS_NAME),Darwin)
Expand All @@ -36,7 +36,7 @@ MSBUILD_FLAGS += /v:diag
endif # $(V) != 0

ifeq ($(MSBUILD),msbuild)
USE_MSBUILD = 1
export USE_MSBUILD = 1
endif # $(MSBUILD) == msbuild

ifeq ($(USE_MSBUILD),1)
Expand Down
8 changes: 4 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
return;
}
if (level.Contains ("warning")) {
LogWarning (singleLine);
LogCodedWarning ("APT0000", singleLine);
return;
}

Expand All @@ -450,15 +450,15 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
message = message.Substring ("error: ".Length);

if (level.Contains ("error") || (line != 0 && !string.IsNullOrEmpty (file))) {
LogError ("APT0000", message, file, line);
LogCodedError ("APT0000", message, file, line);
return;
}
}

if (!apptResult) {
LogError ("APT0000", string.Format ("{0} \"{1}\".", singleLine.Trim (), singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1)), ToolName);
LogCodedError ("APT0000", string.Format ("{0} \"{1}\".", singleLine.Trim (), singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1)), ToolName);
} else {
LogWarning (singleLine);
LogCodedWarning ("APT0000", singleLine);
}
}
}
Expand Down
53 changes: 39 additions & 14 deletions src/Xamarin.Android.Build.Tasks/Tasks/AsyncTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,25 @@ public void LogMessage (string message, MessageImportance importance = MessageIm

public void LogError (string message)
{
LogError (code: null, message: message, file: null, lineNumber: 0);
LogCodedError (code: null, message: message, file: null, lineNumber: 0);
}

public void LogError (string message, params object[] messageArgs)
public void LogError (string message, params object [] messageArgs)
{
LogError (code: null, message: string.Format (message, messageArgs));
LogCodedError (code: null, message: string.Format (message, messageArgs));
}

public void LogCodedError (string code, string message)
{
LogError (code: code, message: message, file: null, lineNumber: 0);
LogCodedError (code: code, message: message, file: null, lineNumber: 0);
}

public void LogCodedError (string code, string message, params object[] messageArgs)
public void LogCodedError (string code, string message, params object [] messageArgs)
{
LogError (code: code, message: string.Format (message, messageArgs), file: null, lineNumber: 0);
LogCodedError (code: code, message: string.Format (message, messageArgs), file: null, lineNumber: 0);
}

public void LogError (string code, string message, string file = null, int lineNumber = 0)
public void LogCodedError (string code, string message, string file, int lineNumber)
{
if (UIThreadId == Thread.CurrentThread.ManagedThreadId) {
#pragma warning disable 618
Expand Down Expand Up @@ -186,24 +186,49 @@ public void LogError (string code, string message, string file = null, int lineN
EnqueueMessage (errorMessageQueue, data, errorDataAvailable);
}

public void LogWarning (string message)
{
LogCodedWarning (code: null, message: message, file: null, lineNumber: 0);
}

public void LogWarning (string message, params object[] messageArgs)
{
LogWarning (string.Format (message, messageArgs));
LogCodedWarning (code: null, message: string.Format (message, messageArgs));
}

public void LogWarning (string message)
public void LogCodedWarning (string code, string message)
{
LogCodedWarning (code: code, message: message, file: null, lineNumber: 0);
}

public void LogCodedWarning (string code, string message, params object [] messageArgs)
{
LogCodedWarning (code: code, message: string.Format (message, messageArgs), file: null, lineNumber: 0);
}

public void LogCodedWarning (string code, string message, string file, int lineNumber)
{
if (UIThreadId == Thread.CurrentThread.ManagedThreadId) {
#pragma warning disable 618
Log.LogWarning (message);
Log.LogWarning (
subcategory: null,
warningCode: code,
helpKeyword: null,
file: file,
lineNumber: lineNumber,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
message: message
);
return;
#pragma warning restore 618
}
var data = new BuildWarningEventArgs (
subcategory: null,
code: null,
file: null,
lineNumber: 0,
code: code,
file: file,
lineNumber: lineNumber,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
Expand Down Expand Up @@ -298,7 +323,7 @@ protected void WaitForCompletion ()
case WaitHandleIndex.WarningDataAvailable:
LogInternal<BuildWarningEventArgs> (warningMessageQueue, (e) => {
#pragma warning disable 618
Log.LogWarning (e.Message);
Log.LogCodedWarning (e.Code, file: e.File, lineNumber: e.LineNumber, message: e.Message);
#pragma warning restore 618
}, warningDataAvailable);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ void AddAssemblyReferences (DirectoryAssemblyResolver resolver, ICollection<stri
string missingAssembly = Path.GetFileNameWithoutExtension (ex.FileName);
string message = $"Can not resolve reference: `{missingAssembly}`, referenced by {references}.";
if (MonoAndroidHelper.IsFrameworkAssembly (ex.FileName)) {
LogError ("XA2002", $"{message} Perhaps it doesn't exist in the Mono for Android profile?");
LogCodedError ("XA2002", $"{message} Perhaps it doesn't exist in the Mono for Android profile?");
} else {
LogError ("XA2002", $"{message} Please add a NuGet package or assembly reference for `{missingAssembly}`, or remove the reference to `{resolutionPath [0]}`.");
LogCodedError ("XA2002", $"{message} Please add a NuGet package or assembly reference for `{missingAssembly}`, or remove the reference to `{resolutionPath [0]}`.");
}
return;
}
Expand Down
Loading

0 comments on commit a770051

Please sign in to comment.