Skip to content

Commit 7dd1f3d

Browse files
committed
[build] Use $(AndroidPlatformId) when appropriate
Context: 485e39b Context: eb08bb4 ...and doubtless others... Three MSBuild properties control the `android.jar` which is bound and the `$(TargetFrameworkVersion)` of `Mono.Android.dll`: * `$(AndroidApiLevel)`: The API level that is bound. Must be an int. * `$(AndroidFrameworkVersion)`: The `$(TargetFrameworkVersion)` of the generated `Mono.Android.dll`. Must be *mostly* parseable by `System.Version` except with a leading `v`, e.g. `v10.0`. * `$(AndroidPlatformId)`: The "ID" of the API level. *Most* of the time, `$(AndroidApiLevel)` and `$(AndroidPlatformId)` will be *identical*: for API-29, they're both `29`. Where they differ is for new *preview* API levels, such as API-R: `$(AndroidApiLevel)` will be 30, but `$(AndroidPlatformId)` is `R`. The distinction is important because various filesystem paths within the Android SDK use the "id" and *not* the API level when they differ, e.g. the API-R `android.jar` is installed into: $(AndroidSdkDirectory)/platforms/android-R/android.jar We thus need to be *careful* when distinguishing between `$(AndroidApiLevel)` and `$(AndroidPlatformId)`, using the former when an integer is *required*, and using the latter whenever it refers to filesystem paths. Unfortunately, we *haven't* been careful, because these values really only differ for ~4 months out of the year, and for only one `$(TargetFrameworkVersion)` version. Start bringing some sanity...and finding bugs while we do so: `api-xml-adjuster.targets` should use `%(AndroidApiInfo.Id)` and *not* `%(AndroidApiLevel.Level)`, as it references filesystem locations. Consequently, `src/Mono.Android/Profiles/api-30.params.txt` must be renamed to `src/Mono.Android/Profiles/api-R.params.txt` so that it correctly embeds the `$(AndroidPlatformId)` value. `Mono.Android.targets` should likewise use `$(AndroidPlatformId)` and not `$(AndroidApiLevel)` when using filesystem paths from the SDK. For good measure, `Mono.Android.csproj` now overrides `$(IntermediateOutputPath)` to contain `$(AndroidPlatformId)`, because why not (MOAR CONSISTENCY!). These changes, unfortunately, introduce breakage, which will need to be addressed: *Because* API-R was installed into `$(AndroidSdkDirectory)/platforms/android-R`, `api-versions.xml` *was not previously used* because `Mono.Android.targets` was using `$(AndroidApiLevel)`, and `platforms/android-30/data/api-version.xml` does not yet exist. (It will come June! But not now.) As it didn't exist, it hit the fallback path and used `platform-tools/api/api-versions.xml` (4cd2060). You would *think* this wouldn't be a problem, but the API-R `api-versions.xml` is *missing* members relative to platform-tools, resulting in members *missing* `RegisterAttribute.ApiSince` values, which `Microsoft.DotNet.ApiCompat.exe` reports, e.g.: CannotChangeAttribute : Attribute 'Android.Runtime.RegisterAttribute' on 'Java.Lang.StringBuilder.TrimToSize()' changed from '[RegisterAttribute("trimToSize", "()V", "", ApiSince=9)]' in the contract to '[RegisterAttribute("trimToSize", "()V", "")]' in the implementation dotnet/java-interop@568d24ac added support to allow `generator --apiversions` to be specified multiple times. Take advantage of this new support to pass in the `api-versions.xml` files from *both* `platforms/android-R` *and* `platform-tools/api`. This works around the deficiency in API-R's `api-versions.xml` and allows us to retain correct `RegisterAttribute.ApiSince` values. Aside: to manually build the API-R binding, use: msbuild /p:AndroidPlatformId=R /p:AndroidApiLevel=30 /p:AndroidFrameworkVersion=v10.0.99 src/Mono.Android/Mono.Android.csproj /v:diag > b.txt
1 parent 12df2be commit 7dd1f3d

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

