Sample Native Application development using Command Line Interface

Introduction

The Command Line Interface (CLI) provide functionalities for developing Tizen applications by issuing commands in the form of successive lines instead of Tizen Studio IDE. This interface supports the entire development process from creating the project to running an application.

The previous tip document ‘Sample Web Application development using Command Line Interface’ already covers basics of web application development environment using CLI. But for developing in CLI native environment, changes in parameters and commands are required. So in this document, we will focus on sample native application development using CLI from scratch.

Step 1. Download & Install CLI

Download Tizen Studio 1.2 with CLI (command line interface) installer for appropriate platform.

Link: https://developer.tizen.org/development/tizen-studio/download

To Install, enter chmod +x command to apply the execute permission to installer file.  (On Ubuntu and Mac OS® X)

Then, execute the installer by entering command based on following syntax:

tizen-web-cli-<version> [options] [<directory path>]

Example command:

$ tizen-web-cli_TizenSDK_2.4.0_Rev8_ubuntu-64.bin  --accept-license ~/tizen-sdk

Developer has to install ‘web-cli’ first, then update the CLI for native development environment

Prerequisites: https://developer.tizen.org/development/tizen-studio/download/installing-tizen-studio/prerequisites

Installation Guide: https://developer.tizen.org/development/tizen-studio/download/installing-tizen-studio#cli

Updating Tizen Studio: https://developer.tizen.org/development/tizen-studio/download/installing-tizen-studio/updating-tizen-studio

Step 2. Updating CLI for Native development environment

Native application development environment is generally not set up with default installer. Developer has to update the CLI using package-manager-cli located on <Tizen SDK Directory>/package-manager.

‘show-pkgs’ command is used to display package information.

Example command:

$ cd ~/tizen-studio/package-manager
~/tizen-studio/package-manager$ ./package-manager-cli.bin show-pkgs

Output:

Display installed packages information
Tizen Package Manager (0.2.29)
Status	Package Name                            	    Package Version	 Component Name      
------------------------------------------------------------------------------------------------------------------------
ni   	MOBILE-2.4                              	        2.4.74         	2.4 Mobile          		 
i    	MOBILE-2.4-Emulator                     		2.4.74         	Emulator            			 
ni   	MOBILE-2.4-NativeAppDevelopment-CLI     	        2.4.74         	Native app. development (CLI) 
ni   	MOBILE-2.4-NativeAppDevelopment         	        2.4.74         	Native app. development (IDE)
…………..
………….
ni   	WEARABLE-2.3.1                          		2.3.19         	2.3.1 Wearable                            
ni   	WEARABLE-2.3.1-Emulator                	 	        2.3.19         	Emulator                                       
ni   	WEARABLE-2.3.1-NativeAppDevelopment-CLI 	        2.3.19         	Native app. development (CLI) 
ni   	WEARABLE-2.3.1-NativeAppDevelopment     	        2.3.19         	Native app. development (IDE) 
…………..
………
ni   	TOOLS                                   		2.4.68         	Tizen SDK tools                              
i    	Emulator                           		     	2.4.68         	Emulator manager                      
ni   	NativeCLI                               		2.4.68         	Native CLI                                    
ni   	NativeIDE                               		2.4.68         	Native IDE
ni   	NativeToolchain                         		2.4.68         	Native toolchain    	              
ni   	NativeToolchain-Gcc-4.6                	 	        2.4.68         	Gcc 4.6 toolchain                        
ni   	NativeToolchain-Gcc-4.9                 		2.4.68         	Gcc 4.9 toolchain                         
ni   	PlatformIDE                             		2.4.68         	Platform IDE                                 
ni   	EXTRAS                                  		0.0.0          	Extras                                              
i    	cert-add-on                            		 	1.0.42         	Samsung Certificate Extension                                     

Install packages required to develop native application. Example command is shown to update the environment for development in wearable native.

-p parameter takes the OS admin login password

$ cd ~/tizen-studio/package-manager
~/tizen-studio/package-manager$ ./package-manager-cli.bin   install   WEARABLE-2.3.1  --accept-licence   -p ******

Output:

Tizen Package Manager (0.2.29)
****************************************                                                                                            
******* Start SDK Update *******                                                       
****************************************
Nothing to update.
****************************************                                                      		                  
******* Start SDK Installation *******		                              
****************************************
Under packages are will be installed.
	 * WEARABLE-2.3.1-Emulator
	 * NativeToolchain-Gcc-4.6
	 * WEARABLE-2.3.1-NativeAppDevelopment-CLI
	 * WEARABLE-2.3.1-NativeAppDevelopment
	 * WEARABLE-2.3.1-WebFramework-TAU-CLI
	 * WEARABLE-2.3.1-WebAppDevelopment
	 * WEARABLE-2.3.1-WebFramework-TAU
