Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Bundled multidex jar (#124)
Browse files Browse the repository at this point in the history
* [msbuild] switch to bundled multidex jar

Android SDK had obsoleted multidex support components, so we'd rather
embed the jar directly in our SDK.

* Copy android-support-multidex.jar into mandroid directory.

What this change actually does are:

- additionally download support m2repository in android-toolchains.
- extract multidex jar from support multidex aar.
- extend UnzipDirectoryChildren task to support non-children extraction.

* Copy support library license file to lib/mandroid as MULTIDEX_JAR_LICENSE.

It is to make it clear that the jar file is from Android SDK support library.
  • Loading branch information
atsushieno authored and jonpryor committed Aug 9, 2016
1 parent 6805d20 commit b891914
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions build-tools/android-toolchain/android-toolchain.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
<HostOS></HostOS>
<DestDir>platforms\android-24</DestDir>
</AndroidSdkItem>
<AndroidSdkItem Include="android_m2repository_r16.zip">
<HostOS></HostOS>
<DestDir>extras\android\m2repository</DestDir>
</AndroidSdkItem>
</ItemGroup>
<ItemGroup>
<_NdkToolchain Include="arm-linux-androideabi-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi:')) Or $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi-v7a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-armeabi:'))">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="Xamarin.Android.Tools.BootstrapTasks.GenerateProfile" AssemblyFile="..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" />
<UsingTask TaskName="Xamarin.Android.Tools.BootstrapTasks.UnzipDirectoryChildren" AssemblyFile="..\..\bin\Build$(Configuration)\Xamarin.Android.Tools.BootstrapTasks.dll" />
<PropertyGroup>
<_SharedRuntimeBuildPath Condition=" '$(_SharedRuntimeBuildPath)' == '' ">..\..\bin\$(Configuration)\lib\xbuild-frameworks\MonoAndroid\</_SharedRuntimeBuildPath>
<_GeneratedProfileClass>$(IntermediateOutputPath)Profile.g.cs</_GeneratedProfileClass>
<BuildDependsOn>
$(BuildDependsOn);
_CopyExtractedMultiDexJar;
</BuildDependsOn>
<_AndroidSdkLocation>$(ANDROID_SDK_PATH)</_AndroidSdkLocation>
<_AndroidSdkLocation Condition="'$(_AndroidSdkLocation)'==''">$(AndroidToolchainDirectory)\sdk</_AndroidSdkLocation>
<_MultiDexAarInAndroidSdk>extras\android\m2repository\com\android\support\multidex\1.0.1\multidex-1.0.1.aar</_MultiDexAarInAndroidSdk>
<_SupportLicenseInAndroidSdk>extras\android\m2repository\NOTICE.txt</_SupportLicenseInAndroidSdk>
</PropertyGroup>
<ItemGroup>
<_SharedRuntimeAssemblies Include="$(_SharedRuntimeBuildPath)v1.0\*.dll;$(_SharedRuntimeBuildPath)$(AndroidFrameworkVersion)\*.dll"/>
Expand All @@ -23,4 +32,19 @@
Lines="$(_GeneratedProfileClass)"
Overwrite="false"/>
</Target>

<Target Name="_CopyExtractedMultiDexJar"
Inputs="$(_AndroidSdkLocation)\$(_MultiDexAarInAndroidSdk);$(_AndroidSdkLocation)\$(_SupportLicenseInAndroidSdk)"
Outputs="$(OutputPath)..\..\..\mandroid\android-support-multidex.jar;$(OutputPath)..\..\..\mandroid\MULTIDEX_JAR_LICENSE">
<UnzipDirectoryChildren
NoSubdirectory="true"
SourceFiles="$(_AndroidSdkLocation)\$(_MultiDexAarInAndroidSdk)"
DestinationFolder="$(IntermediateOutputPath)multidex-aar" />
<Copy
SourceFiles="$(IntermediateOutputPath)multidex-aar\classes.jar"
DestinationFiles="$(OutputPath)..\..\..\mandroid\android-support-multidex.jar" />
<Copy
SourceFiles="$(_AndroidSdkLocation)\$(_SupportLicenseInAndroidSdk)"
DestinationFiles="$(OutputPath)..\..\..\mandroid\MULTIDEX_JAR_LICENSE" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<DeployExternal Condition="'$(DeployExternal)' == ''">False</DeployExternal>
<UseShortFileNames Condition="'$(UseShortFileNames)' != 'True'">False</UseShortFileNames>

<AndroidMultiDexSupportJar>extras\android\support\multidex\library\libs\android-support-multidex.jar</AndroidMultiDexSupportJar>
<!-- Obsolete build property: should be removed in the future releases -->
<AndroidMultiDexSupportJar></AndroidMultiDexSupportJar>

<AndroidSupportedAbis Condition=" '$(AndroidSupportedAbis)' == '' ">armeabi-v7a</AndroidSupportedAbis>

Expand Down Expand Up @@ -1072,7 +1073,11 @@ because xbuild doesn't support framework reference assemblies.

<Target Name="_AddMultiDexDependencyJars">
<CreateItem Include="$(AndroidSdkDirectory)\$(AndroidMultiDexSupportJar)"
Condition="'$(AndroidEnableMultiDex)' == 'True'">
Condition="'$(AndroidEnableMultiDex)' == 'True' AND '$(AndroidMultiDexSupportJar)' != ''">
<Output TaskParameter="Include" ItemName="AndroidJavaLibrary" />
</CreateItem>
<CreateItem Include="$(MonoAndroidToolsDirectory)\android-support-multidex.jar"
Condition="'$(AndroidEnableMultiDex)' == 'True' AND '$(AndroidMultiDexSupportJar)' == ''">
<Output TaskParameter="Include" ItemName="AndroidJavaLibrary" />
</CreateItem>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public UnzipDirectoryChildren ()
[Required]
public ITaskItem DestinationFolder { get; set; }

public bool NoSubdirectory { get; set; }

public override bool Execute ()
{
Log.LogMessage (MessageImportance.Low, "Unzip:");
Expand Down Expand Up @@ -101,7 +103,9 @@ async TTask ExtractFile (string tempDir, string sourceFile, string relativeDestD
p.WaitForExit ();
}

foreach (var dir in Directory.EnumerateDirectories (nestedTemp, "*")) {
var dirs = NoSubdirectory ? new string [] { nestedTemp } : Directory.EnumerateDirectories (nestedTemp, "*");

foreach (var dir in dirs) {
foreach (var fse in Directory.EnumerateFileSystemEntries (dir)) {
var name = Path.GetFileName (fse);
var destDir = string.IsNullOrEmpty (relativeDestDir)
Expand Down

0 comments on commit b891914

Please sign in to comment.