Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1107639
  • 博文数量: 276
  • 博客积分: 8317
  • 博客等级: 少将
  • 技术积分: 2329
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-12 08:17
个人简介

http://ads.buzzcity.net/adpage.php?partnerid=40096

文章分类

全部博文(276)

文章存档

2013年(1)

2012年(38)

2011年(102)

2010年(85)

2009年(45)

2008年(5)

分类: 嵌入式

2011-05-11 17:17:37

前面说过我以前规划过的东西已经有人在做了,而且在我的后续规划里提到的那些feature也已经陆陆续续在android-lighthouse这个项目里得到了实施。看到android-lighthouse取得的成绩,唯一遗憾的是实施的人不是我而已。不过没有关系,这里记录一下他们的构建过程,对自己也是一份参考和帮助。
Compile QtCreator
Requirements

To compile QtCreator you need Qt framework, if your system doesn't ship a version >=4.7.0 you mustdownload one

Clone android-qt-creator repository

git clone git://gitorious.org/~taipan/qt-creator/android-qt-creator.git

Compile QtCreator

To compile QtCreator you need to use the usual qmake & make sequence.

cd /path/to/cloneOfandroid-qt-creator qmake -r make -j3

you have to replace 3 with the number of CPU′s your PC have + 1

If you use QtSDK you must use full path for qmake command

/opt/QtSDK/Desktop/Qt/471/gcc/bin/qmake -r

of-course you have to replace /opt/QtSDK/Desktop/Qt/471/gcc/bin/qmake with the path you've installed QtSDK.

Compile Qt framework

RequirementsClone android-lighthouse repository

git clone git://gitorious.org/~taipan/qt/android-lighthouse.git

Prepare & compile Qt

cd /path/to/cloneOfandroid-lighthouse/, use androidconfigbuild.sh to configure and compile Qt framework. Use the following command if you configure/compile Qt for the first time:

./androidconfigbuild.sh -r /where/you/install/android/ndk -q 1

Previous command will cleanup any older configuration, and then will configure & build (for debugging) Qt framework, it will take a while until everything is finished.

If you want ONLY to compile Qt (you MUST have it previously configured) you should useandroidconfigbuild.sh without -q 1 option.

./androidconfigbuild.sh -r /where/you/install/android/ndk

After Qt finish the compilation you can add it to QtCreator Qt Versions, check [Setup QtCreator] page for more informations.

To complete the job, you have to push qt libs to your device.
QtCreator can do this job for you, if you check Deploy local qt libs option (Projects->Android (run tab)->Deploy configurations->Deploy local qt libs) check the picture below.

Deploy local qt libs

androidconfigbuild.sh accepts the following parameters (you can see all options by adding -help to script parameters):

usage: ./androidconfigbuild.sh options

OPTIONS:

-help Shows this message

-r NDK root. Default "/usr/local/android-ndk-r5"

-h NDK host. Default "linux-x86"

-p NDK toolchain prefix. Default "arm-linux-androideabi"

-v NDK toolchain version. Default "4.4.3"

-a Target cpu architecture. Default "armeabi" armeabi - tune for android arm v5 armeabi-v7a - tune for android arm v7

-q Qt build options. 0 - don't configure qt (only compile) default 1 - configure qt and compile qt

-d Build type. Default "1" 1 - Compile and link Qt with debugging turned on. 0 - Compile and link Qt using release compilation flags, it also contains debugging informations.

-c Patch qt. 0 - don't patch qt (used to make the installer) 1 - patch qt (default)

-i Install path. Default "/data/data/eu.licentia.necessitas.ministro/files/qt"

Setup QtCreator

After you finish to Install QtCreator or you finish to [Compile QtCreator] you have to set it up.

Requirements
  • Ant version: Please check your ant version before using Qt Creator, you should at least have ant 1.8.0. You can check with the ant -version command.
  • Java Development Kit: The optimal Java Development Kit for Necessitas is the OpenJDK. You can check with the java -version command if you have it, you can also install it if you don't have the OpenJDK with thesudo apt-get install openjdk-6-jdk command.
Configure Qt Creator

