Prototype/proof of concept of a "lite" Xamarin.Android that only supports Xamarin.Forms.
DISCLAIMER: I created this project during Microsoft's #HackWeek 2018. It is not "a real thing" or endorsed/supported by Xamarin/Microsoft. If you would like it to be "a real thing", show your support! Star this Github repo, like the YouTube video, post on social media, comment, etc.! Every bit helps!
Download Xamarin.Android.Lite on NuGet
NOTE: in the video, I have MSBuild.exe
in my PATH
example on how
to do this here.
The path to my MSBuild is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
Mac users can just run msbuild
and it works...
The easiest way to create a new project, is to use the Xamarin.Forms
project template in Visual Studio. Just check one platform, use
NetStandard
, and delete the platform-specific project.
NOTE: shared projects won't work (or make sense), Xamarin.Android.Lite is for NetStandard only
Edit your project file to look something like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.png" />
<PackageReference Include="Xamarin.Android.Lite" Version="0.1.0.43-preview" />
</ItemGroup>
</Project>
Remove the existing <PackageReference />
to Xamarin.Forms from the
Xamarin.Forms project template, as Xamarin.Android.Lite is pinned to a
specific version of Xamarin.Forms.
To run the app:
SignAndroidPackage
,
Install
, or Run
.Details on each target:
SignAndroidPackage
drops an APK file in $(OutputPath)
Install
deploys the APK to the connected deviceRun
launches the main activity on the deviceSo, assuming the right MSBuild.exe
is in your path on Windows (Mac
will "just work"):
msbuild MyApp.csproj /t:Run
This command gets you going!
Visit the MSBuild documentation for further details about MSBuild (project) properties.
Comparing the Install
target deploying to an emulator and device
(Pixel 2). I deleted bin
/obj
and ran msbuild /t:Restore
before
timing each test. On the Second Install
, I modified a XAML file and
ran /t:Install
again.
Xamarin.Android.Lite
Time Elapsed 00:00:06.54
Time Elapsed 00:00:03.01
Time Elapsed 00:00:05.60
Time Elapsed 00:00:02.71
Xamarin.Android "proper"
Time Elapsed 00:00:49.46
Time Elapsed 00:00:06.22
Time Elapsed 00:00:46.87
Time Elapsed 00:00:05.95
NOTE: I compared this times on Windows with Visual Studio 15.7.5, using the default Xamarin.Forms Master Detail project template.
Mark Seeman on an episode of .NET Rocks talked about: "constraints liberate". I don't know if he originated the idea, but that is definitely what is happening here.
NetStandard
2.0 projects only, Xamarin.Forms onlyMono.Android.dll
or native APIs? Nope.EmbeddedResource
.Xamarin.Android.Lite is bundled with Xamarin.Forms and Xamarin.Essentials to get the best APIs available for NetStandard.
Currently using:
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
<PackageReference Include="Xamarin.Essentials" Version="0.9.1-preview" />
If another library is deemed useful here, let me know--I could bundle it!
As noted in the project file above, <EmbeddedResource />
is the way
to go:
<EmbeddedResource Include="**\*.png" />
Then to load the image, you will need to use the following C#:
yourImage.Source = ImageSource.FromResource ("YourNameSpace.xamarin_logo.png", typeof (App));
Or better yet, make your own XAML markup extension to do this!
msbuild build.proj /t:Bootstrap
msbuild build.proj