jonathanpeppers / Xamarin.Android.Lite

Prototype/proof of concept of a "lite" Xamarin.Android that only supports Xamarin.Forms
MIT License
121 stars 6 forks source link

Xamarin.Android.Lite

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

NuGet

Xamarin.Android.Lite

Demo Video

Xamarin.Android.Lite

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...

How do I use it?

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:

Details on each target:

So, 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.

How do the build times compare?

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

Xamarin.Android "proper"

NOTE: I compared this times on Windows with Visual Studio 15.7.5, using the default Xamarin.Forms Master Detail project template.

What are the limitations?

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.

What's in the box?

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!

How do I use images?

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!

How do I contribute? Or build this repo?

msbuild build.proj /t:Bootstrap
msbuild build.proj