пʼятниця, 23 червня 2017 р.

Compilation: every .cs file in .csproj


You should add a .cs file to the Sample.csproje, to the appropriate <ItemGroup> manually:

<Compile Include="MyButton.cs" />

otherwise you may get this:

I/MonoDroid( 2017): UNHANDLED EXCEPTION:
I/MonoDroid( 2017): Xamarin.Forms.Xaml.XamlParseException: Position 8:3. Type local:MyButton not found in xmlns clr-namespace:Sample

P.S. seems that MonoDevelop may add it automatically.

Compilation prerequisites

On Linux you can't create the Xamarin.Forms project from zero.

And for the compilation it is necessary to take the good template (!!!),
then msbuild will compile it correctly in many cases,
otherwise you may have a very strange errors in runtime,
or you will be able to build it only with xbuld.

Today you may try to use the xamarin-forms-samples for your experiments.

Sample.sln

Please comment out #
lines for iOS (and other, UWP, if any) project(s) - there are 3 lines for each project to comment out.

And every Sample.Droid.csproj will need the next:

<PropertyGroup Condition=" '$(OS)' == 'Unix' ">
  <AndroidSdkDirectory>/home/workerlamp/android-toolchain/sdk</AndroidSdkDirectory>
</PropertyGroup>

(please refer to this link to use more properties)

Also I set for all three PropertyGroup(s) the next line

<AndroidSupportedAbis>armeabi-v7a,x86</AndroidSupportedAbis>

x86 allows me to run it on emulator,

but if I will set pure "armeabi" as in some of examples it will not work on emulator at all,
but "armeabi-v7a" and "x86" works ok for me.
Usually I use only x86: <AndroidSupportedAbis>x86</AndroidSupportedAbis>

I don't know is it possible to make release builds on Linux to work on different devices, but for the development it is enough.

Making the xaml page


It is not enough to create 2 files:

SomePage2.xaml

<?xml version="1.0" encoding="utf-8"?>
  <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:Sample" x:Class="Sample.SomePage2">
  <Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

SomePage2.xaml.cs

using Xamarin.Forms;
  namespace Sample
  {
    public partial class SomePage2 : ContentPage
    {
      public SomePage2()
     {
       InitializeComponent();
     }
   }
 }

Additionally you will need to edit the Sample.csproj file manually, for example:

<ItemGroup>
  <EmbeddedResource Include="App.xaml" />
  <EmbeddedResource Include="SamplePage.xaml" />
  <EmbeddedResource Include="SomePage2.xaml" />
</ItemGroup>

<ItemGroup>
  <Compile Include="App.xaml.cs">
    <DependentUpon>App.xaml</DependentUpon>
  </Compile>
  <Compile Include="SamplePage.xaml.cs">
    <DependentUpon>SamplePage.xaml</DependentUpon>
  </Compile>
  <Compile Include="SomePage2.xaml.cs">
    <DependentUpon>SomePage2.xaml</DependentUpon>
  </Compile>
...
</ItemGroup>

Visual Studio Code

Visual Studio Code has a limited functionality today, but it is maybe the best tool I see today:

File system links:

~/.vscode/extensions/ms-vscode.csharp-1.10.0/bin

xbuild -> /usr/lib/mono/xbuild
xbuild-frameworks -> /usr/lib/mono/xbuild-frameworks/

~/.vscode/extensions/ms-vscode.csharp-1.10.0/bin/omnisharp/msbuild

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

where /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/ is my build path for xamarin-android.

File system links


Usually many of C# IDE on Linux are using the msbuild,
but if you will try to use the msbuild from the command line (you must try it to tune an IDE) you will see the different errors, because it can't find either some targets or it can't find the "The reference assemblies for framework MonoAndroid,Version=v1.0" (thanks to this developer who helped me to fix the MonoAndroid issue).

So we may use the symbolic links:

Path: /usr/lib/mono/xbuild

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

Path: /usr/lib/mono/xbuild-frameworks

MonoAndroid -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid


Path: /usr/lib/mono/msbuild/15.0/bin

Novell -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell
Xamarin -> /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Xamarin

where /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/ is my build path for xamarin-android.
I use the "ln -s directory" to make a link,
for example:
cd /usr/lib/mono/xbuild
ln -s /home/workerlamp/xamarin_local/xamarin-andr/xamarin-android/bin/Debug/lib/xbuild/Novell

Other solutions


Personally I've found this link:
https://github.com/0xFireball/xamarin-android-linux

Compilation details

Before proceeding, please take a look at this link first: other solutions, maybe it will be better for you than manual compilation.

Xamarin.Android sources:
https://github.com/xamarin/xamarin-android

My environment:
* Debian 9 (probably it will work on Debian 8 also);
* x86_64 computer (probably it may work on x86 also)

I've compiled this version:

commit e83c99c12d9a397457146c639c3d4e85198bda91
Date:   Thu Jun 15 2017

But I would not reccomend to do the same, because I've spent a lot of time to fix the issues.

If you will take a look
https://github.com/0xFireball/xamarin-android-linux
then you may find this very interesting link:

https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/lastSuccessfulBuild/Azure/

So, you can find the last successful build version and retry the build if you want.

Personally, I have not tried to use files from their Jenkins distribution...

Compilation details:

*  git clone https://github.com/xamarin/xamarin-android.git (it is necessary to don't forget to clone the successful build version);
* http://www.mono-project.com/download/alpha/ (alpha version), because it needs mono => 5.2.0 and msbuild (and later you will need the nuget);
* add javac (version >= 1.8) to the PATH, for example export PATH="$HOME/java/jdk1.8.0_101/bin:$PATH"
* install cmake (an ordinary Linux package);


P.S. Today (27 Sep 2017) it is not the alpha repository, but the stable repository(!)


Xamarin.Forms on Linux

Maybe somebody will find it useful.