Qt on Android Episode 3)

Source: Internet
Author: User

 

After learning how to build an android development environment, we will continue in this article and learn how to use Qt Creator 3.0 to create, run, debug, and deploy Qt applications on Android. This article only covers Android-related parts of Qt Creator.

Prepare your android Qt Project

If you want to start a new project or just want to test whether the development environment you just set up is correct, make sure to select an android suite when creating a project. View the following image:

If you already have a project and want to support Android, you only need to add an android kit for an existing project. View the following image:

To compile, deploy, run, and debug Android applications, you must first select an android suite. View the following image:

Let's have a try.

To test the application on Android, you only need to clickRun/DebugButton.

A dialog box will appear soon listing all connected compatible and incompatible devices and available simulators. Select the desired device. If you want to use the same device to run the application multiple times, selectUse this device for architecture ..This means that Qt Creator will automatically use this device and will not bother you any more. The following figure shows my computer:

If no device is listed, check whether the development environment is correctly configured.

After a while, your application should be running on your device. If you choose AVD, it will take some time to start and be patient.

If you selectUse this device for architecture .., Qt Creator will remember this option until you reset the default device or close the project. To reset the default device, you must selectProjectsView, clickRunTag, expandDeploy deploymentsAnd clickReset Default DevicesButton.

You don't need to do anything special to debug the Qt app on a device or simulator, it was born to work, just make sure your device uses Android API-10 +.

Android Manifest

Each Android Application requires a manifest file. This is the entry to your application. Android uses this file to determine which application or activity to start. It includes the permissions of the application, the required API version, and many other content.

Androiddeployqt(A tool, Qt Creator uses it to deploy your application) use an Android Manifest template and fill in several default values to run your application. However, this is not enough to publish your application. Therefore, we need to create an xml file named AndroidManifest. xml. To do this, openProjectsView, clickRunTag, expandDeploy deploymentsClick Create AndroidManifest. xml. Don't forget to add this file to your SCM. View the following image to see how you can create the AndroidManifest. xml file:

Now, after creating the AndroidManifest. xml file, it is time to set it. After you create the AndroidManifest. xml file, Qt Creator automatically opens it. Take a look at this image:

As you can see, Qt Creator provides a good and easy-to-use editor for AndroidManifest. xml. With this editor, you can set the following values:

 

Package nameThe package name is a reversed URL. For example, do not change com. kdab. QtControlsExample as a unique identifier after it is published. Otherwise, the application cannot be upgraded. Version code/nameThe next step is to set the version number and version name. You don't need to change anything at the beginning, but each time you release a new application, you must change these values, so they are very important. Version Number-Android and the market use it to distinguish different version names-user-visible version strings, Android OS and the market will show that it needs to change each new release

 

 

Minimum and target SDK. Qt Creator uses the minimum and target sdks to set node attributes. SDK for the minimum requirement-edit the android: minSdkVersion attribute, which is an integer API version. The android Market uses it to filter devices that can install this application. Android OS also uses it to prevent apps from being installed to lower versions. Target SDK -- edit the android: targetSdkVersion attribute.

The android document said: "This property notifies the system that you have tested the target version. The system should not use any compatibility behavior to maintain the forward compatibility of your application to the target version. The application can still run on a lower version (until minSdkVersion ).

This attribute has no effect on Android applications that only use Qt.

 

 

Application name, Qt Creator can only help you set the name of the English version of the application. RunHere you should select the application you want to launch. Most projects only have one application, so there is no need to choose anything here. PermissionsPermissions are very important to an android program. If you do not set them correctly, your application will not be able to access system resources (such as networks and external storage ). Starting from the Qt 5.2 SDK, qmake uses ANDROID_PERMISSIONSVariable to set the minimum permission set for each Qt module (these will be AndroiddeployqtBut in some cases you need to manually add or remove them. Qt Creator provides a good permission editor to help you do this.

 

Your application should not declare excessive permissions than it actually requires, which will scare users away.

 

In my QtQuick example application, the Android manifest editor of Qt Creator looks like the following. My example applications do not require any special permissions, So I deleted them all.

Android manifest is quite complex. Sometimes you need to manually edit it. Qt Creator allows you to switch to the XML source code. As shown in:

Android manifest is an animal! Read the manifest page for Android: http://developer.android.com/guide/topics/manifest/manifest-intro.html to learn about it.

Android Target SDK,This SDK is used to compile the Java part of your application.

Don't worry about choosing the highest SDK, your app can still run on any Android device using API-9 +, Qt java only uses API-9 code.

"What are you talking about? Another SDK? How many sdks do we need to set ?" Okay, there are a total of four Android sdks. There are three in the manifest file (minimum, target, and maximum). Here is one.

Additional Library, Use this editor to add any third-party libraries to your project. Qt Creator edit your. pro file and setANDROID_EXTRA_LIBSQmake variable. Of course, developers should not mix incompatible libraries. For example, x86 libraries cannot be used in arm-specific applications.

As the KDAB guide says, I should not create articles with more than one thousand words (this article is much more than enough), so I have to stop. Next time, we will look at the deployment system of Qt on Android and how to sign the package. These two steps are the most important thing before the release.

 

Review:

 

Qt on Android Episode 1 (translation) Qt on Android Episode 2 (translation) Windows Qt 5.2 for Android development entry

 

Related Article

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.