You will just need to set up the Qt in Path to the freshly installed Qt for Android Sdk, and to provide the android Sdk to use.

  • Previous step should have installed you Qt Creator for Android, you will find a shortcut on your desktop.
  • Run Qt Creator for Android and click on Tools > Options, then jump to the Qt4 tab. Just add the qmake path from the Qt For Android Sdk (/opt/necessitas/Android//bin/qmake by default).
  • Give this Qt version a name (e.g. android-lighthouse-4.8.0).

Set Qt Path in Qt CreatorFigure 1. Set Qt Path for Qt Creator to Qt Sdk for Android

Set Android Sdk, Ndk & Ant Path in Qt CreatorFigure 2. Set Android Sdk, Ndk & Ant Path - With this view you can even manage the AVDs you created (AVD stands for Android Virtual Device)

  • Jump back to the Qt4 tab, select the version of Qt you added previously and build the gdb helpers, so that your debugging output will be clean and easily readable for Qt specific constructs.
  • Click Apply & Ok and you are done, you can start using the awesome Qt Sdk for Android.
  • You can now try: [How to write Qt apps for Android]
How to write Qt apps for Android

There are multiple ways to develop Qt Applications for Android, the easiest one is to use the fabulous Qt Creator For Android enabling you to deploy, run and debug Qt and your Qt application on the device.

Although if you are more used to the CLI using an advanced text editor, or if you want to use another IDE thenecessitas framework provides you scripts you can use to manage your Qt for Android projects. Both ways are explained in the subchapters.

Using Qt Creator

Qt Creator is a first class IDE for developing Qt Applications with the different tools it provides. Developing a Qt Application for Android with the Qt Creator provided in the necessitas framework lets programmers be productive and enjoy Android application development in C++.

Create a new Qt C++ Project

Create a new Qt C++ Project, this can either be a Qt Gui Project or a Qt Mobile Application (in this case you will have to remove the body of MainWindow::setOrientation generated by Qt Creator, which contains references to Qt For Symbian).

Choose the Qt Version

Once you have chosen the project name QtCreator will ask you which Qt version to use. It should propose by default those you configured: android-lighthouse-4.8.0 debug & android-lighthouse-4.8.0 release. Check them if they aren’t already selected and deselect any other Qt versions which are available.

Android version targeted

When your project is created, you are almost done, you will just need to select which android version you are targeting and how you want to deploy the Qt Libs onto the device.

The Projects View

Click on the Projects view (the icon is located on the left hand side of the QtCreator window): Qt for Android Integration adds two views here: Build & Run which appear in a small box towards the top of the main window, clicking on Build or Run swaps between the Build and Run views within the Project View.

The Run ViewPackage Configurations

Select Run view and then by selecting Details at the side of Package Configurations you can select between the ManifestApplicationPermissions and Libraries tabs.

Manifest Tab

In the Manifest tab you can select which Android target SDK you want to use. This provides the different API levels which match specific Android versions. You can find more information about API levels and how they equate to the Android version here.

Note: android-4 API level is the only one which doesn’t support multitouch, so if your application needs multitouch you have to chose a higher one.

You can choose a Package name for your application, indeed the application is launched by an automatically generated java launcher, which will be packaged with your application in an .apk (more information about the .apk: Android Application Fundamentals), and an apk has to be in a package.

Package Manifest Figure 1. You can choose the Android target SDK (Android Level API) and the other Manifest information of you Android Qt application.

Application Tab

On the Application tab you can choose an icon for your application and set the application's name.

Permissions Tab

With the Permissions tab you can pick which permissions are needed for your application, so that the people installing it, will know what it will do, and that the Android OS will give your application access to the required features.

Package Permissions Figure 2. You can easily pick one of the existing Android permissions, or add yourself new ones if you are deploying for a specific Android OS.

Libraries Tab

The Libraries tab will offer you an automatic way to determine which Qt libraries you use! Or if needed let you select manually the Qt libraries and the external libraries you think your application needs. These entries will be used by the Ministro tool to determine which Qt libraries have to be downloaded.

Libraries thumbFigure 3. This gives the Java Loader the list of required Qt Libraries and other prebundled libraries, that should get loaded with your application. It also provides to ministro the list of Qt Libraries required.

Deploy Configurations

Also on the Run view you can set the Deploy Configurations, by selecting Details at the right hand side these are the different options you can choose between:

Use devices qt libs

The Use devices qt libs option depends also on the Use local qt libs option. When Use local qt libs is unchecked your application will need the Ministro package to run. However if Use local qt libs is checked, Qt Creator will pass special parameters to the application, forcing it to use Qt libraries from the/data/local/qt path on the device.

Deploy local qt libs

The Deploy local qt libs option makes Qt Creator deploy qt libs found in the Qt SDK chosen (e.g. android-lighthouse-4.8.0). This option is useful when you hack on the Qt framework to test it.

This option automatically selects the Use local qt libs option. This option get automatically unchecked after Qt Creator pushes the Qt libs. This option can be checked every time you need to push your local Qt modifications. (In fact it has the same effect as the push_qt_libs.sh script, which can be found at the root of the Qt for Android Sdk). You do not need to check Deploy local qt libs to take advantage of the Use local qt libs option.

Install Ministro system

Install Ministro system option installs the Ministro package (actually it installs any .apk you select :) ) for you. It is useful when you try to test your application on Android Virtual Devices. You can get theMinistro .apk on the Google Market or from here.

Deploy ConfigurationFigure 4. The Deploy Configuration of the Projects Run View provides different ways to deploy Qt on the Android Virtual Devices following needs

Using CLI

This part will be added, as soon as we update the helper scripts for CLI development with Qt on Android.

Conclusion

You are done, you can now enjoy the development phase. :) You can build and run your application on the device. You will notice that the application output is forwarded to Qt Creator and that you can get interesting debugging information there, plus you can also set breakpoints.

Debugging Qt apps for Android

Warning

Debugging multi-thread applications on Android is possible starting with android 2.2.1 version (if you are using AVD you have to choose android 2.3 or later), for more informations please check NDK-GDB.html file located into android-ndk-folder/docs.

Replace gdb version of the Android Native Development Kit

For a seamless debugging experience you should replace the default android-ndk gdb with 7.1.x or 7.2 (download). You can simply overwrite the /pathTo/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/folder with one of the arm-linux-androideabi-4.4.3 folder present in the tar archive.

Change Android target Sdk

Debugging native multi threaded applications on Android (Qt applications are multi threaded) is supported only since the android-10 API level, so please choose this level or a higher one if you want to be able to debug your applications.

Choose android-10 as Android target Sdk

Figure 1. Changing Android target Sdk to one which supports native multi threaded applications debugging

Rebuild your application

Please take care that you have to rebuild the application in debug mode, if you want to be able to debug it. Click on the project source tree and rebuild everything before trying to launch in debug, it will not be done automatically.

Rebuild you application

Figure 2. Clean & Rebuild everything in debug mode

阅读(1497) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~