Difference between revisions of "Using Qt for Android"

From Tuxamito
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
= Installation =
 
= Installation =
 
* Qt 5.12.0
 
* Qt 5.12.0
* QtCreator 4.8.0
+
* QtCreator 4.8.1
 
+
* Android Studio 3.3
* Android SDK Tools, Revision 26.1.1 (September 2017)
 
* Android NDK r18b
 
* OpenJDK 11 (Java)
 
  
 
== Qt libraries and QtCreator ==
 
== Qt libraries and QtCreator ==
  
In the website of Qt, [https://info.qt.io/download-qt-for-application-development download the Qt installer open-source application development].  Then go to the directory where it is downloaded, make it executable and run it as root:
+
In the website of Qt, [https://www.qt.io/download download the Qt installer open-source application development].  Then go to the directory where it is downloaded, make it executable and run it as root:
  
 
<pre>
 
<pre>
Line 25: Line 22:
 
[[File:qtinst2.png]]
 
[[File:qtinst2.png]]
  
Make sure that the Tools and a version of the Qt libraries are selected, inside it also select the android packages:
+
Make sure that the Tools and a version of the Qt libraries are selected, inside it also select the android packages (you can remove the sources packages and save some storage space):
  
[[File:qtinst3.png]]
+
[[File:qtinst3b.png]]
  
 
Once the installation is finished you can add the ''qtcreator'' executable to the system PATH or link into a directory that is already in it:
 
Once the installation is finished you can add the ''qtcreator'' executable to the system PATH or link into a directory that is already in it:
Line 37: Line 34:
 
== Android Tools & SDK ==
 
== Android Tools & SDK ==
  
To install the android tools follow the next instructions (the recommended version for now is r25.2.5). The first step is to download it and decompress it:
+
We will use the [https://developer.android.com/studio/ Android Studio (that you can download here)] to install the necessary Android components. Go to the directory where it was downloaded, unzip it and execute it:
 +
 
 
<pre>
 
<pre>
sudo mkdir -p /opt/android
+
unzip android-studio-ide-xxx.yyyyyyy-linux.zip
wget https://dl.google.com/android/repository/tools_r25.2.5-linux.zip
+
cd android-studio/bin
mkdir android-sdk
+
./studio.sh
cd android-sdk
 
unzip ../tools_r25.2.5-linux.zip
 
 
</pre>
 
</pre>
  
Then execute it to download the rest of the components:
+
On the next screen, there is no need to import anything, but you can do it if you have a previous installation:
<pre>
+
 
cd tools
+
[[File:As01.png]]
./android update sdk
+
 
</pre>
+
Then select custom installation:
 +
 
 +
[[File:As02.png]]
  
Make sure that ''Android SDK Platform-tools'', ''Android SDK Build-tools'' and at least one of the ''Android API'' are selected:
+
Then select the "Android Virtual Device" option to be able to test the android applications in a simulated device in your computer. You can also change the installation path of the android components (for example, I like to have them in the hidden directory ".Android" inside the home of my user account):
  
[[File:Androidtools1.png]]
+
[[File:As03.png]]
  
[[File:Androidtools2.png]]
+
Then review the configuration and wait till all the android components are installed. When the starting window of the Android Studio start (if it does not start automatically, then launch it again) click on "Configure -> SDK Manager".  Inside the SDK Manager click on "SDK Tools" and install the NDK component as shown in the picture:
  
Then accept the license and after the installation is finish move the Android SDK to an accessible directory.
+
[[File:As05.png]]
<pre>
 
cd ../..
 
sudo mv android-sdk/ /opt/android/
 
</pre>
 
  
The next step is to install the Android NDK (version r10e is recommended by Qt). Download it, uncompress it and copy it to the same directory as the SDK with the following commands:
+
You can install other SDK platforms to support older versions of Android.
  
<pre>
 
wget https://dl.google.com/android/repository/android-ndk-r10e-linux-x86_64.zip
 
unzip android-ndk-r10e-linux-x86_64.zip
 
sudo mv android-ndk-r10e /opt/android/android-ndk
 
</pre>
 
  
 
== Integrate Android Tools in QtCreator ==
 
== Integrate Android Tools in QtCreator ==
  
First install the necessary dependencies:
+
First install the necessary dependencies, which include the java openjdk version 8, as newer ones might not work:
 
<pre>
 
<pre>
sudo apt install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 libsdl1.2debian:i386
+
sudo apt install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 libsdl1.2debian:i386 openjdk-8-jdk openjdk-8-jre
 
</pre>
 
</pre>
  
 
Then open QtCreator and go to the menu ''Tools -> Options -> Devices -> Android''. There set the paths to the different components as shown in the next image:
 
Then open QtCreator and go to the menu ''Tools -> Options -> Devices -> Android''. There set the paths to the different components as shown in the next image:
  
[[File:Qtcreatorandroid.png]]
+
[[File:Qtandroid01.png]]
  
Then check in the menu ''Tools -> Options -> Build & Run -> Kits'' that the Android Kits appear:
+
If all goes fine, the QtCreator building Kits for Android are automatically added:
  
[[File:Qtcreatorandroid2.png]]
+
[[File:Qtandroid02.png]]
  
 
From that moment QtCreator will be able to compile and generate apk files from your Qt applications so that they can be executed in Android.
 
From that moment QtCreator will be able to compile and generate apk files from your Qt applications so that they can be executed in Android.

Latest revision as of 22:16, 20 January 2019

Installation

  • Qt 5.12.0
  • QtCreator 4.8.1
  • Android Studio 3.3

Qt libraries and QtCreator

In the website of Qt, download the Qt installer open-source application development. Then go to the directory where it is downloaded, make it executable and run it as root:

chmod 777 qt-unified-linux-x64-3.0.6-online.run
sudo ./qt-unified-linux-x64-3.0.6-online.run

When the next window appears then click on skip to continue without registering:

Qtinst1.png

Then choose the installation path, the default one is usually a good choice:

Qtinst2.png

Make sure that the Tools and a version of the Qt libraries are selected, inside it also select the android packages (you can remove the sources packages and save some storage space):

Qtinst3b.png

Once the installation is finished you can add the qtcreator executable to the system PATH or link into a directory that is already in it:

sudo ln -sf /opt/Qt/Tools/QtCreator/bin/qtcreator.sh /usr/local/bin/qtcreator


Android Tools & SDK

We will use the Android Studio (that you can download here) to install the necessary Android components. Go to the directory where it was downloaded, unzip it and execute it:

unzip android-studio-ide-xxx.yyyyyyy-linux.zip
cd android-studio/bin
./studio.sh

On the next screen, there is no need to import anything, but you can do it if you have a previous installation:

As01.png

Then select custom installation:

As02.png

Then select the "Android Virtual Device" option to be able to test the android applications in a simulated device in your computer. You can also change the installation path of the android components (for example, I like to have them in the hidden directory ".Android" inside the home of my user account):

As03.png

Then review the configuration and wait till all the android components are installed. When the starting window of the Android Studio start (if it does not start automatically, then launch it again) click on "Configure -> SDK Manager". Inside the SDK Manager click on "SDK Tools" and install the NDK component as shown in the picture:

As05.png

You can install other SDK platforms to support older versions of Android.


Integrate Android Tools in QtCreator

First install the necessary dependencies, which include the java openjdk version 8, as newer ones might not work:

sudo apt install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386 libsdl1.2debian:i386 openjdk-8-jdk openjdk-8-jre

Then open QtCreator and go to the menu Tools -> Options -> Devices -> Android. There set the paths to the different components as shown in the next image:

Qtandroid01.png

If all goes fine, the QtCreator building Kits for Android are automatically added:

Qtandroid02.png

From that moment QtCreator will be able to compile and generate apk files from your Qt applications so that they can be executed in Android.

Older Instructions