Linux qt creator android

Using QtCreator on Linux to cross compile for Android

This is a log of setting up a development environment. I am using Ubuntu 14.04.

My ultimate goal is to use pyqtdeploy to distribute a (Python, PyQt, Qt) app to Android (and iOS.)

Installing QtCreator

QtCreator is a cross platform IDE. I have been using Eclipse and PyDev, but QtCreator might be better, since it comes from the Qt project.

( This bug report explains that the version 3.0.1 of QtCreator shipped with Ubuntu 14.04 will give the error message:

Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable

so I downloaded a later version of QtCreator 3.1.0. You can’t just use >sudo apt-get install qtcreator.

In my experience, Ubuntu lags behind on Qt, and Qt changes rapidly, so it is worthwhile to download the latest Qt.)

At this website I chose the ‘Qt Online Installer’, and the file ‘qt-opensource-linux-x86-1.6.0-4-online’ was downloaded. Then give it execute permission and click on the downloaded file. The ‘Qt Setup Wizard’ app opens. Accept the defaults, and newer versions of Qt and Qt Creator will be downloaded to ~/Qt directory. (This will include the Qt library built for ARM i.e. for Android.)

(As explained by the Qt project, Qt is supports iOS, but QtCreator doesn’t support iOS directly, you will need to use a .pro file AND the Apple Xcode IDE for that. This blog may apply to using OSX as the host and cross compiling to Android.)

Install more tool chain

Qt Creator (when cross compiling for Android) relies on:

Installing Android SDK

Under ‘SDK Tools Only‘, choose a package to download. (I don’t want a package that includes the Eclipse IDE or the newer ‘Android Studio’ IDE, since I am using the QtCreator IDE.)

Extract the package, say to your home directory.

Refreshing the Android SDK

Now you have just the basics, as explained here by the Android team. You use the ‘Android SDK Manager’ to download more. It is a package manager. You can start it from a command line:

>cd ~/android*/tools >./android sdk

A GUI app will open. It lets you browse a tree directory of packages to install. It will open with an appropriate set (the latest) packages you need to download. That includes:

  • Android SDK Platform-tools
  • Android SDK Build-tools
  • a version of the Android API
Читайте также:  Linux install application command

I unselected the latest version of the Android API (Android L, API 20 preview) and selected the next API (since I don’t want to mess with a possibly unstable API.)

Now choose the ‘Install packages ‘button.

Downloading the Android NDK

The SDK is for developing in Java. You need the NDK for developing in C.

Navigate your browser to the Android Developer website page for downloading the NDK. Choose the download for your host word length (32-bit or 64-bit) (in my case, 32-bit Ubuntu 14.04) and for your target Android word length (in my case, 32-bit, since I am just testing and have no specific target device in mind.)

Extract the download, say to your home directory.

Installing Ant

(I’m not sure what kind of tool ant is.)

Install a JDK

You can use the Ubuntu Software Center to find the name of the package and download it. Search for ‘JDK’ and also choose ‘Show xxx technical items’ near the bottom. I chose openjdk-7-jdk, but clicking the ‘Install’ button didn’t seem to work, so…

>sudo apt-get install openjdk-7-jdk

Configure QtCreator to use the tool chain: SDK, NDK, ant, and JDK

