Skip to content

Commit

Permalink
[msbuild] support AndroidManifest.xml placeholders.
Browse files Browse the repository at this point in the history
We only support ${applicationId} so far, but it seems to be used a lot as
https://developer.android.com/studio/build/manifest-build-variables.html

Since we are not using Gradle, we'd need something similar to it, which
is therefore MSBuild property.
  • Loading branch information
atsushieno committed Jan 16, 2017
1 parent 5743327 commit 77fb54a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Expand Up @@ -38,6 +38,7 @@ public class GenerateJavaStubs : Task
public bool Debug { get; set; }
public string ApplicationName { get; set; }
public string PackageName { get; set; }
public string [] ManifestPlaceholders { get; set; }

public string AndroidSdkDir { get; set; }

Expand Down Expand Up @@ -77,6 +78,7 @@ public override bool Execute ()
Log.LogDebugTaskItems (" MergedManifestDocuments:", MergedManifestDocuments);
Log.LogDebugMessage (" PackageNamingPolicy: {0}", PackageNamingPolicy);
Log.LogDebugMessage (" ApplicationJavaClass: {0}", ApplicationJavaClass);
Log.LogDebugTaskItems (" ManifestPlaceholders: ", ManifestPlaceholders);

try {
// We're going to do 3 steps here instead of separate tasks so
Expand Down Expand Up @@ -199,6 +201,7 @@ void Run (DirectoryAssemblyResolver res)

manifest.PackageName = PackageName;
manifest.ApplicationName = ApplicationName ?? PackageName;
manifest.Placeholders = ManifestPlaceholders;
manifest.Assemblies.AddRange (assemblies);
manifest.Resolver = res;
manifest.SdkDir = AndroidSdkDir;
Expand Down
10 changes: 9 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Expand Up @@ -47,6 +47,7 @@ internal class ManifestDocument
public string PackageName { get; set; }
public List<string> Addons { get; private set; }
public string ApplicationName { get; set; }
public string [] Placeholders { get; set; }
public List<string> Assemblies { get; set; }
public DirectoryAssemblyResolver Resolver { get; set; }
public string SdkDir { get; set; }
Expand Down Expand Up @@ -780,7 +781,7 @@ public void Save (string filename)
using (var file = new StreamWriter (filename, false, new UTF8Encoding (false)))
Save (file);
}

public void Save (System.IO.TextWriter stream)
{
var ms = new MemoryStream ();
Expand All @@ -790,6 +791,13 @@ public void Save (System.IO.TextWriter stream)
var s = new StreamReader (ms).ReadToEnd ();
if (ApplicationName != null)
s = s.Replace ("${applicationId}", ApplicationName);
if (Placeholders != null)
foreach (var entry in Placeholders.Select (e => e.Split (new char [] {'='}, 2, StringSplitOptions.None))) {
if (entry.Length == 2)
s = s.Replace ("${" + entry [0] + "}", entry [1]);
else
log.LogWarning ("Invalid application placeholders (AndroidApplicationPlaceholders) value. Use 'key1=value1;key2=value2, ...' format. The specified value was: " + Placeholders);
}
stream.Write (s);
}

Expand Down
Expand Up @@ -178,7 +178,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<AndroidUpdateResourceReferences Condition="'$(AndroidUpdateResourceReferences)' == ''">True</AndroidUpdateResourceReferences>
<EmbedAssembliesIntoApk Condition="'$(EmbedAssembliesIntoApk)' == ''">True</EmbedAssembliesIntoApk>


<!-- Ahead-of-time compilation properties -->
<AndroidAotMode Condition=" '$(AndroidAotMode)' == '' And '$(AotAssemblies)' == 'True' ">Normal</AndroidAotMode>
<AotAssemblies Condition=" '$(AndroidAotMode)' != '' ">True</AotAssemblies>
Expand Down Expand Up @@ -249,6 +248,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.

<_AndroidMainDexListFile>$(IntermediateOutputPath)multidex.keep</_AndroidMainDexListFile>

<AndroidManifestPlaceholders Condition="'$(AndroidManifestPlaceholders)' == ''"></AndroidManifestPlaceholders>

<_PackagedResources>$(IntermediateOutputPath)android\bin\packaged_resources</_PackagedResources>

<_Android32bitArchitectures>armeabi-v7a;armeabi;x86;mips</_Android32bitArchitectures>
Expand Down Expand Up @@ -1675,6 +1676,7 @@ because xbuild doesn't support framework reference assemblies.
AndroidSdkPlatform="$(_AndroidApiLevel)"
AndroidSdkDir="$(_AndroidSdkDirectory)"
PackageName="$(_AndroidPackage)"
ManifestPlaceholders="$(AndroidManifestPlaceholders)"
OutputDirectory="$(IntermediateOutputPath)android"
MergedAndroidManifestOutput="$(IntermediateOutputPath)android\AndroidManifest.xml"
UseSharedRuntime="$(AndroidUseSharedRuntime)"
Expand Down

0 comments on commit 77fb54a

Please sign in to comment.