Calaf
Calaf

Reputation: 10847

Developing a Qt app for Android from the command line

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.

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. Installed the Android SDK.
  2. Installed the Android NDK.
  3. Installed Qt5 by sudo port install qt5-mac.

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++.

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

Update

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.

Upvotes: 6

Views: 4885

Answers (2)

Musa
Musa

Reputation: 524

Thanks Marian that has wrote a complete response. just if you are going to sign your package too, say it to androiddeployqt by:

/Path/To/QtForAndroid/bin/androiddeployqt --output android --verbose --input android-libMyProject.so-deployment-settings.json --sign <url/to/keystore> <alias> --storepass <password>

Upvotes: 3

Marian Munteanu
Marian Munteanu

Reputation: 359

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  

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

export ANDROID_NDK_HOST=darwin-x86_64

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

Upvotes: 10

Related Questions