http://ads.buzzcity.net/adpage.php?partnerid=40096
分类: 嵌入式
2011-05-11 17:17:37
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 repositoryCompile QtCreatorgit clone git://gitorious.org/~taipan/qt-creator/android-qt-creator.git
To compile QtCreator you need to use the usual qmake & make sequence.
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
of-course you have to replace /opt/QtSDK/Desktop/Qt/471/gcc/bin/qmake with the path you've installed QtSDK.
Compile Qt framework
Prepare & compile Qtgit clone git://gitorious.org/~taipan/qt/android-lighthouse.git
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:
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.
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.
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.
RequirementsYou 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.
Figure 1. Set Qt Path for Qt Creator to Qt Sdk for Android
Figure 2. Set Android Sdk, Ndk & Ant Path - With this view you can even manage the AVDs you created (AVD stands for Android Virtual Device)
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 CreatorQt 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++ ProjectCreate 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 VersionOnce 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 targetedWhen 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 ViewClick 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 ConfigurationsSelect Run view and then by selecting Details at the side of Package Configurations you can select between the Manifest, Application, Permissions and Libraries tabs.
Manifest TabIn 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.
Figure 1. You can choose the Android target SDK (Android Level API) and the other Manifest information of you Android Qt application.
Application TabOn the Application tab you can choose an icon for your application and set the application's name.
Permissions TabWith 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.
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 TabThe 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.
Figure 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 ConfigurationsAlso 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 libsThe 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 libsThe 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 systemInstall 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.
Figure 4. The Deploy Configuration of the Projects Run View provides different ways to deploy Qt on the Android Virtual Devices following needs
Using CLIThis part will be added, as soon as we update the helper scripts for CLI development with Qt on Android.
ConclusionYou 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
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 KitFor 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 SdkDebugging 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.
Figure 1. Changing Android target Sdk to one which supports native multi threaded applications debugging
Rebuild your applicationPlease 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.
Figure 2. Clean & Rebuild everything in debug mode