build-tools/api-xml-adjuster/api-xml-adjuster.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</_Api>
1616
</ItemGroup>
1717
<CreateItem Include="@(_Api)"
18-
AdditionalMetadata="ParameterDescription=$(_TopDir)\src\Mono.Android\Profiles\api-%(_Api.Level).params.txt;ClassParseXml=$(_OutputPath)api\api-%(_Api.Level).xml.class-parse;ApiAdjustedXml=$(_OutputPath)api\api-%(_Api.Level).xml.in">
18+
AdditionalMetadata="ParameterDescription=$(_TopDir)\src\Mono.Android\Profiles\api-%(_Api.Id).params.txt;ClassParseXml=$(_OutputPath)api\api-%(_Api.Id).xml.class-parse;ApiAdjustedXml=$(_OutputPath)api\api-%(_Api.Id).xml.in">
1919
<Output TaskParameter="Include" ItemName="ApiFileDefinition"/>
2020
</CreateItem>
2121
</Target>

src/Mono.Android/Mono.Android.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
9898
<PropertyGroup>
9999
<ImplicitlyExpandDesignTimeFacades>False</ImplicitlyExpandDesignTimeFacades>
100-
<IntermediateOutputPath>$(IntermediateOutputPath)android-$(AndroidApiLevel)\</IntermediateOutputPath>
100+
<IntermediateOutputPath>$(IntermediateOutputPath)android-$(AndroidPlatformId)\</IntermediateOutputPath>
101101
</PropertyGroup>
102102
<Import Project="Mono.Android.targets" />
103103
<PropertyGroup>

src/Mono.Android/Mono.Android.targets

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@
7878
Inputs="metadata;enumflags;map.csv;methodmap.csv;$(IntermediateOutputPath)mcw\api.xml"
7979
Outputs="$(IntermediateOutputPath)mcw\Mono.Android.projitems">
8080
<MakeDir Directories="$(IntermediateOutputPath)mcw" />
81-
<PropertyGroup>
82-
<_ApiVersions Condition="Exists('$(AndroidSdkDirectory)\platforms\android-$(AndroidApiLevel)\data\api-versions.xml')">"$(AndroidSdkDirectory)\platforms\android-$(AndroidApiLevel)\data\api-versions.xml"</_ApiVersions>
83-
<_ApiVersions Condition="'$(_ApiVersions)'==''">"$(AndroidSdkDirectory)\platform-tools\api\api-versions.xml"</_ApiVersions>
84-
</PropertyGroup>
81+
<ItemGroup>
82+
<_ApiVersion Include="$(AndroidSdkDirectory)\platform-tools\api\api-versions.xml" />
83+
<_ApiVersion
84+
Condition="Exists('$(AndroidSdkDirectory)\platforms\android-$(AndroidPlatformId)\data\api-versions.xml')"
85+
Include="$(AndroidSdkDirectory)\platforms\android-$(AndroidPlatformId)\data\api-versions.xml"
86+
/>
87+
</ItemGroup>
8588
<PropertyGroup>
8689
<Generator>"$(XAInstallPrefix)xbuild\Xamarin\Android\generator.exe"</Generator>
8790
<_GenFlags>--public --product-version=7</_GenFlags>
@@ -91,7 +94,7 @@
9194
<_Fixup>--fixup=metadata</_Fixup>
9295
<_Enums1>--preserve-enums --enumflags=enumflags --enumfields=map.csv --enummethods=methodmap.csv</_Enums1>
9396
<_Enums2>--enummetadata=$(IntermediateOutputPath)mcw\enummetadata</_Enums2>
94-
<_Versions>--apiversions=$(_ApiVersions)</_Versions>
97+
<_Versions>@(_ApiVersion->'--apiversions="%(Identity)"', ' ')</_Versions>
9598
<_Annotations>--annotations="$(AndroidSdkDirectory)\platform-tools\api\annotations.zip"</_Annotations>
9699
<_Assembly>--assembly="Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"</_Assembly>
97100
<_TypeMap>--type-map-report=$(IntermediateOutputPath)mcw\type-mapping.txt</_TypeMap>

0 commit comments

Comments
 (0)