Skip to content

Commit 9d4828a

Browse files
committed
[Xamarin.Android.Build.Tasks] Fast Deployment v2.0
Fixes #5009 Fixes #5147 Fixes #4996 The Fast Deployment system used for debugging Xamarin.Android apps has been completely re-written. This is mostly due to changes in the android OS which means we can no longer use the external storage directory to store assemblies. Fast Deployment works by not including files which change often, like assemblies, in the actual apk. This means the .apk will mostly not need to be re-installed during a debugging/development session. Instead the assemblies are "Fast Deployed" to a special directory where a debug version of our runtime knows where to find them. Historically this was on the external storage directory such as `/storage/emulated/0/Android/data/com.some.package` `/mnt/shell/emulated/0/Android/data/com.some.package` `/storage/sdcard/Android/data/com.some.package` With the advent of Android 11, these directories are no longer accessable. So instead we need to deploy the assemblies into the app internal `files` directory. This is usually located in `/data/data/com.some.package`. This is not a global writable folder, so we need to use the `run-as` tool to run all the commands to copy the files into that diectory. The `run-as` tool does not always work on older devices. So from this point on Fast Deployment will only be available on API 21 devices or newer. If a certain device does not support the `run-as` tool, then you can always fall back to debugging without Fast Deployment. While this is slower, it should still work on most devices. The [Enhanced Fast Deployment](~/android/deploy-test/building-apps/build-properties.md#AndroidFastDeploymentType) mode is still available with this new system. This will deploy both assemblies, native libraries, typemaps and dexes to the `files` directory. Support for Fast Deploying resources and assets via that system was removed in commit [f0d565f](f0d565f). This was becuase it required the use of depreicated API's to work. The Shared Runtime has also be removed in this new system. Before we used to deploy the BCL and API specific assemblies via seperate .apks. This new system removes the need for that. All the BCL and API specific assemblies will be deployed to the `files` directory like all the other assemblies. The new system is on par with the existing system when it comes to speed. More improvements are planned in future releases which should make it much quicker. Using the `samples\HelloWorld` project these are the performance differences using `HelloWorld.csproj /restore /t:Install /v:n` Old From Clean Time Elapsed 00:00:11.42 Old C# Change Time Elapsed 00:00:02.58 New From Clean Time Elapsed 00:00:11.78 New C# Change Time Elapsed 00:00:02.43
1 parent cdc35b6 commit 9d4828a

File tree

101 files changed

+412
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+412
-664
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:master@1ac5333ec5e90b4e1fb9b324714811effdede37f
1+
xamarin/monodroid:master@767f647151936303c294d154d0d0a4da8b601464
22
mono/mono:2020-02@be2226b5a1c57df065efc4c1cf008d581e5cec7d

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"bin/TestDebug/MSBuildDeviceIntegration/MSBuildDeviceIntegration.dll",
55
"bin/TestDebug/net472/Xamarin.Android.Build.Tests.dll",
66
"bin/TestDebug/Xamarin.Android.Build.Tests.Commercial.dll",
7+
"bin/TestRelease/MSBuildDeviceIntegration/MSBuildDeviceIntegration.dll",
78
],
89
"cmake.configureOnOpen": false
910
}

Documentation/guides/building-apps/build-process.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,35 @@ In broad terms, there are two types of Android application packages
3636
Not coincidentally, these match the MSBuild `Configuration` which
3737
produces the package.
3838