[WEARABLE-2.3.1-Emulator] 
0% [----------------------------------------] 100 %

Step 3. Add CLI directory path to the $PATH environment variable

The CLI is located in $<TIZEN_SDK_HOME>/tools/ide/bin/ directory. For developing an application using CLI, add CLI directory path to the $PATH environment variable using following command:

$ export PATH=$PATH:~/tizen-sdk/tools/ide/bin
$ tizen version
 Tizen CLI 1.2.3

Step 4. List down Available Application templates

‘list’ command is used to list down available project templates:

tizen list <option> :

native-project   Show native project template list

web-project       Show web project template list

list native-project command would list down all the native project templates available.

Example Command:

~$ tizen list native-project

Output:

-----------------------------------------------------	                                                                                                                   
Starting native-project											 
-----------------------------------------------------
[PROFILE]            [TEMPLATE]
mobile-2.4           IMEApplication                                                                                                   
mobile-2.4           ServiceApp									 
mobile-2.4           SharedLibrary									
………												 
wearable-2.3.1       ServiceApp						                                                 
wearable-2.3.1       SharedLibrary					                                        
wearable-2.3.1       StaticLibrary									 
wearable-2.3.1       basic-edc-ui								    	 
wearable-2.3.1       basic-ui							 		 
wearable-2.3.1       watchapp										 
-----------------------------------------------------
Finished native-project

Step 5. Create Tizen native project

To create a tizen native project ‘tizen create’ command is used with the parameters:

-p            Profile name.                                                                                                                                                                    
-t            Template name.                                                                                                                                                  
-n           Project name.                                                                                                                                                                 
--            Destination directory

Example Command:

~$ tizen create native-project -p wearable-2.3.1 -t basic-ui -n ProjectA -- ~/cli-workspace/

Output:

-----------------------------------------------------									 
Starting native-project											 
-----------------------------------------------------
Project Location: ~/cli-workspace/ProjectA
-----------------------------------------------------
Finished native-project 

Step 6. Build native project

‘build’ command builds the Tizen native project.

--             Specifies the project directory

Example Command:

~$ tizen build-native -- ~/cli-workspace/ProjectA

Output:

-----------------------------------------------------									 
Starting build-native											 
-----------------------------------------------------
[ARCHITECTURE]: x86
[COMPILER]: llvm
[CONFIGURATION]: Debug
"~/tizen-studio/tools/smart-build-interface/bin/sbi_make" -v "Wearable 2.3.1" -a i386 -t LLVM-3.6 -c Debug -p app
Checking prerequisite...
Checking make... ok
make: Nothing to be done for `all'.
PLATFORM_VER	: Wearable 2.3.1
ARCHITECTURE	: i386
TOOLCHAIN	    : LLVM-3.6
BUILD_CONFIG	: Debug
PROJECT_TYPE	: app
PROJECT_PATH	: ~/cli-workspace/ProjectA
SDK_PATH	    : ~/cli
APPLICATION_ID	: org.example.projecta
-----------------------------------------------------
Finished build-native
Total time: 00:00:00.216

Step 7. Clean native project

‘clean’ command cleans the Tizen project. If you clean the project, all build output directories under the project root path will be removed (Debug, Release, and .buildResult).

Example Command:

~$ tizen clean -- ~/cli-workspace/ProjectA

Output:

-----------------------------------------------------									 
Starting clean											              
-----------------------------------------------------
~/tizen-studio/tools/smart-build-interface/bin/sbi_make -v "Wearable 2.3.1" -a i386 -t LLVM-3.6 -c Debug -p app clean
Checking prerequisite...
APPLICATION_ID: org.example.projecta
-----------------------------------------------------
Finished clean

Step 8. Edit Source Code 

To edit the ‘.c’, '.h', ’.xml’ files or to create new files you have to change the directory to the project directory. Then open the files using editor to edit source code. Example Command:

~$ cd ~/cli-workspace/ProjectA
~/cli-workspace/ProjectA$ ls
Build  data  inc  lib  project_def.prop  res  shared  src  tizen-manifest.xml
~/cli-workspace/ProjectA$ cd src
~/cli-workspace/ProjectA/src$ ls
projecta.c
~/cli-workspace/ProjectA/src$ nano projecta.c

Step 9. Generating Certificate

‘certificate’ command generates a Tizen certificate for the application. To upload the application to Tizen store or install to a Tizen device, Tizen certificate must be generated.

-a alias name*            -p password*             -c country code         -s state     -ct  city
-o organization          -u unit                         -n username               -e email    -f    filename*            
-- output path

(*) marked parameters are mandatory.

Example Command:

~$ tizen certificate -a testCertA -p 12345678 -f testCert

Output:

-----------------------------------------------------
Starting certificate
-----------------------------------------------------
No path option. Will be generated on '~/cli-data/keystore/author'.
Working path: ~/cli-data/keystore/author
Generating a certificate with
  File name = testCert
  Container Password = ********
  Alias = testCertA
  Key Password = ********
  Internal Certificates Directory = ~/tizen-studio/tools/certificate-generator
'testCert' has been generated in '~/cli-data/keystore/author'.
-----------------------------------------------------
Finished certificate

Step 10. Managing Security Profiles

Tizen packages an application with signing profile.

‘security-profiles’ command manages security profiles, which is a set of signing certificates (author certificate, distributor certificate). Sub commands for tizen security profiles are Add, list and remove.

Security-profiles Add command takes the parameters:

-n profile name         -a author certificate path           -p password              
                                     -d distributor certificate path   -dp distributor password

Example Command:

~$ tizen security-profiles add -n ProfileA -a ~/cli-data/keystore/author/testCert.p12 -p 12345678

Output:

-----------------------------------------------------
Starting add
-----------------------------------------------------
Loaded in '~/cli-data/ide/keystore/profiles.xml'.
author path: ~/cli-data/keystore/author/testCert.p12
author password: ********
distributor1 path: ~/tizen-studio/tools/certificate-generator/certificates/distributor/tizen-distributor-signer.p12
distributor1 password: *************************
distributor1 CA path: ~/tizen-studio/tools/certificate-generator/certificates/distributor/tizen-distributor-ca.cer

Wrote to '~/cli-data/ide/keystore/profiles.xml'.
Succeed to add 'ProfileA' profile.
If want to sign by this, add the file of security profiles in CLI configuration
  like 'tizen cli-config "profiles.path=~/cli-data/ide/keystore/profiles.xml"'.
-----------------------------------------------------
Finished add If want to sign by this, add the file of security profiles in CLI configuration
  like 'tizen cli-config "profiles.path~/cli-data/ide/keystore/profiles.xml"'.
-----------------------------------------------------
Finished add

To list down security profiles ‘list’ command is used.

Example Command:

~$ tizen security-profiles list

Output:

-----------------------------------------------------
Starting list
-----------------------------------------------------
Loaded in '~/cli-data/ide/keystore/profiles.xml'.
========================================
Name
========================================
MyProfile123
pro9
ProfileA
-----------------------------------------------------
Finished list

Step 11. Packaging the native application with Signing

Tizen native application is packed as .tpk file. Package is used to install, uninstall or update application.  Package is zip archive file, and it includes source codes of application and signature data. To publish application in the app store, application should be packed inside .tpk file.

tizen package command takes following parameters:

-t            Package type                                                                                                                        
-s           Security profile name for signing.                                                                                                 
--           Build output path

~$ tizen package -t tpk -s ProfileA -- ~/cli-workspace/ProjectA/Debug

Output:

-----------------------------------------------------
Starting package
-----------------------------------------------------

Initialize... OK
Copying files... OK
Signing... OK
Zip path: ~/cli-workspace/ProjectA/Debug/org.example.projecta-1.0.0-i386.tpk
  adding: signature1.xml	(in=4175) (out=1938) (deflated 54%)
  adding: res/	(in=0) (out=0) (stored 0%)
  adding: bin/	(in=0) (out=0) (stored 0%)
  adding: bin/projecta	(in=18886) (out=7845) (deflated 58%)
  adding: shared/	(in=0) (out=0) (stored 0%)
  adding: shared/res/	(in=0) (out=0) (stored 0%)
  adding: shared/res/projecta.png	(in=57662) (out=18633) (deflated 68%)
  adding: shared/data/	(in=0) (out=0) (stored 0%)
  adding: shared/trusted/	(in=0) (out=0) (stored 0%)
  adding: tizen-manifest.xml	(in=396) (out=232) (deflated 41%)
  adding: lib/	(in=0) (out=0) (stored 0%)
  adding: author-signature.xml	(in=4118) (out=2159) (deflated 48%)
total bytes=85237, compressed=30807 -> 64% savings
Zipping... OK
Package File Location: ~/cli-workspace/ProjectA/Debug/org.example.projecta-1.0.0-i386.tpk
-----------------------------------------------------
Finished package

Step 12: Create and Run an Emulator for app deployment

Emulator Manager allows the developer to easily generate emulator instances from a pre-defined platform and template. Emulator manager can be launched from

 <Tizen Studio dir>/tools/emulator/bin/em-cli

Emulator manager cli commands to list available platforms:

list-platform                list of available platforms

list-template               list of available device templates

list-vm                           list of all virtual machines created

~$ cd ~/tizen-sdk/tools/emulator/bin

list available platform & templates:

~/tizen-studio/tools/emulator/bin$ ./em-cli list-platform
mobile-2.4
wearable-2.3.1-circle
wearable-2.3.1

~/tizen-studio/tools/emulator/bin$ ./em-cli list-template
360x480 Wearable
Wearable Circle
320x320 Wearable
HD Mobile

Create emulator:

-p platform         -t template         -n emulator name

~/tizen-studio/tools/emulator/bin$ ./em-cli create -n WearEmulator -p wearable-2.3.1-circle -t Wearable-Circle
New virtual machine is created

List VM and Launch:

~/tizen-studio/tools/emulator/bin$ ./em-cli list-vm
CLI1
testDevice
WearEmulator

~/tizen-studio/tools/emulator/bin$ ./em-cli launch -n WearEmulator
Launch command : "~/tizen-studio/platforms/tizen-2.3.1/common/emulator/bin/emulator.sh" --conf "~/cli-data/emulator/vms/WearEmulator/vm_launch.conf"

The VM is launched

Step 13: Install the app package on a target

‘install’ command is used to install a tizen application package to device or emulator.

-n                tizen package file name

-t                 target name

--                 directory path of the package file.

Example command:

~$ tizen install -n org.example.projecta-1.0.0-i386.tpk -- ~/cli-workspace/ProjectA/Debug

Output:

-----------------------------------------------------
Starting install
-----------------------------------------------------

Transferring the package...
Transferred the package: ~/cli-workspace/ProjectA/Debug/org.example.projecta-1.0.0-i386.tpk -> /opt/usr/apps/tmp
Installing the package...
--------------------
Platform log view
--------------------
path is /opt/usr/apps/tmp/org.example.projecta-1.0.0-i386.tpk
__return_cb req_id[30000002] pkg_type[coretpk] pkgid[org.example.projecta] key[start] val[install]
__return_cb req_id[30000002] pkg_type[coretpk] pkgid[org.example.projecta] key[install_percent] val[30]
__return_cb req_id[30000002] pkg_type[coretpk] pkgid[org.example.projecta] key[install_percent] val[60]
__return_cb req_id[30000002] pkg_type[coretpk] pkgid[org.example.projecta] key[install_percent] val[100]
__return_cb req_id[30000002] pkg_type[coretpk] pkgid[org.example.projecta] key[end] val[ok]
spend time for pkgcmd is [2293]ms
Installed the package: Id(org.example.projecta)
Tizen application is successfully installed.
-----------------------------------------------------
Finished install

Step 14: Running the Application on a Target

tizen run command is used to run a tizen application package on a target. Package Id is required to run the application on device.

-p                Package ID installed on the target.

-t                 target device name

Example command:

~$ tizen run -p org.example.projecta

Output:

-----------------------------------------------------
Starting run
-----------------------------------------------------

[Name]: projecta
[Type]: rpm
[appId]: org.example.projecta
Launching the Tizen application...
org.tizen.sdblib.exception.SdbCommandRejectedException: closed
	at org.tizen.sdblib.SdbHelper.sendServiceRequest(SdbHelper.java:576)
	at org.tizen.sdblib.PlatformCapability.loadPlatformCapability(PlatformCapability.java:136)
	at org.tizen.sdblib.PlatformCapability.(PlatformCapability.java:132)
	at org.tizen.ncli.ide.subcommands.RunCLICommand.runApp(RunCLICommand.java:185)
	at org.tizen.ncli.ide.subcommands.RunCLICommand.call(RunCLICommand.java:80)
	at org.tizen.ncli.ide.subcommands.RunCLICommand.call(RunCLICommand.java:42)
	at org.tizen.ncli.ide.subcommands.AbstractSubCommand.runCommand(AbstractSubCommand.java:76)
	at org.tizen.ncli.ide.shell.RunCLI.execute(RunCLI.java:66)
	at org.tizen.ncli.ide.shell.AbstractCLI.execute(AbstractCLI.java:90)
	at org.tizen.ncli.ide.shell.Main.run(Main.java:141)
	at org.tizen.ncli.ide.shell.Main.main(Main.java:73)
--------------------
Platform log view
--------------------
... successfully launched
Tizen application is successfully launched.
-----------------------------------------------------
Finished run

Screenshot of the Tizen native project :

Reference:

[1] https://developer.tizen.org/development/tools/common-tools/smart-development-bridge

[2] https://developer.tizen.org/development/tools/native-tools/command-line-interface

[3] https://developer.tizen.org/development/tools/common-tools/emulator#manager

[4] https://developer.tizen.org/development/tools/download/installing-sdk#cli

[5] https://developer.tizen.org/development/tizen-studio/download/installing-tizen-studio/updating-tizen-studio#cli_package_manager

文件附件: 
List
SDK Version Since: 
2.4 mobile/2.3.1 wearable