Thanks to Daniel Juyung Seo this post is also available in Korean.
Overview
Tizen has the capacity for native applications written using the Enlightenment Foundation Libraries (EFL), however in the 1.0 SDK release this functionality isn’t particularly well exposed. Instead the main focus is currently on HTML5/JavaScript based applications, which is fine, but it’s not appropriate for all applications. As a way to get to grips with Tizen in more detail I decided to try porting one of my existing applications, Eyrie, from MeeGo Harmattan (as used by the Nokia N9) to Tizen.
Eyrie is one such application which clearly isn’t especially suited to being written as a web app. It requires the ability to get raw audio samples from the microphone and perform some signal processing on them to extract acoustic fingerprints. As far as I can see the current Tizen Web API doesn’t really have the capacity to handle audio input at such a low level, and even if it did making use of it for Eyrie would involve completely rewriting the EchoPrint codegen library in JavaScript to handle the fingerprinting.
However by making use of EFL I was able to get the bulk of Eyrie ported to Tizen in less than 24 hours. Thanks to both MeeGo and Tizen using GStreamer as their multimedia framework and the EchoPrint codegen library being easy enough to compile for both platforms all that was really needed was a new UI using EFL instead of QML. Below you can see a video of the initial port running on the Tizen emulator (I don’t have a real device to play with at the moment), the UI is still a little rough around the edges but all the main functionality is working.
Video of the Eyrie music identifier’s initial port to EFL on Tizen
In this tutorial we’ll work through the creation, building, packaging and deployment of a very simple EFL application, which I hope will give people a handle on a potential workflow for native application development using the 1.0 SDK release.
Scratchbox
Although it’s not made obvious, the SDK actually contains a full scratchbox environment which the IDE drops into when build packages. While it might potentially be possible to write EFL apps purely using the IDE I found it easier to ignore this and jump into scratchbox directly, this then frees you up to make use of whatever editor/IDE you’re most comfortable with. If you are looking to work just within the IDE you might find the Tizen Platform Developer’s Guide a good starting point.
I’ll be assuming that you installed the Tizen SDK to ~/tizen_sdk/
Note: After installing the SDK it’s necessary to open the IDE and create (and possibly compile) a platform project. Simply select a new platform project and then hit compile. This sets up the scratchbox targets the first time around. You only need to do this once after installing the SDK.
Before we enter the scratchbox environment we should find out what targets are available to us. We can do this by running:
~/tizen_sdk/SDK/build-system/toolchains/scratchbox2/bin/sb2-config -l
With the 1.0 SDK release this produces the following output:
tizen-device-1.0.sb2_gcc45sbox2.armel.cdeb
tizen-device-1.0.sb2_gcc45sbox2.armel.platform
tizen-emulator-1.0.sb2_gcc45sbox2.i386.platform
Since I’m working with the emulator in x86 mode I’ll be using the tizen-emulator-1.0.sb2_gcc45sbox2.i386.platform target, to compile packages for real devices you’ll need to replace this with one of the armel targets in the following commands. I’m unclear on the intended separation between the two armel targets, but I expect either should be usable for our purposes.
To access the scratchbox as your normal user you can simply run:
~/tizen_sdk/SDK/build-system/toolchains/scratchbox2/bin/sb2 -t tizen-emulator-1.0.sb2_gcc45sbox2.i386.platform
This is perfectly usable for building and editing packages, and you should find that your home directory is available within the scratchbox. However the rest of the environment will be mounted read-only, preventing you from installing new packages.
To start a session in which it’s possible to install packages we can run:
~/tizen_sdk/SDK/build-system/toolchains/scratchbox2/bin/sb2 -e -R -t tizen-emulator-1.0.sb2_gcc45sbox2.i386.platform
This mode is only really suitable for installing packages and isn’t usable for general development as most compilation tools aren’t available.
We want to try writing a simple EFL application using the Elementary toolkit, so to start with we’re going to need to install the Elementary development package:
apt-get install libelm-dev
As you can probably tell from the above scratchbox is a Debian based environment, so most of the normal Debian tools are available to us. So for example if we didn’t know the exact name of the Elementary package we need we could simply run:
apt-cache search elementary
And we’d get a list of likely looking candidates to choose from. As a side note the Eclipse based IDE does have a simple package management interface which can be found on the default toolbar, however this appears to lacks any way of searching for packages, but if you are trying to do everything through the IDE without dropping into scratchbox you might find it helpful.
Elementary
So now that we have a compilation environment capable of targeting both the emulator and real devices we can start writing our applications. For this tutorial we’ll just create a very simple Elementary application that displays a label:
#include <Elementary.h> static void on_quit(void *data, Evas_Object *obj, void *event_info) { elm_exit(); } EAPI int elm_main(int argc, char *argv[]) { Evas_Object *win, *bg, *box, *lbl; /* Create our window */ win = elm_win_add(NULL, "eflexample", ELM_WIN_BASIC); elm_win_title_set(win, "Tizen EFL Example"); evas_object_smart_callback_add(win, "delete,request", on_quit, NULL); /* Give it a background */ bg = elm_bg_add(win); evas_object_size_hint_weight_set(bg, 0.0, 0.0); elm_win_resize_object_add(win, bg); evas_object_show(bg); /* Create a box to place our label inside */ box = elm_box_add(win); elm_box_horizontal_set(box, EINA_FALSE); evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0); elm_win_resize_object_add(win, box); evas_object_show(box); /* Make a label */ lbl = elm_label_add(win); evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_object_part_text_set(lbl, NULL, "Hello Tizen!"); elm_box_pack_end(box, lbl); evas_object_show(lbl); /* Display the window */ evas_object_show(win); /* Start the Elementary main loop */ elm_run(); return 0; } ELM_MAIN();
I’ll assume we’re working in the directory ~/src/tizen/eflexample/, so we can save this as ~/src/tizen/eflexample/eflexample.c
More comprehensive documentation on Elementary can be found on the Enlightenment Wiki.
We’ll keep the build process very simple for this example and just have a small Makefile handle compilation. For more complex projects both autotools and cmake are available.
CFLAGS=`pkg-config --cflags elementary` LDFLAGS=`pkg-config --libs elementary` eflexample: $(CC) $(CFLAGS) eflexample.c -o eflexample $(LDFLAGS) all: eflexample clean: rm -f eflexample install: all mkdir -p $(DESTDIR)/opt/share/applications cp com.mikeasoft.eflexample.desktop $(DESTDIR)/opt/share/applications/ mkdir -p $(DESTDIR)/opt/com.mikeasoft.eflexample cp eflexample $(DESTDIR)/opt/com.mikeasoft.eflexample/ cp icon.png $(DESTDIR)/opt/com.mikeasoft.eflexample/
This gets saved as ~/src/tizen/eflexample/Makefile
By including the $(DESTDIR) variable in our install paths we allow the Debian packaging we’re about to write to override the install destination and place it inside a temporary directory prior to being packed into a .deb.
If we run make in the ~/src/tizen/eflexample directory whilst inside our scratchbox session it should then compile successfully.
Launcher
You might notice in the earlier Makefile a couple of files that we haven’t yet discussed, com.mikeasoft.eflexample.desktop and icon.png. These are going to be used for adding our application to Tizen’s launcher. The .desktop file gets installed to /opt/share/applications/ alongside all other Tizen .desktop launchers, and should look something like:
Name=EFL Example
Type=Application
Exec=/opt/com.mikeasoft.eflexample/eflexample
Icon=/opt/com.mikeasoft.eflexample/icon.png
Comment=An example of how to write native EFL applications for Tizen
Version=0.1
X-TIZEN-TaskManage=True
X-TIZEN-Multiple=False
X-TIZEN-Removable=True
This is then saved to ~/src/tizen/eflexample/com.mikeasoft.eflexample.desktop
You’ll probably notice that there’s a selection of Tizen specific entries. The first, X-TIZEN-TaskManage, controls whether or not our application will appear in the Tizen task manager. The second, X-TIZEN-Multiple, tells the task manager if it is allowed to launch more than one copy of our application. If this is set to false the task manager will instead try to restore a currently running version of our application to the foreground. Because our simple example doesn’t perform the extra necessary work to allow Tizen to restore it to the foreground the task manager will instead simply kill our application when clicked a second time. Finally the last setting, X-TIZEN-Removable, specifies whether or not our application can be uninstalled through the application manager.
For the icon file we’ll simply use the Enlightenment logo:
Which needs to be saved to ~/src/tizen/eflexample/icon.png
Packaging
At this stage we could potentially just copy our eflexample binary to the device and start it via the command line, but a much more complete and redistributable solution is to construct a Debian package for it.
First we create our control file, which describes our package and its various dependencies:
Source: com.mikeasoft.eflexample
Section: user/other
Priority: extra
Maintainer: Michael Sheldon <elleo@gnu.org>
Build-Depends: debhelper (>= 7), libelm-dev
Standards-Version: 3.8.4
Homepage: http://blog.mikeasoft.com
Package: com.mikeasoft.eflexample
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: An example of creating EFL applications for Tizen
Architecture: any
This gets placed in ~/src/tizen/eflexample/debian/control
Because our build system is fairly standard and handles the DESTDIR parameter being passed to it we can use debhelper to automate all of our rules file for us:
#!/usr/bin/make -f %: dh $@
This is then saved to ~/src/tizen/eflexample/debian/rules
Then we have our changelog:
com.mikeasoft.eflexample (0.1.0-1) unstable; urgency=low * Initial release -- Michael Sheldon <elleo@gnu.org> Sat, 23 Jun 2012 04:32:27 +0100
Which is saved to ~/src/tizen/eflexample/debian/changelog
Finally we can specify which version of debhelper we’re compatible with by running:
echo 7 > ~/src/tizen/eflexample/debian/compat
Now we’re ready to actually build our package. To do this we need to be inside our scratchbox session as a normal user, which we achieve by running:
~/tizen_sdk/SDK/build-system/toolchains/scratchbox2/bin/sb2 -t tizen-emulator-1.0.sb2_gcc45sbox2.i386.platform
Then we can begin building our package:
cd ~/src/tizen/eflexample
dpkg-buildpackage -rfakeroot
After our application has been successfully compiled and packaged it’ll be saved in the parent of our current directory (i.e. ~/src/tizen/).
Deploying
Now that we’ve built a package for our application we can deploy it using the sdb tool provided with the SDK. This should work with either the emulator or a connected device. First we transfer our Debian package to the device and place it in the /tmp/ directory, then we run dpkg on the device to install our new package. If we had used any additional dependencies that aren’t already installed by default we’d need to use apt-get to install them prior to installing our own package. However since libelm is part of the default Tizen system all we need to do is:
~/tizen_sdk/SDK/sdb/sdb push ~/src/tizen/com.mikeasoft.eflexample_0.1.0-1_i386.deb /tmp/ && ~/tizen_sdk/SDK/sdb/sdb shell dpkg -i /tmp/com.mikeasoft.eflexample_0.1.0-1_i386.deb
We should now see a new icon in the Tizen application launcher for our example app, which we can simply click to start.
Source
The complete source for this tutorial can be download here: eflexample.tar.gz.
[…] Comments http://blog.mikeasoft.com/2012/06/23/writing-native-tizen-applications-using-the-1-0-larkspur-sdk-sc… Related posts:Interview with Jim Zemlin, Linux FoundationUpgrade Your Website to […]
Pingback by Michael Sheldon’s Stuff รยป Writing native Tizen applications using the 1.0 (Larkspur) SDK Scratchbox and EFL | TizenExperts — June 23, 2012 @ 3:40 pm
cool! I’ll refer to your informations for build own application on Tizen.
Comment by moguriso — June 23, 2012 @ 4:17 pm
Thanks for providing a nice guide on how to get started, including a clean way of doing Debian packaging with debhelper 7 ๐ Much appreciated!
Comment by thp — June 23, 2012 @ 4:58 pm
Thank you very much for this blog post! Will definitely be referring to it in the future and hope to see more to come!
Comment by Cody — June 23, 2012 @ 8:08 pm
Next to the elementary wiki page we also have a not that bad code documentation:
http://docs.enlightenment.org/auto/elementary/
Nice write up to sow people that it is possible to do native apps right now already.
Comment by Stefan Schmidt — June 25, 2012 @ 11:56 am
[…] Well, good news(!) — Michael will be posting detailed instructions on his blog soon (EDIT: The full instructions are now up). While waiting for it, here is how he explained it to me in an email:Hi Reggie,I’m planning […]
Pingback by From Qt to EFL: Eyrie Music Identifier on Tizen (updated) | Tizen Talk — June 29, 2012 @ 3:07 pm
hello i have a trouble when i was ejecute ~/tizen_sdk/SDK/build-system/toolchains/scratchbox2/bin/sb2-config -l i don’t have install the scratchbox2 the i ejecute sudo apt-get install scartchbox2
Comment by cidetec — July 5, 2012 @ 5:54 pm
cidetec – Scratchbox2 is included as part of the SDK package, make sure you’re using the actual path that you installed it to, the path I’m giving is just the default location.
Comment by Mike — July 5, 2012 @ 8:26 pm
Hello I have a troble with that .scratchbox2 missing, create some targets with sb2-init! some one knows what can i do??? thanks
Comment by zamora — July 10, 2012 @ 3:07 pm
Finally I translated your blog posting to Korean.
Thanks for the good posting. http://seoz.egloos.com/3862259
Comment by Daniel Juyung Seo — July 16, 2012 @ 2:31 pm
Daniel – Awesome, thanks for the translation.
Comment by Mike — July 16, 2012 @ 11:10 pm
Nice post Mike, write more posts like this about Tizen.
Comment by Long — August 2, 2012 @ 8:21 am
Can you please guide how to build a shared object in Tizen SDK for native applications written in C/C++
Comment by Naveen — August 14, 2012 @ 6:08 am
Naveen – Once you’re inside the scratchbox environment you can just build a shared object as you would normally within Linux, everything will be compiled against the Tizen libraries automatically.
Comment by Mike — August 14, 2012 @ 1:36 pm
Hello, Mike.
Thank you for such exciting manual.
Can you, or somebody, please, answer my question?
Question:
“I’ve developed EFL GUI in terms of .edfj binary file (the result of applying of Edje library), and I also have native .c file with API. Corresponding to this guide, I can easily deploy my compiled .c file on Emulator/device, in case this binary file is the only. But in my GUI application, this binary dynamically takes .edj binary file onto account. I tried to put .edj binary beside .c binary in the same directory on Emulator/device, but it does not work, seems, that my .c binary does not see .edj binary. The problem is more general: how can I correctly deploy an application on Emulator/device, if it dynamically binds with one or several dynamic libraries .so? Maybe, I should just add several new lines into .desktop and Makefile, or something more complex? Can you, please, help me?”
Thank you.
Comment by Maxim — August 22, 2012 @ 8:02 am
There is a misspelled letter in the sample c code.
It is ‘#include elementary.h’
It has to be corrected as shown below.
‘#include Elementary.h’
This small mistyping took of 30 minutes for me to do a trouble-shooting.
The attached file is ok only the one on the html is wrong..
Comment by Journeyer — September 8, 2012 @ 7:51 am
Hi Journeyer, thanks for spotting that, I’ve corrected it now.
Comment by Mike — September 10, 2012 @ 2:27 pm
Thanks very much for this guide. We are using it internally now. However, when running sb2 I am getting errors regarding *.lua, and then qemu-arm starting. Is that anything you ran across or would know how to fix?
Comment by joe — September 12, 2012 @ 11:17 pm
Hi Joe,
Sorry, that’s not a problem I’ve encountered myself. Could you paste some full examples of the errors you’re getting and under what conditions? I might be able to take a guess at what’s causing them.
Comment by Mike — September 13, 2012 @ 4:47 am
Hi,
Nice post Mike. very easy to understand.
Comment by Viraj — September 28, 2012 @ 5:12 am
Hi,
Does the given instructions hold good for Tizen 2.0 release??
If I am not wrong, 2.0 uses RPMs not Deb.
Did you manage to port this to Tizen 2.0 ?
Any instructions will be helpful.
Comment by Amit S — October 1, 2012 @ 9:27 am
Hi,
Please port on Tizen 2.0 and post the instructions.
It would really be helpful.
Comment by Alex — October 4, 2012 @ 6:59 am
Hi All,
Instructions for Tizen 2.0,
1. Install package alien using sudo apt-get install alien.
2. Prepare your .deb using the procedure using tizen 1.0 SDK.
3. Convert .deb to .rpm using alien -r *.deb
4. Start Tizen 2.0 Emulator.
5. Install *.rpm package using tizen 1.0 sdk
~tizen_sdk/SDK/sdb/sdb push *.rpm /tmp/ && ~tizen_sdk/SDK/sdb/sdb shell rpm -i /tmp/*.rpm
6. click on the Icon.
Done. Hope this helps.
Cheers!!!
Comment by Viraj — October 9, 2012 @ 7:13 am
Hi!
Thank you for your kind postings.
But I have doubt about your latest instructions for SDK 2.0.
This instruction uses toolchain in SDK 1.0.
Do SDK 1.0 and SDK 2.0 use same toolchain?
Thank you.
Comment by Journeyer — October 10, 2012 @ 7:14 am
Hi,
I am able to run the Sample application in Tizen Emulator.Can you please let me know how to link user created libraries to it and how to Create a package that consists other than EFL libraries and how to run it in Tizen Emulator.
Comment by Naveen — October 11, 2012 @ 6:14 am
In my investigation, SDK 1.0 and SDK 2.0 use different toolchains.
Now I have my answer.
Thank you.
Comment by Journeyer — October 11, 2012 @ 11:03 am
Hi,
I would to like to know ,are there any alternative ways to create User Interface(UI) that links the Shared Libraries (.so) other than EFL libraries. Thanks in advance.Even I need clarification how to link the user created Shared libraries to an native EFL Application
Comment by Naveen — October 15, 2012 @ 12:53 pm
Naveen – You can link to any libraries you like, developing in the method outlined above is equivalent to developing on any standard GNU/Linux system. To ship custom shared libraries with your application simply include them in your package and then set the LD_LIBRARY_PATH to include the location that they’re installed to at run time.
Comment by Mike — October 15, 2012 @ 10:50 pm
Hello Mike,
I need one clarification from your side.For my application it is necessary to give one folder ( contains different File Formats).Now am able to run my application with static libraries linked on the Tizen Emulator by creating a package with .exe . So,I have a set of questions like
1)Is there any way to pass these files along with the package to run it on Emulator as it is running in the Emulator not in the Linux machine
2)Otherwise,we can bypass the path folder to that residing in the Linux system while the application will be running in the Emulator.
Comment by Naveen — October 17, 2012 @ 2:24 pm
Hello,
One more information needed ,if user wants to store and edit the files where it should be placed Or any separate location available for User created files.Thanks in advance.
Comment by Naveen — October 19, 2012 @ 11:51 am
Hello All,
Is Scratch Box is available in Tizen 2.0 ?.Thanks in advance.
Comment by Naveen — October 22, 2012 @ 12:07 pm
Nice tutorial Mike, Is there any mechanism in Tizen to communicate to web app from native app or vice a versa using dbus or inbuilt tizen sdk apis?
Comment by Sameer — December 11, 2012 @ 7:42 am
Hi Sameer,
Not as far as I’m aware in the current version; it might be worth asking on the mailing list though. I’ve drifted away from Tizen somewhat since Jolla started making progress (and because the Tizen steering committee still hasn’t answered some pretty fundamental questions about the direction of Tizen with regards to native apps), so I might not be fully up-to-date on that side of things.
Comment by Mike — December 12, 2012 @ 9:31 pm
Thanks Viraj, for the introduction in Tizen 2.0!
good Day
Comment by Smart Tizen — December 17, 2012 @ 6:32 pm
[…] For all the full information please visit Michael Sheldon’s Stuff […]
Pingback by Writing native Tizen Applications using the 1.0 (Larkspur) SDK Scratchbox and EFL — February 23, 2013 @ 12:45 pm