Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Documentation/docs-mobile/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,67 @@ If `DebugType` is not set or is the empty string, then the
`DebugSymbols` property controls whether or not the Application is
debuggable.

## DiagnosticAddress

A value provided by `dotnet-dsrouter` such as `127.0.0.1`, the IP
address component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `127.0.0.1`.

## DiagnosticConfiguration

A value provided by `dotnet-dsrouter` for `$DOTNET_DiagnosticPorts` such as:

* `127.0.0.1:9000,suspend,connect`
* `127.0.0.1:9000,nosuspend,connect`

Note that the `,` character will need to be escaped with `%2c` if
passed in command-line to `dotnet build`:

```dotnetcli
dotnet build -c Release -p:DiagnosticConfiguration=127.0.0.1:9000%2csuspend%2cconnect
```

This will automatically set the `$DOTNET_DiagnosticPorts` environment
variable packaged inside the application.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

## DiagnosticListenMode

A value provided by `dotnet-dsrouter` such as `connect`, the listening
mode component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `connect`.

## DiagnosticPort

A value provided by `dotnet-dsrouter` such as `9000`, the port
component of `$(DiagnosticConfiguration)` or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `9000`.

## DiagnosticSuspend

A boolean value provided by `dotnet-dsrouter` such as `true/suspend`
or `false/nosuspend`, a component of `$(DiagnosticConfiguration)`
or `$DOTNET_DiagnosticPorts`.

Implicitly enables the Mono diagnostic component, meaning that
`$(EnableDiagnostics)`/`$(AndroidEnableProfiler)` is set to `true`.

Defaults to `false`.

## EmbedAssembliesIntoApk

A boolean property that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ properties that determine build ordering.
_ConvertCustomView;
$(_AfterConvertCustomView);
$(AfterGenerateAndroidManifest);
_GenerateEnvironmentFiles;
_ReadAndroidManifest;
_CompileJava;
_CreateApplicationSharedLibraries;
_CompileDex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
<AndroidEnableRestrictToAttributes Condition=" '$(AndroidEnableRestrictToAttributes)' == '' ">obsolete</AndroidEnableRestrictToAttributes>

<!-- Mono components -->
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">$(EnableDiagnostics)</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == ''">false</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' ">$(EnableDiagnostics)</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' and ('$(DiagnosticConfiguration)' != '' or '$(DiagnosticAddress)' != '' or '$(DiagnosticPort)' != '' or '$(DiagnosticSuspend)' != '' or '$(DiagnosticListenMode)' != '') ">true</AndroidEnableProfiler>
<AndroidEnableProfiler Condition=" '$(AndroidEnableProfiler)' == '' ">false</AndroidEnableProfiler>

<!--
Android package (apt/aab) alignment, expressed as the page size in kilobytes. Two values are supported: 4 and 16.
Expand All @@ -55,6 +56,16 @@
<AndroidZipAlignment Condition=" '$(AndroidZipAlignment)' == '' ">16</AndroidZipAlignment>
</PropertyGroup>

<PropertyGroup Condition=" '$(AndroidEnableProfiler)' == 'true' and '$(DiagnosticConfiguration)' == '' ">
<DiagnosticAddress Condition=" '$(DiagnosticAddress)' == '' ">127.0.0.1</DiagnosticAddress>
<DiagnosticPort Condition=" '$(DiagnosticPort)' == '' ">9000</DiagnosticPort>
<DiagnosticSuspend Condition=" '$(DiagnosticSuspend)' == '' ">false</DiagnosticSuspend>
<DiagnosticListenMode Condition=" '$(DiagnosticListenMode)' == '' ">connect</DiagnosticListenMode>
<DiagnosticConfiguration>$(DiagnosticAddress):$(DiagnosticPort),$(DiagnosticListenMode)</DiagnosticConfiguration>
<DiagnosticConfiguration Condition=" '$(DiagnosticSuspend)' == 'true' ">$(DiagnosticConfiguration),suspend</DiagnosticConfiguration>
<DiagnosticConfiguration Condition=" '$(DiagnosticSuspend)' != 'true' ">$(DiagnosticConfiguration),nosuspend</DiagnosticConfiguration>
</PropertyGroup>

<!-- User-facing configuration-specific defaults -->
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AndroidLinkMode Condition=" '$(AndroidLinkMode)' == '' ">None</AndroidLinkMode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,21 +1255,30 @@ public void AbiNameInIntermediateOutputPath ()
}

