How to Package a cmake Ubuntu mobile app as a snap app

Source: Internet
Author: User
Tags wrapper git clone

In the previous article, "How to Package a qmake Ubuntu mobile app as a snap app," we described how to package a qmake Ubuntu mobile app as a snap desktop app. In today's tutorial, we'll show you how to convert a cmake Ubuntu mobile project into a snap desktop app.



1) Develop a mobile app that we need through the Ubuntu SDK



We can create a project that we want through the Ubuntu SDK. about how to create an Ubuntu mobile app, this is not in our scope of this tutorial. If you are interested in developing a mobile app using the Ubuntu SDK, please refer to our article "Ubuntu Mobile Development Training Preparation". There will be no longer a statement of exhaustion.


It is worth pointing out: In today's tutorial, we will teach you how to package a cmake Ubuntu mobile app as a snap application. Here, we'll start with a project that I've developed earlier as a routine. We enter the following command under Terminal:

$ git clone https://github.com/liu-xiao-guo/photos

After downloading the source code structure is as follows:

liuxg@liuxg:~/snappy/desktop/photos$ tree-l 2
.
├──photos.wrapper
├──setup
│└──gui
├──snapcraft.yaml
├──snappy-qt5.conf
└──src
    ├──app< C8/>├──cmakelists.txt
    ├──manifest.json.in
    ├──photos.apparmor
    └──po

As shown above, in the SRC directory there is a complete CMake mobile app that can be executed. Its project management file is CMakeLists.txt. In its root directory, there is a file called the Snapcraft.yaml file. This is used to package our CMake mobile app and make it a snap app that can be run on our 16.04 desktop.



2) package for our CMake project


In the previous section, we have mentioned the Snapcraft.yaml file for our project. Now let's show this file as follows:


Snapcraft.yaml

Name:photos-app version:1.0 Summary:ubuntu Photos app Description: |
    This is a demo app showing what to convert a cmake Ubuntu phone app to a snap app Apps:photos:command:photos Plugs: [Network,home,unity7,opengl] parts:photos:plugin:cmake configflags: [-dcmake_install_prefix=/usr,-DC Lick_mode=off] Source:src/build-packages:-cmake-gettext-intltool-ubuntu-touch-so 
      Unds-suru-icon-theme-qml-module-qttest-qml-module-qtsysteminfo-qml-module-qt-labs-settings
      -Qtdeclarative5-u1db1.0-qtdeclarative5-qtmultimedia-plugin-qtdeclarative5-qtpositioning-plugin -Qtdeclarative5-ubuntu-content1-qt5-default-qtbase5-dev-qtdeclarative5-dev-qtdeclarati
    Ve5-dev-tools-qtdeclarative5-folderlistmodel-plugin-qtdeclarative5-ubuntu-ui-toolkit-plugin-xvfb
   Stage-packages:-Ubuntu-sdk-libs-qtubuntu-desktop   -QML-MODULE-QTSYSTEMINFO-UBUNTU-DEFAULTS-ZH-CN Snap:--usr/share/doc--usr/include environ Ment:plugin:copy Files:photos.wrapper:bin/photos Snappy-qt5.conf:etc/xdg/qtchooser/snappy-qt5.con F

Here, I don't want to be tired of talking about the meaning of each field here. You can refer to my article "How to Package a qmake Ubuntu mobile app as a snap app". In particular, in our Snapcraft.yaml file, we define a new environment part (which can be any name we like). Inside it, it uses a CopyPlugin It photos.wrapper the current directory into the Bin/photos. The execution file in our command is photos. As we pack, we must remember to turn our script into executable scripts:
$ chmod a+x Photos.wrapper

In our project, because the CMake project does not contain any C + + code, we must use Qmlscene to start. This can be seen in our Photos.wrapper:
Photos.wrapper
#!/bin/sh arch= ' x86_64-linux-gnu ' export ld_library_path= $SNAP/usr/lib/$ARCH: $LD _library_path # XKB config export xkb_ config_root= $SNAP/USR/SHARE/X11/XKB # Qt Platform to Mir #export qt_qpa_platform=ubuntumirclient export Qtchooser_no_ Global_dir=1 Export QT_SELECT=SNAPPY-QT5 # QT Libs export ld_library_path= $SNAP/usr/lib/$ARCH/qt5/libs: $LD _library_ PATH export ld_library_path= $SNAP/usr/lib/$ARCH/pulseaudio: $LD _library_path # Qt Modules export qt_plugin_path= $SNAP/ usr/lib/$ARCH/qt5/plugins export qml2_import_path= $SNAP/usr/lib/$ARCH/qt5/qml/photos export qml2_import_path= $QML 2
_import_path: $SNAP/usr/lib/$ARCH/qt5/qml export qml2_import_path= $QML 2_import_path: $SNAP/lib/$ARCH # Mesa Libs Export ld_library_path= $SNAP/usr/lib/$ARCH/mesa: $LD _library_path export ld_library_path= $SNAP/usr/lib/$ARCH/ MESA-EGL: $LD _library_path # XDG Config export xdg_config_dirs= $SNAP/etc/xdg: $XDG _config_dirs Export xdg_config_dirs=$ SNAP/USR/XDG: $XDG _config_dirs # note:this doesn ' t seem to work, QML ' s LocaLstorage either ignores # or fails to use $SNAP _user_data if defined here export xdg_data_dirs= $SNAP _user_data: $XDG _data_d IRS Export xdg_data_dirs= $SNAP/usr/share: $XDG _data_dirs # Good, needed for fontconfig export xdg_data_home= $SNAP/usr /share # Font Config export fontconfig_path= $SNAP/etc/fonts/config.d export fontconfig_file= $SNAP/etc/fonts/ Fonts.conf # Tell Libgl where to find the drivers export libgl_drivers_path= $SNAP/usr/lib/$ARCH/dri # necessary for the SDK to find the Translations directory export app_dir= $SNAP # Ensure the Snappy GL Libs win export ld_library_path= "$SNAP
 _library_path: $LD _library_path "CD $SNAP exec $SNAP/usr/bin/qmlscene $SNAP/share/qml/photos/main.qml

In the last sentence above, it shows us how to launch our application:
EXEC $SNAP/usr/bin/qmlscene $SNAP/share/qml/photos/main.qml

We can enter the following commands directly in our project root directory:
$ snapcraft

It can package our app as the snap app package we want.
about how to install and run our app. I'm not going to be too tired here. Please read my article "How to Package a qmake Ubuntu mobile app as a snap app".

Below, we put a screenshot of the results of the run as shown below:
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.