Uno Platform

6/19/2018

Uno Platform is likely the best platform for developing apps targeting multiple platforms - Windows, web, Android and iOS.

Uno Platform is likely the best platform for developing apps targeting multiple platforms - Windows, web, Android and iOS.

To start a project to target multiple platforms:

  1. Join Uno Gitter,  well supported must-have lifeline at this stage of Uno.
  2. Install the Uno Solution Template Visual Studio Extension (UnoSolutionTemplate.vsix)
  3. Create a new C# solution using the Uno App Solution template.  This results in 5 project folders: .Droid, .iOS, .Shared, .UWP and .Wasm.
  4. Update NuGet Packages. Use the latest prerelease Uno NuGet packages. 
  5. Set the the UWP target to Build 17134, and Min to Build 16299.
  6. Add the Shared project to the references of the other 4 projects.
  7. Build the UWP project (required for Xaml intellisense)
  8. Do not reference any .NET Standard 2.0 class library.  Create a Uno class library as described later.
  9. Do not use "Binding", instead, use "x:Bind" for data binding.  "Binding" works only for UWP head, not for Droid.
  10. Do as much as possible in the Shared project.
  11. Use the UWP project (top left corner) for Xaml editing.

UWP Head:

  1. Associate the app with Microsoft Store.
  2. Edit Assembly Information of the project properties.
  3. Edit Package_appxmanifest.xml.  Change Entry point to: MyAppNameSpace.app, select Lock screen notification for the Application tab.  Populate the Visual Assets tab.  
  4. Create the store package and use Windows App Certification Kit to validate it.
  5. Submit the package to Microsoft Store.

Android Head:

  1. Change ApplicationName in Resources > values > Strings.xml to your desired app name. 
  2. Change Assets\Resources\drawable\icon.png from the default Android icon to the app icon.
  3. Properties > Android Manifest: populate the fields properly. Set the Target Android version to a specific version.  Do not use the default value "Use Compile using SDK version" 
  4. Properties > Android Package Signing: use an existing keystore or use Android Studio to create a keystore, then use it.
  5. Select "Any CPU" configuration to deploy the app to ether physical devices or emulators.
  6. Deploy the app to an Android device to generate Android packages (package_name.apk and package_name-Signed.apk) under MyApp.Droid\bin\Release. Build or Rebuild does not create packages.
  7. Upload package_name-Signed.apk to Google Play for publication.

WASM Head (for testing with IIS):

  1. Add an application to a local web site in IIS and set its physical path to: ...\MyApp\MyApp.Wasm\bin\Debug\netstandard2.0\dist 
  2. Add MIME type "application/octet-stream .clr"to IIS.
  3. Add MIME type "application/wasm .wasm" to IIS.
  4. Add MIME type "application/woff2 .woff2" to IIS
  5. Run http:localhost/Myapp for testing.  It usually takes 10+ seconds to load. It works with Chrome, Opera and Firefox.  Microsoft Edge does not support localhost. Wasm cannot be started from Visual Studio.
  6. Build the release version after debugging, and upload the contents of folder "...\MyApp\MyApp.Wasm\bin\Release\netstandard2.0\dist" to a web server, then set a navigation link to the folder or index.html of the folder. Add the aforementioned MIME types to the server's IIS.

 

Create a library that can be referenced by all Uno heads:

  1. Create it using Cross-Platform Library (Uno Platform) template.
  2. Add Newtonsoft.Json NuGet package for using Json.
  3. Add Microsoft.CSharp NuGet package for using dynamic.
  4. Unload the library project.
  5. Edit the this library project's .csproj file.
  6. Following the workaround as of 2018-11-27
  7. Add the following to the .csproj file to use DataContractSerializer and XElement:

    <ItemGroup>
        <Reference Include="System.Runtime.Serialization" />

         <Reference Include="System.Xml.Linq" />

    </ItemGroup>

  8. Save this .csproj file, load and build the project.

 Add a UserControl derived control to Uno class library:

  1. Right click Uno class library project > Add > new item > Uno Platform > Blank Page.
  2. Go to the newly created Xaml page and replace Page with UserControl.
  3. Go to the newly created C# class file and replace Page with UserControl.

For analytics and ads, use the official Xamarin packages for non-WASM heads.

For sockets, use .Net sockets for non-WASM heads.

 

Initial method to create a library that can be referenced by all Uno projects:

  1. Create a .NET Standard Class library.
  2. Unload the library project.
  3. Edit the this library project's .csproj file.
  4. Copy the contents from this demo file.
  5. Remove the <Page> element for "Themes\Generic.xaml"
  6. Ensure the version in <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform " Version="6.1.5" /> is the latest version of Microsoft.NETCore.UniversalWindowsPlatform.  Normal NuGet update of Microsoft.NETCore.UniversalWindowsPlatform does not work for this library. 
  7. Ensure the uap version is at least uap10.0.16299 in <TargetFrameworks> so that NuGet packages such as Newtonsoft.Json can be installed properly. 
  8. Change this line <ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' "> to <ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0.16299' "> to avoid "Error CS0012 The type 'Object' is defined in an assembly that is not referenced."
  9. Add the following to the .csproj file to use DataContractSerializer and dynamic:

    <ItemGroup>
    <Reference Include="System.Runtime.Serialization" />

    <Reference Include="Microsoft.CSharp" />
    </ItemGroup>

  10. Save this .csproj file, load and build the project.
  11. Install NuGet package Microsoft.CSharp

 For imaging work, there is an outstanding review for the options. SkiaSharp NuGet package is a great choice.

Unsupported:

  • Implicit style.
  • Microsoft Advertising SDK for XAML.
  • Toast functions.
  • Windows.Security.Cryptography. (replacement System.Security.Cryptography of .Net Standard). 
  • FrameworkElement
  • IStorageFolder
  • EmailMessage
  • Windows.ApplicationModel.DataTransfer.DataPackage 
  • DataTransferManager
  • System.Math.Log10
  • System.Math.Ceiling
  • NavigationView
  • BitmapEncoder

 WASM performance is the major issue of UNO.  It takes more than 10 seconds to load