Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Improved Fast Deployment (#609)
Browse files Browse the repository at this point in the history
Context: https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/#Fast_Deployment
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=55050

What do we want?  To fast deploy *all the things*!  Not just
assemblies, as is currently supported, but `.dex` files,
Android resources, Android assets, shared libraries (`.so` files),
the works.  If we can avoid updating and re-installing the `.apk`,
we want to do so.

TODO: Support Fast Deployment of `.jm` and `.mj` files; see
#1917

*How* do we do that?  Previously, we used `StubApplication.java`,
which would "work some magic" to better support loading types from
multiple `.dex` files, allow loading Android Resources from multiple
locations, etc.  The problem with `StubApplication.java` is that it's
"too late" in process startup: certain constructs such as
`ContentProvider`s are created *before* the `andorid.app.Application`
instance is created, meaning those constructs couldn't be handled
like the rest of multidex.

Avoid that special case by "moving" the `StubApplication.java` logic
into the new `MultiDexLoader` types, which are `ContentProvider`s in
the spirit of `MonoRuntimeProvider`, and are thus created *before*
the `Application` is created.  This in turn allows `Application`
subclasses to be located *outside* the default `classes.dex` file
(multidex!), while still allowing the `Application` type to be
resolved and instantiated.

Add a new `ResourcePatcher` ContentProvider which "fixes up" various
Android types to permit looking up Android Resources from their
fast deployment locations.  Previously, resource patching required
that the Application be created, which prevented custom `Application`
types in a multidex environment (it couldn't be found).  Moving
Resource patching into a separate content provider allows separation
of responsibility, and supports custom `Application` subclasses.

Finally, rework `monodroid-glue.c` to copy over any `.so` files which
are found in the `.__override__` directory into the local app
directory, as **dlopen**(3) won't load `.so` files located outside of
the local app directory.  This enables fast deployment of native
libraries.
  • Loading branch information
dellis1972 authored and jonpryor committed Sep 25, 2018
1 parent 6c2cb23 commit 3f360c0
Show file tree
Hide file tree
Showing 43 changed files with 1,872 additions and 533 deletions.
1 change: 1 addition & 0 deletions build-tools/scripts/RunTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<_ApkTestProject Include="$(_TopDir)\tests\BCL-Tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\EmbeddedDSOs\EmbeddedDSO\EmbeddedDSO.csproj" />
<_ApkTestProject Include="$(_TopDir)\tests\Runtime-MultiDex\Mono.Android-TestsMultiDex.csproj" />
<_ApkTestProjectAot Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" />
<_ApkTestProjectBundle Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Exec
Condition=" '$(HostOS)' != 'Windows' And '$(_EmuTarget)' != '' "
ContinueOnError="WarnAndContinue"
IgnoreStandardErrorWarningFormat="true"
Command="kill -KILL $(_EmuPid)"
/>
</Target>
Expand Down
45 changes: 45 additions & 0 deletions src/Mono.Android/Test/Mono.Android-Test.Shared.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>{0AB4956E-6FB9-4DA0-9D49-AB65A3FF403A}</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Mono.Android-Test.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)\Resources\Resource.designer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Properties\AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.App\ApplicationTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Content\IntentTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Runtime\CharSequenceTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Runtime\JavaCollectionTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Runtime\JnienvArrayMarshaling.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Runtime\XmlReaderPullParserTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Runtime\XmlReaderResourceParserTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.Widget\AdapterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Java.Interop\JavaConvertTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Java.Lang\ObjectArrayMarshaling.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Java.Lang\ObjectTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Java.Interop\JnienvTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System\AppDomainTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System\AssemblyInformationalVersionAttributeTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System\ExceptionTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System\TimeZoneTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.IO\DriveInfoTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.IO.Compression\GZipStreamTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.Net\ProxyTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.Net\SslTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.Net\NetworkInterfaces.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\System.Threading\InterlockedTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Java.Interop\JavaObjectExtensionsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.Net\AndroidClientHandlerTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.Net\HttpClientIntegrationTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.RuntimeTests\MainActivity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.RuntimeTests\MyIntent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.RuntimeTests\NonJavaObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Xamarin.Android.RuntimeTests\TestInstrumentation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Android.OS\BundleTest.cs" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions src/Mono.Android/Test/Mono.Android-Test.Shared.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{0AB4956E-6FB9-4DA0-9D49-AB65A3FF403A}</ProjectGuid>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<Import Project="Mono.Android-Test.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions src/Mono.Android/Test/Mono.Android-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
</PropertyGroup>
<Import Project="Mono.Android-Test.Shared.projitems" Label="Shared" Condition="Exists('Mono.Android-Test.Shared.projitems')" />
<Import Project="..\..\..\Configuration.props" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
3 changes: 2 additions & 1 deletion src/Xamarin.Android.Build.Tasks.tpnitems
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
https://github.com/bazelbuild/bazel/tree/master/src/tools/android/java/com/google/devtools/build/android/incrementaldeployment
* Xamarin.Android.Build.Tasks/Resources/IncrementalClassLoader.java
* Xamarin.Android.Build.Tasks/Resources/Placeholder.java
* Xamarin.Android.Build.Tasks/Resources/StubApplication.java
* Xamarin.Android.Build.Tasks/Resources/MonkeyPatcher.java
* Xamarin.Android.Build.Tasks/Resources/ResourceLoader.java
-->
<ThirdPartyNotice Include="bazelbuild/bazel">
<LicenseFile>$(MSBuildThisFileDirectory)\..\build-tools\license-data\Apache-2.0.txt</LicenseFile>
Expand Down
Loading

0 comments on commit 3f360c0

Please sign in to comment.