39-
## Shared Runtime
40-
41-
The *shared runtime* is a pair of additional Android packages which
42-
provide the Base Class Library (`mscorlib.dll`, etc.) and the
43-
Android binding library (`Mono.Android.dll`, etc.). Debug builds
44-
rely upon the shared runtime in lieu of including the Base Class Library and
45-
Binding assemblies within the Android application package, allowing the
46-
Debug package to be smaller.
47-
48-
The shared runtime may be disabled in Debug builds by setting the
49-
[`$(AndroidUseSharedRuntime)`](~/android/deploy-test/building-apps/build-properties.md#androidusesharedruntime)
50-
property to `False`.
51-
5239
<a name="Fast_Deployment"></a>
5340

5441
## Fast Deployment
5542

56-
*Fast deployment* works in concert with the shared runtime to further
57-
shrink the Android application package size. This is done by not
58-
bundling the app's assemblies within the package. Instead, they are
59-
copied onto the target via `adb push`. This process speeds up the
60-
build/deploy/debug cycle because if *only* assemblies are changed,
61-
the package is not reinstalled. Instead, only the updated assemblies are
62-
re-synchronized to the target device.
43+
*Fast deployment* works by further shrinking Android application
44+
package size. This is done by not bundling the app's assemblies
45+
within the package. Instead, the are deployed directly to the
46+
application internal `files` directory. This is usually located
47+
in `/data/data/com.some.package`. This is not a global writable
48+
folder, so we need to use the `run-as` tool to run all the
49+
commands to copy the files into that diectory.
6350

64-
Fast deployment is known to fail on devices which block `adb` from
65-
synchronizing to the directory
66-
`/data/data/@PACKAGE_NAME@/files/.__override__`.
51+
This process speeds up the build/deploy/debug cycle because
52+
if *only* assemblies are changed, the package is not reinstalled.
53+
Instead, only the updated assemblies are re-synchronized to the
54+
target device.
55+
56+
Fast deployment is known to fail on devices which block `run-as`. This
57+
is usually devices of API 20 and lower.
6758

6859
Fast deployment is enabled by default, and may be disabled in Debug builds
6960
by setting the `$(EmbedAssembliesIntoApk)` property to `True`.
7061

62+
The [Enhanced Fast Deployment](~/android/deploy-test/building-apps/build-properties.md#AndroidFastDeploymentType) mode can
63+
be used in conjunction with this feature to speed up deployments even further.
64+
This will deploy both assemblies, native libraries, typemaps and dexes to the `files`
65+
directory. But you should only really need to enable this if you are changing
66+
native libraries, bindings or Java code.
67+
7168
## MSBuild Projects
7269

7370
The Xamarin.Android build process is based on MSBuild, which is also

Documentation/guides/building-apps/build-properties.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ compiler.
418418

419419
Added in Xamarin.Android 10.2.
420420

421+
<a name="AndroidFastDeploymentType"></a>
422+
421423
## AndroidFastDeploymentType
422424

423425
A `:` (colon)-separated list
@@ -433,12 +435,16 @@ faster.) Valid values include:
433435

434436
- `Assemblies`: Deploy application assemblies.
435437

436-
- `Dexes`: Deploy `.dex` files, Android Resources, and Android
437-
Assets. **This value can *only* be used on devices running
438+
- `Dexes`: Deploy `.dex` files, native libraries and typemaps.
439+
**This value can *only* be used on devices running
438440
Android 4.4 or later (API-19).**
439441

440442
The default value is `Assemblies`.
441443

444+
Support for Fast Deploying resources and assets via that system was
445+
removed in commit [f0d565fe](https://github.com/xamarin/xamarin-android/commit/f0d565fe4833f16df31378c77bbb492ffd2904b9). This was becuase it required the use of
446+
deprecated API's to work.
447+
442448
**Experimental**. Added in Xamarin.Android 6.1.
443449

444450
## AndroidGenerateJniMarshalMethods
@@ -1003,18 +1009,6 @@ than `aapt`.
10031009

10041010
Added in Xamarin.Android 8.1.
10051011

1006-
## AndroidUseSharedRuntime
1007-
1008-
A boolean property that
1009-
determines whether the *shared runtime packages* are required in
1010-
order to run the Application on the target device. Relying on the
1011-
shared runtime packages allows the Application package to be
1012-
smaller, speeding up the package creation and deployment process,
1013-
resulting in a faster build/deploy/debug turnaround cycle.
1014-
1015-
This property should be `True` for Debug builds, and `False` for
1016-
Release projects.
1017-
10181012
## AndroidVersionCodePattern
10191013

10201014
A string property which allows

Documentation/guides/messages/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ ms.date: 01/24/2020
6969
+ [XA0122](xa0122.md): Assembly '{assembly}' is using a deprecated attribute '[assembly: Java.Interop.DoNotPackageAttribute]'. Use a newer version of this NuGet package or notify the library author.
7070
+ XA0123: Removing {issue} from {propertyName}. Lint {version} does not support this check.
7171
+ [XA0124](xa0124.md): Interpreter is not supported by the x86 ABI
72+
+ [XA0125](xa0125.md): `{Project}` is using a deprecated debug information level.
73+
Set the debugging information to Portable in the Visual Studio project property pages or edit the project file in a text editor and set the 'DebugType' MSBuild property to 'portable' to use the newer, cross-platform debug information level.
74+
If this file comes from a NuGet package, update to a newer version of the NuGet package or notify the library author.
75+
+ [XA0126](xa0126.md): Error installing FastDev Tools. This device does not support Fast Deployment. Please rebuild your app using `EmbedAssembliesIntoApk = True`.
76+
+ [XA0127](xa0127.md): There was an issue deploying {destination} using {FastDevTool}. We encountered the following error {output}. Please rebuild your app using `EmbedAssembliesIntoApk = True`.
77+
+ [XA0128](xa0128.md): Stdio Redirection is enabled. Please disable it to use Fast Deployment.
78+
+ [XA0129](xa0129.md): Error deploying `{File}`. Please disable fast deployment in the Visual Studio project property pages or edit the project file in a text editor and set the 'EmbedAssembliesIntoApk' MSBuild property to 'true'.
79+
+ [XA0130](xa0130.md): Sorry. Fast deployment is only supported on devices running Android 5.0 (API level 21) or higher.
80+
Please disable fast deployment in the Visual Studio project property pages or edit the project file in a text editor and set the 'EmbedAssembliesIntoApk' MSBuild property to 'true'.
7281

7382
## XA1xxx: Project related
7483

@@ -233,6 +242,7 @@ and `NNN` is a 3 digit number indicating the type of the unhandled `Exception`.
233242
* `DES` - `Desugar`
234243
* `DJL` - `DetermineJavaLibrariesToCompile`
235244
* `DX8` - `D8`
245+
* `FD` - `FastDeploy`
236246
* `FLB` - `FindLayoutsToBind`
237247
* `FLT` - `FilterAssemblies`
238248
* `GAD` - `GetAndroidDefineConstants`

Documentation/guides/messages/xa0119.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ Remove the following options from `Debug` configurations:
3131

3232
* `<AndroidLinkMode>None</AndroidLinkMode>`
3333
* `<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>`
34-
* `<AndroidUseSharedRuntime>True</AndroidUseSharedRuntime>`
3534

3635
*DO* use the following options for `Release` configurations:
3736

3837
* `<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>`
39-
* `<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>`
4038

4139
Consider submitting a [bug][bug] if you are getting one of these
4240
warnings under normal circumstances.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Xamarin.Android error XA0126
3+
description: XA0126 error code
4+
ms.date: 08/07/2020
5+
---
6+
# Xamarin.Android error XA0126
7+
8+
## Issue
9+
10+
This issue happens when you are trying to use fast deployment on a device which
11+
does not support it. Fast deployment requires features which are not available
12+
on devices running API 20 or lower. The Fast Deployment system makes use of the
13+
[`run-as`](https://android.googlesource.com/platform/system/core.git/+/refs/heads/master/run-as/run-as.cpp#42) feature of the Android OS. This feature was either not available or had
14+
limited capabilities in API 20 and earlier.
15+
16+
## Solution
17+
18+
Disable Fast Deployment by setting `EmbedAssembliesIntoApk = True` in your .csproj.
19+
Or turn off `Fast Deployment` in the IDE. You will still be able to debug on the device,
20+
all the required files will be packaged inside the .apk.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Xamarin.Android error XA0127
3+
description: XA0127 error code
4+
ms.date: 08/07/2020
5+
---
6+
# Xamarin.Android error XA0127
7+
8+
## Issue
9+
10+
If you encounter this issue something unexpected happened with the Fast Deployment
11+
native tooling. This is most likely to be a native crash.
12+
13+
## Solution
14+
15+
To work around the issue disable Fast Deployment by setting `EmbedAssembliesIntoApk = True`
16+
in your .csproj. Or turn off `Fast Deployment` in the IDE. You will still be able to debug
17+
on the device, all the required files will be packaged inside the .apk.
18+
19+
In addition raise an issue at [https://github.com/xamarin/xamarin-android/issues/new/choose](https://github.com/xamarin/xamarin-android/issues/new/choose). Please provide the deployment log and as much detail as possible.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Xamarin.Android error XA0128
3+
description: XA0128 error code
4+
ms.date: 08/07/2020
5+
---
6+
# Xamarin.Android error XA0128
7+
8+
## Issue
9+
10+
The Fast Deployment system relys on reading the output from the various system applications
11+
on the device. This is done by reading `System.out`, which by default is where all output
12+
will be redirected. If `log.redirect-stdio` this will cause all of the Fast Deployment tooling
13+
to fail.
14+
15+
## Solution
16+
17+
Disable the redirection of stdio in order to use Fast Deployment. This can be done using
18+
the following commands.
19+
20+
```
21+
adb shell stop
22+
adb shell setprop log.redirect-stdio false
23+
adb shell start
24+
```
25+
26+
Depending on the device you might need to run `adb root` before running the above commands.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: Xamarin.Android error XA0129
2+
description: XA0129 error code
3+
ms.date: 08/07/2020
4+
---
5+
# Xamarin.Android error XA0129
6+
7+
## Issue
8+
9+
This issue happens when you are trying to use fast deployment on a device which
10+
does not support it. In this case both the normal and backup types of fast
11+
deployment failed. The Fast Deployment system makes use of the
12+
[`run-as`](https://android.googlesource.com/platform/system/core.git/+/refs/heads/master/run-as/run-as.cpp#42) feature of the Android OS. This feature was either not available or had
13+
limited capabilities in API 20 and earlier
14+
15+
## Solution
16+
17+
Disable Fast Deployment by setting `EmbedAssembliesIntoApk = True` in your .csproj.
18+
Or turn off `Fast Deployment` in the IDE. You will still be able to debug on the device,
19+
all the required files will be packaged inside the .apk.

0 commit comments

Comments
 (0)