Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Visual Studio Tools for Tizen

DZone's Guide to

Visual Studio Tools for Tizen

Samsung recently announced Visual Studio development tools for Tizen, the Linux-based open-source mobile development platform.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

Tizen is a Linux-based open-source platform for mobile phones and TVs. Earlier this year, Samsung announced Tizen development tools for Visual Studio, and now it is time to try out how things work. Although the tooling is still in preview and there is no stable version, it's still possible to start playing with Tizen development. This blog post gives an overview of my first experiences with Xamarin Forms and Tizen development.

NB! My experiment started actually by trying out Visual Studio Tools for Tizen, but as Xamarin Forms supports also other platforms like Android, iOS, and UWP, I went on with all of these (except iOS, because I don’t have any option to run XCode server). So, my sample application doesn’t contain just a Tizen project, but also Android, iOS, and UWP.

Sample application: my Xamarin Forms sample application with Tizen support can be found in my GitHub repository MyMobileApp.

Tizen Templates

There are three project templates available for Tizen:

  • Blank App (Tizen Xamarin.Forms Portable).
  • Blank App (Tizen Xamarin.Forms Single).
  • Class Library (Tizen).

The template for the portable version creates a solution with Portable Class Library (PCL) where shared code and views are held. Single means that there is one project that contains all artifacts. As I found out while experimenting, shared libraries are not yet supported.

When creating a solution with PCL, there is a project wizard where we can configure our Tizen solution.

Image title

The important thing is to understand profile options:

  • Mobile – create a project for a mobile application.
  • TV – create a project for a TV application.
  • Common – create one application project that runs on TVs and phones.

My solution uses a separate library, as I share code and views with other mobile platforms.

Tizen Applications

Tizen applications have a simple structure. The following folders are created by default:

  • lib – folder for additional libraries used by Tizen applications.
  • res – resource files delivered with the application.
  • shared – folders shared with other applications and operating systems.
  • shared/res – resources shared with other applications.

There can be more folders, as described in the document Tizen File System Directory Hierarchy.

tizen-manifest.xml is manifest file similar to what other mobile platforms have – definitions for application and its capabilities. With Visual Studio tools comes a nice looking editor for Tizen manifest files.

Image title

project.json is also present and this is where dependencies, framework support, build settings, and runtimes are described. I am not sure if this file will be needed in future as with .NET Core projects Microsoft is moving back to .csproj files.

As Tizen uses Xamarin Forms, the start-up code for the application is short and primitive.

class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
{
    protected override void OnCreate()
    {
        base.OnCreate();
            
        LoadApplication(new App());
    }
 
    static void Main(string[] args)
    {
        var app = new Program();
        global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
        app.Run(args);
    }
}

Here, the application is initialized, then the Xamarin Forms application is loaded from the PCL project.

Tizen Emulators

Tizen tools come with emulators for mobile phones and TV. There is a nice and simple emulator management application that is installed with Tizen tools. This is the place where emulators are created and managed.

Image title

NB! There are some requirements for using Tizen emulators. Your machine must support hardware virtualization and Hyper-V must be disabled. You can find more information in the document Installing Visual Studio Tools for Tizen.

I wasn’t able to get my application running in the mobile emulator due to the emulator’s network issues. The emulator for TV works well with the same network settings, but network connections are very slow. It takes around half a minute to load.

Here is the screenshot of my sample application running on Tizen TV-emulator.

Image title

Although the emulator seems primitive it has many settings available like described in document Emulator Control Panel.

Supporting Tizen Projects With Other Xamarin Forms Projects

Although Xamarin Forms projects for Android, iOS, and UWP support shared libraries, it doesn’t hold true for Tizen projects. Today, Tizen wants PCL or .NET Standard projects. The good thing is that other projects support .NET Standard too.

If you started with a PCL project, then delete it and create a new .NET Standard project using Visual Studio. Move all your files from PCL to there. Then unload the .NET Standard project and edit it with Visual Studio. Make sure that the target framework is netstandard1.4 and the library also supports PCL:

<PropertyGroup>
  <TargetFramework>netstandard1.4</TargetFramework>
  <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>
</PropertyGroup>

Save the project file and reload it.

Maybe there is some better way to do it but this is what started working for me.

Troubleshooting

As Xamarin Forms and Tizen tools are both new and kind of raw, don’t be surprised when running into different issues.

  • Be careful when dealing with NuGet packages. Some packages come with settings saved to project files and on removal, they don’t clean up their modifications. It’s easy to cause “package hell” this way. If you are running out of ideas, check the project files in edit mode and see if there are any traces left by removed packages.
  • Debugging can be challenging as sometimes code seems not to hit breakpoints. It usually means that there is some longer network delay if your code connects to the internet for data.
  • It’s possible you won't get much information about the code when the breakpoint is hit in a shared library. Only some properties of objects are shown and some variables are not reachable through locals and immediate windows. If you don’t find any good way of debugging, just move the code to UWP (or some other) project and debug it there. This way, I was able to debug some nasty code errors that appear only when the code is running.
  • Sometimes, exceptions are not informative. You see a simple message stating there is an error but no details are provided. It’s possible in some cases to get more information when you click Continue and then check the output in the debug window.

Wrapping Up

Although Tizen tools are in preview, they are already pretty usable with Xamarin Forms. There are some annoying issues and things that don't work well, but still, it’s possible to start trying Tizen tools out with real applications. The available tools look promising to me and it’s good to see that Tizen will be a platform where Xamarin developers can make their applications available in the near future.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
mobile ,mobile app development ,tizen ,visual studio ,xamarin forms

Published at DZone with permission of Gunnar Peipman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}