Start QtCreator and choose Tools>Options>Android. Click the ‘Browse’ buttons and navigate to the location where you downloaded the tools. (For many of them, Qt Creator leads you to the right place, but for the JDK I had to navigate to /usr/lib/jvm/java-7-openjdk-i386.

Configure QtCreator to use the Android kit

Choose Tools>Options>Build&Run. Choose ‘Android for armeabi-v7a (GCC 4.8, Qt 5.3.1)’, which is auto-detected.

Create an example Project

I followed this tutorial. I don’t really want to use QtQuick, but this is just an example.

(I also took shortcuts with the example. Instead of displaying an SVG file and moving it, I just displayed the white rect that appears in the default QML.)

After creating the project, I clicked on the ‘Run’ icon. Now it says that I do not have an Android device. It offered to create one for me (a ‘Create Android Virtual Device’ button.) I clicked on that, entered a name for the device, and clicked OK. Then I got an error: ‘Error: invalid –tag default …’ (I suppose it is a bug in QtCreator that might be finessed by different choices.) But I decided to use Android tools to create an AVD….

Читайте также:  Криптопро браузер плагин линукс

Create an AVD using the Android AVD Manager tool

An AVD is a simulator, or Android virtual device. The Android project provides a tool ‘Android Virtual Device Manager’ for creating them.

>cd ~/android*/tools >./android avd

A GUI app will open. Create an AVD. (Glossing the details, but the defaults usually work, and for a clean development machine, you will only see the choices from the things you installed earlier.)

I suppose the list of AVD’s is in a standard place that QtCreator knows about.

Testing

Now in QtCreator when I click the Run button, it:

  • lets me chose the AVD I just created
  • proceeds to build,
  • starts the AVD
  • downloads my app to the AVD

It takes a while for the AVD to boot itself. For a while you may see a black screen or a green arc going in circles. I don’t think the app can load while it is booting. (When it finishes booting, you can interact with the AVD like a real phone, using the mouse. It seems to start in Android’s ‘Getting Started’ help screens (several screens telling you that a swipe does) just as if you had just powered up a newly purchased and activated phone.)

I suppose QtCreator timed out waiting for the AVD to boot. I got:

Unable to start 'org.qtproject.example.accelbubble'.

But the AVD kept running. I tried the Run button again. This time, the application seemed to start on the AVD: it displayed a white rectangle. I tried to click with the mouse in the app to close it, that didn’t work. A swipe with the mouse (pressing the LMB while moving) killed the app in the AVD.

Источник

Getting Started with Qt for Android

The video below is a beginner’s guide to using the Qt for Android toolchain, including the Qt Creator IDE, to get you started developing Android apps.

The rest of this page has more detailed getting started information. To download and install Qt for Android, follow the instructions on the Getting Started with Qt page.

Android Development Prerequisites

  • Java Development Kit (JDK) for Java development
  • Android SDK Command Line Tools for managing dependencies required for developing with Qt for Android, including:
    • Android SDK Platform
    • Android SDK Platform Tools
    • Android SDK Build Tools
    • Android NDK

    The easiest way to manage these dependencies is by using Qt Creator’s built in Android development setup. For more information, see Qt Creator: Specifying Android Device Settings.

    Manually Installing the Prerequisites

    If you prefer to manually install the prerequisites please follow these next steps.

    Java Development Kit (JDK)

    Qt for Android development requires JDK 11 or above, provided by any of the following supported distributions:

    Please install your preferred JDK, and then make sure the JAVA_HOME environment variable is pointing to the location of the installed JDK.

    sudo apt-get install openjdk-11-jdk export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
    brew install openjdk@11 sudo ln -sfn "$(brew --prefix openjdk@11)/libexec/openjdk.jdk" "/Library/Java/JavaVirtualMachines/openjdk-11.jdk" export JAVA_HOME="$(/usr/libexec/java_home -v 11)"

    Android SDK Command Line Tools

    Install the latest version of the Android SDK Command Line Tools for your operating system, and verify that the installation succeeded by running the sdkmanager binary:

    Then make sure the ANDROID_SDK_ROOT environment variable is pointing to the location of the installed command line tools.

    brew install android-commandlinetool export ANDROID_SDK_ROOT="$(brew --prefix)/share/android-commandlinetools"

    Android SDK

    The required version of the Platform, Platform Tools, and Build Tools for 6.5 is 33.

    To install all of these run the following command:

    sdkmanager "platforms;android-31" "platform-tools" "build-tools;33.0.0"

    Android NDK

    The required version of the Android NDK for 6.5 is 25.1.8937393.

    To install the NDK run the following command:

    Then make sure the ANDROID_NDK_ROOT environment variable is pointing to the location of the installed NDK.

    export ANDROID_NDK_ROOT="$(brew --prefix)/share/android-commandlinetools/ndk/23.1.7779620/"

    Emulator

    If you wish to use the Android Emulator, you can install it by running:

    sdkmanager "emulator" "patcher;v4"

    Platform Specific Configurations

    Windows

    The default USB driver on Windows does not allow debugging using Android Debug Bridge (ADB) tool. You must install the additional USB driver provided by the extras Android SDK package. To install it, run the following:

    sdkmanager.bat "extras;google;usb_driver"

    After the package installation is complete, install the driver from /extras/google/usb_driver . Try running a few basic adb commands now and check whether your Android device responds to them.

    Linux

    The following dependencies are needed for using tools such as adb or gdb which can be used by Qt Creator:

    sudo apt-get install libstdc++6 libncurses5

    To run the Android emulator, the following dependencies are also necessary:

    sudo apt-get install libsdl1.2debian

    Testing Your Setup

    Now you can test your development setup by running the examples shipped with the Qt installation. For more information, see Qt for Android Examples.

    To develop a simple application from scratch, see Qt Creator: Creating a Mobile Application.

    © 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

    Источник

Оцените статью
Adblock
detector