从命令行开发适用于Android的Qt应用 [英] Developing a Qt app for Android from the command line

查看:59
本文介绍了从命令行开发适用于Android的Qt应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用QtCreator或Android Studio的情况下,使用vi/emacs和OS X命令行使用Qt 编写的简单helloworld程序编译并部署在Android设备上.

I would like to compile and deploy on an Android device a simple helloworld program written using Qt purely using vi/emacs and the OS X command line, without using QtCreator or Android Studio.

页面介绍了如何填写ANDROID_SDK_ROOTANDROID_NDK_ROOT等的值,然后再编译Qt5.过去,我曾经使用QtCreator来为Android进行编译,而不必自己编译Qt,而现在我想知道是否可以使用命令行工具链来做到这一点.

This page describes how to fill in values for ANDROID_SDK_ROOT, ANDROID_NDK_ROOT, etc, before compiling Qt5. I have in the past used QtCreator to compile for Android without having to compile Qt itself, and I'm now wondering whether it's possible to use a command-line toolchain to do the same.

到目前为止,我采取的步骤是:

The steps I've taken so far are:

  1. 安装了 Android SDK .
  2. 安装了 Android NDK .
  3. sudo port install qt5-mac安装了Qt5.
  1. Installed the Android SDK.
  2. Installed the Android NDK.
  3. Installed Qt5 by sudo port install qt5-mac.

在这最后一步之后,我适当地看到了/opt/local/share/qt5/mkspecs/android-g++,这表明第一步应该是qmake -spec android-g++.

After this last step, I duly see /opt/local/share/qt5/mkspecs/android-g++, which suggests that the first step ought to be qmake -spec android-g++.

您是否已在OS X上成功编译并从命令行将Qt项目部署到Android而不需要编译Qt本身?

Have you successfully compiled on OS X and deployed to Android a Qt project from the command line without having to compile Qt itself?

更新

在OS X上运行sudo port install qt5-mac似乎未安装Qt-for-android.改为下载 qt-opensource-mac-x64-1.6.0-8-online.dmg .挂载/运行.单击,直到Select Components.确保选择Android armv7.

Running sudo port install qt5-mac on OS X appears not to install Qt-for-android. Download instead qt-opensource-mac-x64-1.6.0-8-online.dmg. Mount/run. Click until Select Components. Make sure Android armv7 is selected.

推荐答案

您需要什么:
-Java JDK
-Apache ANT
-Android SDK
-Android NDK
-适用于Android的Qt

What you need:
- Java JDK
- Apache ANT
- Android SDK
- Android NDK
- Qt for Android

设置环境变量(相应更改):

Set the environment variables (change accordingly):

export ANDROID_HOME=/Path/To/AndroidSDK  
export ANDROID_NDK_HOST=linux-x86  
export ANDROID_NDK_PLATFORM=android-12  
export ANDROID_NDK_ROOT=/Path/To/AndroidNDK  
export ANDROID_NDK_TOOLCHAIN_PREFIX=arm-linux-androideabi  
export ANDROID_NDK_TOOLCHAIN_VERSION=4.8  
export ANDROID_NDK_TOOLS_PREFIX=arm-linux-androideabi  
export ANDROID_SDK_ROOT=/Path/To/AndroidSDK  
export ANDROID_API_VERSION=android-12  

export JAVA_HOME=/Path/To/JavaJDK  
export PATH=$PATH:$ANDROID_HOME/tools:/Path/To/ApacheANT/bin:$JAVA_HOME/bin  

如果您使用的是OS X,请改用以下行:

If you're on OS X, use the following line instead:

export ANDROID_NDK_HOST=darwin-x86_64

Build for Android:

Build for Android:

mkdir build_myproj_android  
cd build_myproj_android  
/Path/To/QtForAndroid/bin/qmake -r -spec android-g++ /Path/To/MyProject/MyProject.pro  
make  
make install INSTALL_ROOT=android  
/Path/To/QtForAndroid/bin/androiddeployqt --output android --verbose --input android-libMyProject.so-deployment-settings.json  

最后,使用以下命令进行部署:

And finally, deploy using:

/Path/to/AndroidSDK/platform-tools/adb install /Path/to/build_myproj_android/android/bin/QtApp-debug.apk

这篇关于从命令行开发适用于Android的Qt应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