Skip to content

Commit c87ef95

Browse files
[Xamarin.Android.Build.Tasks] deprecate %(ProjectReference.IsAppExtension) (#4900)
Context: https://developer.android.com/training/wearables/apps/standalone-apps Going forward in .NET 5+, we will be dropping support for embedding Android Wear applications inside a "main" application. From a `Foo.Android.csproj` you can: <ProjectReference Include="..\Foo.Wear\Foo.Wear.csproj"> <IsAppExtension>True</IsAppExtension> </ProjectReference> This would embed `com.foo.wear.apk` *inside* `com.foo.android.apk` in `Resources/raw`. We are removing this functionality in .NET 5+ because Google [states that][0]: > A watch APK should be distributed using [multiple APKs]; > do not embed a watch APK in a phone APK. This advice is the recommendation for Android Wear 2.0+ (API-25+), released on 2016-Oct-19, or ~3.5+ years ago. Given that standalone APK files have been the recommendation for such a long period of time, we see no reason to continue supporting the Wear 1.0 apps when building apps with .NET 5+. Xamarin.Android 11.x will continue to support the "embedding" Wear 1.0 apps into their referencing `App.apk` packages, but doing so will now elicit an XA4312 warning message, so that developers can begin migrating their projects for eventual support under .NET 6. warning XA4312: Referencing an Android Wear application project from an Android application project is deprecated. I moved the relevant MSBuild targets to `Xamarin.Android.Wear.targets`, which is only imported by "legacy" Xamarin.Android projects. .NET 5+ projects will not even import this file. `WearTests.cs` can now run under `dotnet` context.
1 parent b987d1b commit c87ef95

28 files changed

+294
-83
lines changed

Documentation/guides/DotNet5.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ If Java binding is enabled with `@(InputJar)`, `@(EmbeddedJar)`,
102102
`@(LibraryProjectZip)`, etc. then `$(AllowUnsafeBlocks)` will default
103103
to `True`.
104104

105+
Referencing an Android Wear project from an Android application will
106+
not be supported:
107+
108+
```xml
109+
<ProjectReference Include="..\Foo.Wear\Foo.Wear.csproj">
110+
<IsAppExtension>True</IsAppExtension>
111+
</ProjectReference>
112+
```
113+
105114
[rids]: https://docs.microsoft.com/dotnet/core/rid-catalog
106115
[abet-sys]: https://github.com/xamarin/xamarin-android/issues/4127
107116

Documentation/guides/messages/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ ms.date: 01/24/2020
152152
+ [XA4309](xa4309.md): 'MultiDexMainDexList' file '{file}' does not exist.
153153
+ [XA4310](xa4310.md): \`$(AndroidSigningKeyStore)\` file \`{keystore}\` could not be found.
154154
+ XA4311: The application won't contain the paired Wear package because the Wear application package APK is not created yet. If building on the command line, be sure to build the "SignAndroidPackage" target.
155+
+ [XA4312](xa4312.md): Referencing an Android Wear application project from an Android application project is deprecated.
155156

156157
## XA5xxx: GCC and toolchain
157158

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Xamarin.Android error/warning XA4312
3+
description: XA4312 error/warning code
4+
ms.date: 07/07/2020
5+
---
6+
# Xamarin.Android error/warning XA4312
7+
8+
Referencing an [Android Wear][0] application project from an Android
9+
application project is deprecated.
10+
11+
From a `Foo.Android.csproj` in past versions of Xamarin.Android, you
12+
could reference a `Foo.Wear.csproj` such as:
13+
14+
```xml
15+
<ProjectReference Include="..\Foo.Wear\Foo.Wear.csproj">
16+
<IsAppExtension>True</IsAppExtension>
17+
</ProjectReference>
18+
```
19+
20+
This would embed `com.foo.wear.apk` *inside* `com.foo.android.apk` in
21+
`Resources/raw`.
22+
23+
## Solution
24+
25+
Distribute `Foo.Wear.csproj` in the above example as a [standalone][1]
26+
Android Wear application instead.
27+
28+
[0]: https://docs.microsoft.com/xamarin/android/wear/get-started/intro-to-wear
29+
[1]: https://developer.android.com/training/wearables/apps/standalone-apps
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#### Deprecation of Android Wear Embedding
2+
3+
* warning XA4312: Embedding an [Android Wear][0] application inside an
4+
Android application is deprecated. Distribute the Wear application
5+
as a [standalone application][1] instead.
6+
7+
From a `Foo.Android.csproj` Xamarin.Android project, you could
8+
reference a `Foo.Wear.csproj` such as:
9+
10+
```xml
11+
<ProjectReference Include="..\Foo.Wear\Foo.Wear.csproj">
12+
<Name>Wearable</Name>
13+
<IsAppExtension>True</IsAppExtension>
14+
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
15+
</ProjectReference>
16+
```
17+
18+
This would embed `com.foo.wear.apk` *inside* `com.foo.android.apk` in
19+
`Resources/raw`.
20+
21+
Distribute `Foo.Wear.csproj` in the above example as a [standalone][1]
22+
Android Wear application instead.
23+
24+
##### Android Wear 1.x
25+
26+
Note that only Android Wear 2.0 and higher is supported by
27+
Xamarin.Android. Android Wear 1.x applications fail to compile with:
28+
29+
```
30+
error XA0121: Assembly 'Xamarin.Android.Wearable' is using '[assembly: Java.Interop.JavaLibraryReferenceAttribute]', which is no longer supported. Use a newer version of this NuGet package or notify the library author.
31+
error XA0121: Assembly 'Xamarin.Android.Wearable' is using '[assembly: Android.IncludeAndroidResourcesFromAttribute]', which is no longer supported. Use a newer version of this NuGet package or notify the library author.
32+
```
33+
34+
[0]: https://docs.microsoft.com/xamarin/android/wear/get-started/intro-to-wear
35+
[1]: https://developer.android.com/training/wearables/apps/standalone-apps

build-tools/installers/create-installers.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Tools.JavadocImporter.pdb" />
259259
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Tools.Versions.props" />
260260
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.VisualBasic.targets" />
261+
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Android.Wear.targets" Condition=" '$(PackageId)' != 'Microsoft.Android.Sdk' " />
261262
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Build.AsyncTask.dll" />
262263
<_MSBuildFiles Include="$(MSBuildSrcDir)\Xamarin.Build.AsyncTask.pdb" />
263264
<_MSBuildFiles Include="$(MSBuildSrcDir)\K4os.Compression.LZ4.dll" />
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<!--
2+
***********************************************************************************************
3+
Xamarin.Android.Wear.targets
4+
5+
This file contains MSBuild targets related to Android Wear.
6+
7+
This file is only used by "legacy" Xamarin.Android projects.
8+
9+
***********************************************************************************************
10+
-->
11+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12+
13+
<UsingTask TaskName="Xamarin.Android.Tasks.ParseAndroidWearProjectAndManifest" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
14+
<UsingTask TaskName="Xamarin.Android.Tasks.PrepareWearApplicationFiles" AssemblyFile="Xamarin.Android.Build.Tasks.dll" />
15+
16+
<PropertyGroup>
17+
<WearAppTarget>SignAndroidPackage</WearAppTarget>
18+
</PropertyGroup>
19+
20+
<Target Name="_PrepareWearApplication"
21+
Condition=" $(AndroidApplication) And '@(_AppExtensionReference)' != '' "
22+
DependsOnTargets="_ValidateAndroidPackageProperties">
23+
<ParseAndroidWearProjectAndManifest ProjectFiles="@(_AppExtensionReference)">
24+
<Output TaskParameter="ApplicationManifestFile" PropertyName="BundledWearApplicationManifestFile" />
25+
<Output TaskParameter="ApplicationPackageName" PropertyName="BundledWearApplicationPackageName" />
26+
</ParseAndroidWearProjectAndManifest>
27+
<CreateProperty
28+
Condition=" $(WearAppTarget) == 'SignAndroidPackage' And '$(AndroidKeyStore)'=='True' "
29+
Value="AndroidKeyStore=True;AndroidSigningKeyStore=$([System.IO.Path]::GetFullPath ('$(AndroidSigningKeyStore)'));AndroidSigningStorePass=$(AndroidSigningStorePass);AndroidSigningKeyAlias=$(AndroidSigningKeyAlias);AndroidSigningKeyPass=$(AndroidSigningKeyPass)">
30+
<Output TaskParameter="Value" PropertyName="_AdditionaEmbeddedWearAppProperties" />
31+
</CreateProperty>
32+
<MSBuild Projects="@(_AppExtensionReference)" Properties="Configuration=$(Configuration);AndroidUseSharedRuntime=False;EmbedAssembliesIntoApk=True;$(_AdditionaEmbeddedWearAppProperties)" Targets="Build;SignAndroidPackage"/>
33+
<CreateProperty
34+
Condition="$(BundledWearApplicationApkPath) == '' And ($(WearAppTarget) == 'SignAndroidPackage' Or !Exists('%(_AppExtensionReference.RootDir)%(_AppExtensionReference.Directory)$(_AndroidDebugKeyStoreFlag)'))"
35+
Value="%(_AppExtensionReference.RootDir)%(_AppExtensionReference.Directory)bin\$(Configuration)\$(BundledWearApplicationPackageName)-Signed.apk">
36+
<Output TaskParameter="Value" PropertyName="BundledWearApplicationApkPath" />
37+
</CreateProperty>
38+
<CreateProperty
39+
Condition="$(BundledWearApplicationApkPath) == '' And $(WearAppTarget) == 'PackageForAndroid' And Exists('%(_AppExtensionReference.RootDir)%(_AppExtensionReference.Directory)$(_AndroidDebugKeyStoreFlag)')"
40+
Value="%(_AppExtensionReference.RootDir)%(_AppExtensionReference.Directory)bin\$(Configuration)\$(BundledWearApplicationPackageName).apk">
41+
<Output TaskParameter="Value" PropertyName="BundledWearApplicationApkPath" />
42+
</CreateProperty>
43+
<PrepareWearApplicationFiles
44+
PackageName="$(_AndroidPackage)"
45+
IntermediateOutputPath="$(IntermediateOutputPath)"
46+
AndroidLibraryFlatFilesDirectory="$(_AndroidLibraryFlatFilesDirectory)"
47+
WearAndroidManifestFile="$(BundledWearApplicationManifestFile)"
48+
WearApplicationApkPath="$(BundledWearApplicationApkPath)">
49+
<Output TaskParameter="WearableApplicationDescriptionFile" ItemName="_WearableApplicationDescriptionFile" />
50+
<Output TaskParameter="BundledWearApplicationApkResourceFile" ItemName="_BundledWearApplicationApkResourceFile" />
51+
<Output TaskParameter="ModifiedFiles" ItemName="_ModifiedResources" />
52+
</PrepareWearApplicationFiles>
53+
<!-- in case there is no actual wear apk to be bundled, we don't generate wear_app_desc.xml and we shouldn't modify AndroidManifest.xml as if it had the apk -->
54+
<CreateProperty Value=""
55+
Condition=" '@(_WearableApplicationDescriptionFile)' == '' ">
56+
<Output TaskParameter="Value" PropertyName="BundledWearApplicationPackageName" />
57+
</CreateProperty>
58+
</Target>
59+
60+
<Target Name="SetWearAppTargetToPackageForAndroid">
61+
<CreateProperty Value="PackageForAndroid">
62+
<Output TaskParameter="Value" PropertyName="WearAppTarget" />
63+
</CreateProperty>
64+
</Target>
65+
66+
</Project>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BuildOrder.targets

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
3333
$(_AfterCompileDex);
3434
_AddFilesToFileWrites;
3535
</_BeforeIncrementalClean>
36+
<_PackageForAndroidDependsOn>
37+
Build;
38+
_CopyPackage;
39+
</_PackageForAndroidDependsOn>
3640
</PropertyGroup>
3741

3842
<PropertyGroup Condition=" '$(AndroidApplication)' != 'True' ">
@@ -56,14 +60,10 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
5660

5761
<!-- Targets that run unless we are running _ComputeFilesToPublishForRuntimeIdentifiers -->
5862
<PropertyGroup Condition=" '$(_ComputeFilesToPublishForRuntimeIdentifiers)' != 'true' ">
59-
<CoreResolveReferencesDependsOn>
63+
<ResolveReferencesDependsOn>
6064
_SeparateAppExtensionReferences;
61-
_PrepareWearApplication;
6265
$(ResolveReferencesDependsOn);
6366
_AddAndroidCustomMetaData;
64-
</CoreResolveReferencesDependsOn>
65-
<ResolveReferencesDependsOn>
66-
$(CoreResolveReferencesDependsOn);
6767
UpdateAndroidInterfaceProxies;
6868
UpdateAndroidResources;
6969
AddBindingsToCompile;

src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ In this message, the term "bundled" is a short way of saying "included into the
654654
<value>The application won't contain the paired Wear package because the Wear application package APK is not created yet. If building on the command line, be sure to build the "SignAndroidPackage" target.</value>
655655
<comment>The following are literal names and should not be translated: Wear, APK, SignAndroidPackage
656656
"Wear" is a short version of the full product name "Wear OS" and so should not be translated.</comment>
657+
</data>
658+
<data name="XA4312" xml:space="preserve">
659+
<value>Referencing the Android Wear application project '{0}' from an Android application project is deprecated and will no longer be supported in a future version of Xamarin.Android. Remove the Android Wear application project reference from the Android application project and distribute the Wear application as a standalone application instead.</value>
660+
<comment>The following are literal names and should not be translated: Android Wear, Android, Wear.
661+
{0} - The referenced Android Wear project.</comment>
657662
</data>
658663
<data name="XA5101" xml:space="preserve">
659664
<value>Missing Android NDK toolchains directory '{0}'. Please install the Android NDK.</value>

src/Xamarin.Android.Build.Tasks/Properties/xlf/Resources.cs.xlf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ In this message, the term "bundled" is a short way of saying "included into the
656656
<target state="translated">Aplikace nebude obsahovat spárovaný balíček Wear, protože ještě není vytvořen soubor APK pro balíček aplikace Wear. Při sestavování na příkazovém řádku nezapomeňte sestavit cíl SignAndroidPackage.</target>
657657
<note>The following are literal names and should not be translated: Wear, APK, SignAndroidPackage
658658
"Wear" is a short version of the full product name "Wear OS" and so should not be translated.</note>
659+
</trans-unit>
660+
<trans-unit id="XA4312">
661+
<source>Referencing the Android Wear application project '{0}' from an Android application project is deprecated and will no longer be supported in a future version of Xamarin.Android. Remove the Android Wear application project reference from the Android application project and distribute the Wear application as a standalone application instead.</source>
662+
<target state="new">Referencing the Android Wear application project '{0}' from an Android application project is deprecated and will no longer be supported in a future version of Xamarin.Android. Remove the Android Wear application project reference from the Android application project and distribute the Wear application as a standalone application instead.</target>
663+
<note>The following are literal names and should not be translated: Android Wear, Android, Wear.
664+
{0} - The referenced Android Wear project.</note>
659665
</trans-unit>
660666
<trans-unit id="XA5101">
661667
<source>Missing Android NDK toolchains directory '{0}'. Please install the Android NDK.</source>

0 commit comments

Comments
 (0)