[Test]
public void PackageNamingPolicy ([Values ("LowercaseMD5", "LowercaseCrc64")] string packageNamingPolicy)
[TestCase (true, "LowercaseMD5", "")]
[TestCase (true, "LowercaseCrc64", "")]
[TestCase (false, "LowercaseCrc64", "127.0.0.1:9000,suspend,connect")]
public void EnvironmentVariables (bool useInterpreter, string packageNamingPolicy, string diagnosticConfiguration)
{
var proj = new XamarinAndroidApplicationProject ();
proj.SetProperty ("UseInterpreter", "true");
proj.SetProperty ("AndroidPackageNamingPolicy", packageNamingPolicy);
proj.SetProperty ("UseInterpreter", useInterpreter.ToString ());
if (!string.IsNullOrEmpty (packageNamingPolicy))
proj.SetProperty ("AndroidPackageNamingPolicy", packageNamingPolicy);
if (!string.IsNullOrEmpty (diagnosticConfiguration))
proj.SetProperty ("DiagnosticConfiguration", diagnosticConfiguration);
proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86");
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
var environment = b.Output.GetIntermediaryPath (Path.Combine ("__environment__.txt"));
FileAssert.Exists (environment);
var values = new List<string> {
$"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}"
$"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}",
"mono.enable_assembly_preload=0",
};
values.Add ("mono.enable_assembly_preload=0");
values.Add ("DOTNET_MODIFIABLE_ASSEMBLIES=Debug");
if (useInterpreter)
values.Add ("DOTNET_MODIFIABLE_ASSEMBLIES=Debug");
if (!string.IsNullOrEmpty (diagnosticConfiguration))
values.Add ($"DOTNET_DiagnosticPorts={diagnosticConfiguration}");
Assert.AreEqual (string.Join (Environment.NewLine, values), File.ReadAllText (environment).Trim ());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ because xbuild doesn't support framework reference assemblies.
</_GenerateJavaStubsDependsOnTargets>
</PropertyGroup>

<Target Name="_GetGenerateJavaStubsInputs">
<Target Name="_GetGenerateJavaStubsInputs" DependsOnTargets="_GenerateEnvironmentFiles">
<ItemGroup>
<_GenerateJavaStubsInputs Include="@(_AndroidMSBuildAllProjects)" />
<_GenerateJavaStubsInputs Include="$(_ResolvedUserAssembliesHashFile)" />
Expand Down Expand Up @@ -1631,11 +1631,12 @@ because xbuild doesn't support framework reference assemblies.
</PrepareAbiItems>
</Target>

<Target Name="_GenerateEnvironmentFiles" DependsOnTargets="_ReadAndroidManifest">
<Target Name="_GenerateEnvironmentFiles">
<ItemGroup>
<_GeneratedAndroidEnvironment Include="__XA_PACKAGE_NAMING_POLICY__=$(AndroidPackageNamingPolicy)" />
<_GeneratedAndroidEnvironment Include="mono.enable_assembly_preload=0" Condition=" '$(AndroidEnablePreloadAssemblies)' != 'True' " />
<_GeneratedAndroidEnvironment Include="DOTNET_MODIFIABLE_ASSEMBLIES=Debug" Condition=" '$(AndroidIncludeDebugSymbols)' == 'true' and '$(AndroidUseInterpreter)' == 'true' " />
<_GeneratedAndroidEnvironment Include="DOTNET_DiagnosticPorts=$(DiagnosticConfiguration)" Condition=" '$(DiagnosticConfiguration)' != '' " />
</ItemGroup>
<WriteLinesToFile
File="$(IntermediateOutputPath)__environment__.txt"
Expand Down Expand Up @@ -1811,7 +1812,7 @@ because xbuild doesn't support framework reference assemblies.
_ManifestMerger;
_ConvertCustomView;
$(_AfterConvertCustomView);
_GenerateEnvironmentFiles;
_ReadAndroidManifest;
_GetLibraryImports;
_CheckDuplicateJavaLibraries;
UpdateAndroidAssets;
Expand Down
20 changes: 19 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,20 @@ public void SupportDesugaringStaticInterfaceMethods ()
}

[Test]
public void FastDeployEnvironmentFiles ([Values (false, true)] bool isRelease)
[TestCase (false, true)]
[TestCase (false, false)]
[TestCase (true, false)]
public void FastDeployEnvironmentFiles (bool isRelease, bool embedAssembliesIntoApk)
{
if (embedAssembliesIntoApk) {
AssertCommercialBuild ();
}

var proj = new XamarinAndroidApplicationProject {
ProjectName = nameof (FastDeployEnvironmentFiles),
RootNamespace = nameof (FastDeployEnvironmentFiles),
IsRelease = isRelease,
EmbedAssembliesIntoApk = embedAssembliesIntoApk,
EnableDefaultItems = true,
OtherBuildItems = {
new BuildItem("AndroidEnvironment", "env.txt") {
Expand All @@ -967,12 +975,17 @@ public void FastDeployEnvironmentFiles ([Values (false, true)] bool isRelease)
}
}
};
proj.SetProperty ("DiagnosticAddress", "127.0.0.1");
proj.SetProperty ("DiagnosticPort", "9000");
proj.SetProperty ("DiagnosticSuspend", "false");
proj.SetProperty ("DiagnosticListenMode", "connect");
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", @"
Console.WriteLine (""Foo="" + Environment.GetEnvironmentVariable(""Foo""));
Console.WriteLine (""Bar34="" + Environment.GetEnvironmentVariable(""Bar34""));
Console.WriteLine (""Empty="" + Environment.GetEnvironmentVariable(""Empty""));
Console.WriteLine (""MONO_GC_PARAMS="" + Environment.GetEnvironmentVariable(""MONO_GC_PARAMS""));
Console.WriteLine (""DOTNET_MODIFIABLE_ASSEMBLIES="" + Environment.GetEnvironmentVariable(""DOTNET_MODIFIABLE_ASSEMBLIES""));
Console.WriteLine (""DOTNET_DiagnosticPorts="" + Environment.GetEnvironmentVariable(""DOTNET_DiagnosticPorts""));
");
var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed");
Expand Down Expand Up @@ -1006,6 +1019,11 @@ public void FastDeployEnvironmentFiles ([Values (false, true)] bool isRelease)
logcatOutput,
"The Environment variable \"MONO_GC_PARAMS\" was not set to expected value \"bridge-implementation=new\"."
);
StringAssert.Contains (
"DOTNET_DiagnosticPorts=127.0.0.1:9000,connect,nosuspend",
logcatOutput,
"The Environment variable \"DOTNET_DiagnosticPorts\" was not set to expected value \"127.0.0.1:9000,connect,nosuspend\"."
);
// NOTE: set when $(UseInterpreter) is true, default for Debug mode
if (!isRelease) {
StringAssert.Contains (
Expand Down
Loading