@@ -18,6 +18,7 @@ var AAR_VERSION = "25.0.0";
1818// FROM: https://dl.google.com/android/repository/addon.xml
1919// FROM: https://dl.google.com/android/repository/addon2-1.xml
2020var M2_REPOSITORY_URL = "https: //dl-ssl.google.com/android/repository/android_m2repository_r39.zip";
21+ var M2_REPOSITORY_SHA1 = "89 ad37d67a1018c42be36933cec3d7712141d42c";
2122var BUILD_TOOLS_URL = "https: //dl-ssl.google.com/android/repository/build-tools_r24-macosx.zip";
2223var DOCS_URL = "https: //dl-ssl.google.com/android/repository/docs-23_r01.zip";
2324var ANDROID_SDK_VERSION = IsRunningOnWindows ( ) ? "v7.0 " : "android- 24 ";
@@ -26,14 +27,53 @@ var RENDERSCRIPT_FOLDER = "android-N";
2627// We grab the previous release's api-info.xml to use as a comparison for this build's generated info to make an api-diff
2728var BASE_API_INFO_URL = "https: //github.com/xamarin/AndroidSupportComponents/releases/download/24.2.1/api-info.xml";
2829
29- var AAR_DIRS = new [ ] {
30- "support-v4" , "support-v13" , "appcompat-v7" , "gridlayout-v7" , "mediarouter-v7" , "recyclerview-v7" ,
31- "palette-v7" , "cardview-v7" , "leanback-v17" , "design" , "percent" , "customtabs" , "preference-v7" ,
32- "preference-v14" , "preference-leanback-v17" , "recommendation" , "animated-vector-drawable" ,
33- "support-vector-drawable" , "support-compat" , "support-core-utils" , "support-core-ui" ,
34- "support-media-compat" , "support-fragment" , "transition"
30+ var AAR_INFOS = new [ ] {
31+ new AarInfo ( "support-v4" , "v4" , "Xamarin.Android.Support.v4" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
32+ new AarInfo ( "support-v13" , "v13" , "Xamarin.Android.Support.v13" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
33+ new AarInfo ( "appcompat-v7" , "v7-appcompat" , "Xamarin.Android.Support.v7.AppCompat" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
34+ new AarInfo ( "gridlayout-v7" , "v7-gridlayout" , "Xamarin.Android.Support.v7.GridLayout" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
35+ new AarInfo ( "mediarouter-v7" , "v7-mediarouter" , "Xamarin.Android.Support.v7.MediaRouter" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
36+ new AarInfo ( "recyclerview-v7" , "v7-recyclerview" , "Xamarin.Android.Support.v7.RecyclerView" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
37+ new AarInfo ( "palette-v7" , "v7-palette" , "Xamarin.Android.Support.v7.Palette" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
38+ new AarInfo ( "cardview-v7" , "v7-cardview" , "Xamarin.Android.Support.v7.CardView" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
39+ new AarInfo ( "leanback-v17" , "v17-leanback" , "Xamarin.Android.Support.v17.Leanback" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
40+ new AarInfo ( "design" , "design" , "Xamarin.Android.Support.Design" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
41+ new AarInfo ( "percent" , "percent" , "Xamarin.Android.Support.Percent" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
42+ new AarInfo ( "customtabs" , "customtabs" , "Xamarin.Android.Support.CustomTabs" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
43+ new AarInfo ( "preference-v7" , "v7-preference" , "Xamarin.Android.Support.v7.Preference" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
44+ new AarInfo ( "preference-v14" , "v14-preference" , "Xamarin.Android.Support.v14.Preference" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
45+ new AarInfo ( "preference-leanback-v17" , "v17-preference-leanback" , "Xamarin.Android.Support.v17.Preference.Leanback" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
46+ new AarInfo ( "recommendation" , "recommendation" , "Xamarin.Android.Support.Recommendation" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
47+ new AarInfo ( "animated-vector-drawable" , "animated-vector-drawable" , "Xamarin.Android.Support.Animated.Vector.Drawable" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
48+ new AarInfo ( "support-vector-drawable" , "vector-drawable" , "Xamarin.Android.Support.Vector.Drawable" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
49+ new AarInfo ( "support-compat" , "support-compat" , "Xamarin.Android.Support.Compat" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
50+ new AarInfo ( "support-core-utils" , "support-core-utils" , "Xamarin.Android.Support.Core.Utils" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
51+ new AarInfo ( "support-core-ui" , "support-core-ui" , "Xamarin.Android.Support.Core.UI" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
52+ new AarInfo ( "support-media-compat" , "support-media-compat" , "Xamarin.Android.Support.Media.Compat" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
53+ new AarInfo ( "support-fragment" , "support-fragment" , "Xamarin.Android.Support.Fragment" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
54+ new AarInfo ( "transition" , "transition" , "Xamarin.Android.Support.Transition" , AAR_VERSION , NUGET_VERSION , COMPONENT_VERSION ) ,
3555} ;
3656
57+ class AarInfo
58+ {
59+ public AarInfo ( string dir , string path , string nugetId , string aarVersion , string nugetVersion , string componentVersion )
60+ {
61+ Dir = dir;
62+ Path = path;
63+ NugetId = nugetId;
64+ AarVersion = aarVersion;
65+ NuGetVersion = nugetVersion;
66+ ComponentVersion = componentVersion;
67+ }
68+
69+ public string Dir { get ; set ; }
70+ public string Path { get ; set ; }
71+ public string NugetId { get ; set ; }
72+ public string AarVersion { get ; set ; }
73+ public string NuGetVersion { get ; set ; }
74+ public string ComponentVersion { get ; set ; }
75+ }
76+
3777var MONODROID_PATH = "/ Library / Frameworks / Xamarin . Android . framework / Versions / Current / lib / mandroid / platforms / " + ANDROID_SDK_VERSION + " / ";
3878if ( IsRunningOnWindows ( ) )
3979 MONODROID_PATH = MakeAbsolute ( new DirectoryPath ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFilesX86 ) ) . Combine ( "Reference Assemblies/Microsoft/Framework/MonoAndroid/" + ANDROID_SDK_VERSION + "/" ) ) . FullPath ;
@@ -154,11 +194,15 @@ var buildSpec = new BuildSpec {
154194} ;
155195
156196
197+ var NUGET_SOURCES = EnvironmentVariable ( "NUGET_SOURCES" ) ?? string . Empty ;
198+ if ( ! string . IsNullOrEmpty ( NUGET_SOURCES ) )
199+ buildSpec. NuGetSources = NUGET_SOURCES . Split ( ';' , ',' ) . Select ( ns => new NuGetSource { Url = ns } ) . ToArray ( ) ;
157200
158201// You shouldn't have to configure anything below here
159202// ######################################################
160203
161204Task ( "externals" )
205+ . IsDependentOn ( "externals-base" )
162206 . WithCriteria ( ( ) => ! FileExists ( "./externals/support-v4/classes.jar" ) ) . Does ( ( ) =>
163207{
164208 var path = "./externals/" ;
@@ -173,15 +217,16 @@ Task ("externals")
173217 Unzip ( path + "m2repository.zip" , path ) ;
174218
175219 // Copy the .aar's to a better location
176- foreach ( var aar in AAR_DIRS ) {
177- CopyFile ( string . Format ( path + "m2repository/com/android/support/{0}/{1}/{2}-{3}.aar" , aar , AAR_VERSION , aar , AAR_VERSION ) ,
178- string . Format ( path + "{0}.aar" , aar ) ) ;
179- Unzip ( string . Format ( path + "{0}.aar" , aar ) , path + aar ) ;
220+ foreach ( var aar in AAR_INFOS ) {
221+ var aarDir = aar . Dir ;
222+ CopyFile ( string . Format ( path + "m2repository/com/android/support/{0}/{1}/{2}-{3}.aar" , aarDir , AAR_VERSION , aarDir , AAR_VERSION ) ,
223+ string . Format ( path + "{0}.aar" , aarDir ) ) ;
224+ Unzip ( string . Format ( path + "{0}.aar" , aarDir ) , path + aarDir ) ;
180225
181- var implFile = path + aar + "/libs/internal_impl-" + AAR_VERSION + ".jar" ;
226+ var implFile = path + aarDir + "/libs/internal_impl-" + AAR_VERSION + ".jar" ;
182227
183228 if ( FileExists ( implFile ) )
184- MoveFile ( implFile , path + aar + "/libs/internal_impl.jar" ) ;
229+ MoveFile ( implFile , path + aarDir + "/libs/internal_impl.jar" ) ;
185230 }
186231
187232 // Get android docs
@@ -265,7 +310,73 @@ Task ("component-setup").Does (() =>
265310 }
266311} ) ;
267312
268- Task ( "component" ) . IsDependentOn ( "component-docs" ) . IsDependentOn ( "component-setup" ) . IsDependentOn ( "component-base" ) ;
313+ Task ( "nuget-setup" ) . Does ( ( ) => {
314+ var templateText = FileReadText ( "./template.targets" ) ;
315+
316+ if ( FileExists ( "./generated.targets" ) )
317+ DeleteFile ( "./generated.targets" ) ;
318+
319+ foreach ( var aar in AAR_INFOS ) {
320+
321+ var msName = aar . Dir . Replace ( "-" , "" ) ;
322+
323+ var items = new Dictionary < string , string > {
324+ { "_XbdUrl_" , "_XbdUrl_" + msName } ,
325+ { "_XbdSha1_" , "_XbdSha1_" + msName } ,
326+ { "_XbdKey_" , "_XbdKey_" + msName } ,
327+ { "_XbdAarFile_" , "_XbdAarFile_" + msName } ,
328+ { "_XbdAarFileInSdk_" , "_XbdAarFileInSdk_" + msName } ,
329+ { "_XbdAssemblyName_" , "_XbdAssemblyName_" + msName } ,
330+ { "_XbdAarFileFullPath_" , "_XbdAarFileFullPath_" + msName } ,
331+ { "_XbdRestoreItems_" , "_XbdRestoreItems_" + msName } ,
332+ { "$XbdUrl$" , M2_REPOSITORY_URL } ,
333+ { "$XbdSha1$" , M2_REPOSITORY_SHA1 } ,
334+ { "$XbdKey$" , "androidsupport-" + AAR_VERSION } ,
335+ { "$XbdAssemblyName$" , aar . NugetId } ,
336+ { "$AarKey$" , aar . Dir } ,
337+ { "$AarVersion$" , aar . AarVersion }
338+ } ;
339+
340+ var targetsText = templateText ;
341+
342+ foreach ( var kvp in items )
343+ targetsText = targetsText . Replace ( kvp . Key , kvp . Value ) ;
344+
345+ var targetsFile = string . Format ( "{0}/nuget/{1}.targets" , aar . Path , aar . NugetId ) ;
346+ FileWriteText ( targetsFile , targetsText ) ;
347+
348+ // Merge each generated targets file into one main one
349+ // this makes one file to import into our actual binding projects
350+ // which is much easier/less maintenance
351+ if ( ! FileExists ( "./generated.targets" ) )
352+ FileWriteText ( "./generated.targets" , "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n <Project ToolsVersion=\" 4.0\" xmlns=\" http://schemas.microsoft.com/developer/msbuild/2003\" >\n </Project>" ) ;
353+
354+ // Load the doc to append to, and the doc to append
355+ var xFileRoot = System . Xml . Linq . XDocument . Load ( "./generated.targets" ) ;
356+ System . Xml . Linq . XNamespace nsRoot = xFileRoot . Root . Name . Namespace ;
357+ var xFileChild = System . Xml . Linq . XDocument . Load ( targetsFile ) ;
358+ System . Xml . Linq . XNamespace nsChild = xFileRoot . Root . Name . Namespace ;
359+
360+ // Add all the elements under <Project> into the existing file's <Project> node
361+ foreach ( var xItemToAdd in xFileChild . Element ( nsChild + "Project" ) . Elements ( ) )
362+ xFileRoot . Element ( nsRoot + "Project" ) . Add ( xItemToAdd ) ;
363+
364+ // Inject a property to prevent errors from missing assemblies in .targets
365+ // this allows us to use one big .targets file in all the projects and not have to figure out which specific
366+ // ones each project needs to reference for development purposes
367+ if ( ! xFileRoot . Descendants ( nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly" ) . Any ( ) ) {
368+ xFileRoot . Element ( nsRoot + "Project" )
369+ . AddFirst ( new System . Xml . Linq . XElement ( nsRoot + "PropertyGroup" ,
370+ new System . Xml . Linq . XElement ( nsRoot + "XamarinBuildResourceMergeThrowOnMissingAssembly" , false ) ) ) ;
371+ }
372+
373+ xFileRoot . Save ( "./generated.targets" ) ;
374+ }
375+ } ) ;
376+
377+ Task ( "nuget" ) . IsDependentOn ( "nuget-setup" ) . IsDependentOn ( "nuget-base" ) . IsDependentOn ( "libs" ) ;
378+
379+ Task ( "component" ) . IsDependentOn ( "component-docs" ) . IsDependentOn ( "component-setup" ) . IsDependentOn ( "component-base" ) . IsDependentOn ( "libs" ) ;
269380
270381Task ( "clean" ) . IsDependentOn ( "clean-base" ) . Does ( ( ) =>
271382{
@@ -341,7 +452,7 @@ Task ("component-docs").Does (() =>
341452 }
342453} ) ;
343454
344- Task ( "libs" ) . IsDependentOn ( "genapi" ) ;
455+ Task ( "libs" ) . IsDependentOn ( "genapi" ) . IsDependentOn ( "nuget-setup" ) ;
345456
346457Task ( "genapi" ) . IsDependentOn ( "libs-base" ) . IsDependentOn ( "externals" ) . Does ( ( ) => {
347458
0 commit comments