Build the android development environment of qt5.1.0beta

Source: Internet
Author: User
Build the android development environment of qt5.1.0beta

There was nothing to do during my resume recently. I took a weekend to study how to set up the android development environment of qt5.1.0beta. The past two days have passed, which is a small achievement. I would like to share it with you here.

First, let's take a look at the new features of qt5.1.0beta. In addition to some major and minor changes in the module, we also found that it supports static compilation and support for Android and iOS build goals. Static compilation is put aside first. Let's take a look at how qt5.1.0 supports the android development environment.

It is stated that this process is cumbersome. If you want to use this software product, you may wish to wait until the stable version of qt5.2 is released. This tutorial is only applicable to Linux, and I use ubuntu13.04.

Original article, opposed to unstated reference. Original blog address: http://blog.csdn.net/jiangcaiyang123/article/details/8978815

1. Prepare some necessary Development Kits

Follow the instructions in QT-project to download the android SDK, ndk, Apache ant, and openjdk. Android SDK and ndk are required for building the QT Android version. The jar package and tools in the SDK must be used in the make stage, the header file and source file in the ndk need to be used to encapsulate the qtandroid plug-in. Openjdk and ant are required when the application is packaged into an APK. For the convenience of everyone, I will release it.

Android SDK. Here I downloaded ADT, which includes eclipse and SDK. Please ignore eclipse.

Android ndk,

Openjdk, enter sudo apt-Get install openjdk-6-jre in Ubuntu

Ant.

2. Download qt5.1.0beta

Do not download the binary package. We need to compile it ourselves, so we need to download the source package. The link is provided here. If the link becomes invalid, you can search for it here.

3. decompress the source code package.

It should not be a problem to decompress the package, but there is an inexplicable ^ m symbol in the subsequent stages. At this time, I began to wonder if it was wrong to decompress the package ......

In fact, the archive manager of the GUI is used for decompression. By default, the text encoding problem occurs. Therefore, to prevent text files in the source code from being changed to the text format, manually decompress the files on the console. Assume that the downloaded folder is input. The compressed package name is qt5.1.0beta.zip ~ /Programs/qt5.1.0forandroid:

Unzip-A qt5.1.0beta.zip-D ~ /Programs/qt5.1.0forandroid

Cancel the qt-everywhere-opensource-src-5.1.0-beta1 folder and place the content directly in qt5.1.0forandroid. I like the simple folder name.

4. Start configure

After decompression, enter ~ The/programs/qt5.1.0forandroid folder starts the configure stage. I prefer where to decompress the package and qmake, which can save the make install step. However, you can try to add the-Prefix parameter to set the installation location. Here I will follow the steps on the official website to write configure.

. /Configure-developer-Build-xplatform Android-G ++-nomake tests-nomake examples-Android-ndk your ndk path-Android-SDK your SDK path-Android-ndk- host is a 32-bit Linux operating system on the fill linux-x86, 64-bit fill in linux-x86_64-Skip qttranslations-Skip qtwebkit-Skip qtserialport-Skip qtwebkit-Examples

The following are my configure parameters:

. /Configure-developer-Build-xplatform Android-G ++-nomake tests-nomake examples-Android-ndk/home/jiangcaiyang/programs/android-ndk-r8e-Android-SDK/home/jiangcaiyang/ programs/adt-bundle-linux-x86-20130514/SDK-Android-ndk-host linux-x86-Skip qttranslations-Skip qtwebkit-Skip qtserialport-Skip qtwebkit-Examples

If you select the open-source version by default, add-opensource to the above parameters to reduce the number of queries.

In addition, the Android version cannot be compiled statically, because the cannot find-lqandroid error occurs when the target file of the code written by the user is linked. It seems that qandroid must still exist as a plug-in.

5. Start make

Make has the most errors, so you must pay special attention to them.

If you do not have preparations, make may also work, but the compiled library functions are incomplete, so you cannot run the APK program on the simulator.

To prevent missing paths, you need to add two Android environment variables. Enter the following in the console:

Export android_sdk_root =/home/jiangcaiyang/programs/adt-bundle-linux-x86-20130514/SDK

Export android_api_version = Android-17

To prevent missing Java compilation tools such as javac, you need to add the java_home environment variable in/etc/profile:

Export java_home =/usr/lib/JVM/java-6-openjdk-i386

To prevent the DX tool and DX. jar package, Dx and DX. jar from adt-bundle-linux-x86-20130514/SDK/build-tools/Android-4.2.2 and adt-bundle-linux-x86-20130514/SDK/build-tools/Android-4.2.2/lib go to/home/jiangcaiyang/programs/adt-bundle-linux-x86-20130514/SDK/ in platform-tools. (Here, the installation path is used as an example)

To prevent qtmultimedia for Android requires API level 11 errors, you need to run the $ {qt_dir}/qtmultimedia. Pro statement:

! Qtcompiletest (Android): Error ("qtmultimedia for Android requires API level 11 ")

Comment out.

If everything goes well, no project error will be visible.

6. Start make install (optional)

If-prefix is specified in the configure stage, make install is required.

7. Set Environment Variables

In addition to the previous java_home, we still need several environment variables, but they are used on qtcreator, which is not difficult.

Install qtcreator2.7 and open it. Click Tools to go to the options page. The first step is to set the QT version, for example.

Then set the android option. For example:

Here, automatically create kits for Android tool chains is convenient. Three Android kits are automatically added to the build kit, but the compilers are different. Then start the android AVD manager, such:

Click new... to add a simulator, for example:

Set some parameters, and then click Start... to start the simulator. If you think the simulator screen is very slow, you can check the use host GPU option.

8. build and run

We can test a program. Here I tested a QT program: appchooser (in $ {qt_dir}/qtbase/examples/widgets/animation ).

Use qtcreator to open appchooser. in the pro file, select "add build Kit" on the project tab and add the building kit we just set up. Now I will select the one automatically generated by the system, because the icons of the robot are very nice!

As you can see, there are many more files, which are very common files in eclipse. In fact, I don't understand them either. However, this does not affect the operation. As before, click "build with a hammer" and click "run with a green triangle. It takes a long time to open the simulator during running, and the interface will be stuck for a while. At this time, you can prepare a cup of coffee.

The simulator cannot be used to create an APK package. If the java_home variable and ant path are incorrectly set or the JDK version is messy, the package cannot be smoothly packaged, so the previous steps should be noted.

If you create an APK package, you may not be able to run it correctly. This is probably a problem with the QT library. Check the project tab and follow the steps shown on the official website to set it as follows:

In this way, it can run on the simulator. You can also install the Ministro package. I have not studied the debugging and deployment of the real machine.

Okay. Let's take a look at our results.

The screen is too small. change to a larger screen!

If you have any questions, leave me a message and I will do my best to help you solve them.

Refer:

Qt-Project wiki: http://qt-project.org/wiki/Qt5ForAndroid

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.