Android: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(make instructions completed)
(-android-toolchain-version 4.8 -> 4.9. (4.8 does not support the -fstack-protector-strong option, and fails during configure))
Line 1: Line 1:
[[Category:HowTo]]
[[Category:HowTo]]
[[Category:Qt for Android]]
[[Category:Qt for Android]]
These are build instructions for building Qt for Android on Linux or Mac OS X. For cross-compiling on Windows, this is currently [[building_qt-android_on_windows | possible under cmd.exe]].
These are build instructions for building Qt for Android on Linux or Mac OS X. For cross-compiling on Windows, this is currently [[Building qt-android on windows| possible under cmd.exe]].


For general information about Qt 5 for Android, please visit the [[Qt5ForAndroid | wiki]] for that.
For general information about Qt 5 for Android, please visit the [[Qt5ForAndroid| wiki]] for that.


N.B.
N.B.
Line 23: Line 23:
#** Note that this is only necessary for building Qt itself. You can build Qt applications against any API level you wish, As long as it is equal to or higher than 13.
#** Note that this is only necessary for building Qt itself. You can build Qt applications against any API level you wish, As long as it is equal to or higher than 13.
# You also need an Android NDK: https://developer.android.com/tools/sdk/ndk/index.html
# You also need an Android NDK: https://developer.android.com/tools/sdk/ndk/index.html
#* '''Important:''' Download and use NDK r10. This is because NDK r11, r12 and r15 are known to have issues<ref name="known-issues">[[Qt_for_Android_known_issues | Known issues with the Qt for Android build]]</ref>. NDK r13 and r14 are also likely to have the same issues. r15 produces applications that fail with the error message 'This application failed to start because it could not find or load the Qt platform plugin "android"'.
#* '''Important:''' Download and use NDK r10. This is because NDK r11, r12 and r15 are known to have issues<ref name="known-issues">[[Qt for Android known issues| Known issues with the Qt for Android build]]</ref>. NDK r13 and r14 are also likely to have the same issues. r15 produces applications that fail with the error message 'This application failed to start because it could not find or load the Qt platform plugin "android"'.
# Get Qt Creator 2.7.2 (or later): http://qt.io/download#qt-creator
# Get Qt Creator 2.7.2 (or later): http://qt.io/download#qt-creator
# Get Qt 5:
# Get Qt 5:
Line 35: Line 35:
#*$JAVA_HOME (e.g /usr/lib/jvm/java-6-openjdk-i386) You need a JDK (version 1.6+, required 32bit) and you should also have this in your PATH.
#*$JAVA_HOME (e.g /usr/lib/jvm/java-6-openjdk-i386) You need a JDK (version 1.6+, required 32bit) and you should also have this in your PATH.
# Configure Qt and skip unsupported modules:
# Configure Qt and skip unsupported modules:
#:<pre>./configure -xplatform android-g++ --disable-rpath -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -android-ndk-host <e.g. linux-x86_64> -android-toolchain-version <e.g. 4.8> -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors</pre>
#:<pre>./configure -xplatform android-g++ --disable-rpath -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -android-ndk-host <e.g. linux-x86_64> -android-toolchain-version <e.g. 4.9> -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors</pre>
# Build. Run the ''make'' command to build the configured Qt parts.  
# Build. Run the ''make'' command to build the configured Qt parts.  
#:<pre>make</pre>
#:<pre>make</pre>

Revision as of 19:50, 9 November 2017

These are build instructions for building Qt for Android on Linux or Mac OS X. For cross-compiling on Windows, this is currently possible under cmd.exe.

For general information about Qt 5 for Android, please visit the wiki for that.

N.B.

  • When using GCC toolchains on Windows (MinGW, Android NDK, etc.) take into account that there is a restrictions on a build path prefix length QTBUG-52242.
  • When using MSys shell you should not pass Unix-like paths in -prefix argument QTBUG-52675

Building Qt 5 for Android

These are the current build instructions to get to the point where you can deploy a Qt app to an Android device using Qt Creator.

  1. First of all you need an Android SDK.
    • The SDK is bundled with Android Studio: https://developer.android.com/studio/index.html
    • Open Android Studio and run the SDK Manager tool, which is found under Tools > Android > SDK Manager.
    • For Qt 5.6 or earlier: Install API levels 10, 11, 16 and 18 (you may need to check the "Obsolete" checkbox to see these in the SDK manager). Beginning with Qt 5.7, any API level >= 18 will work.
      • Android API level 11 is required to build QtMultimedia.
      • Android API level 18 is required to build QtBluetooth (from Qt 5.5 onwards).
      • Android API level 10, 11 and 16 are required for QtBase.
      • Note that this is only necessary for building Qt itself. You can build Qt applications against any API level you wish, As long as it is equal to or higher than 13.
  2. You also need an Android NDK: https://developer.android.com/tools/sdk/ndk/index.html
    • Important: Download and use NDK r10. This is because NDK r11, r12 and r15 are known to have issues[1]. NDK r13 and r14 are also likely to have the same issues. r15 produces applications that fail with the error message 'This application failed to start because it could not find or load the Qt platform plugin "android"'.
  3. Get Qt Creator 2.7.2 (or later): http://qt.io/download#qt-creator
  4. Get Qt 5:
    git clone git://code.qt.io/qt/qt5.git qt5
    cd qt5
    perl init-repository
  5. Optionally checkout target Qt version to use.
    git checkout v5.9.1
    git submodule update --recursive
  6. Configure Environment Variables You need to set up environment variables for the following:
    • $JAVA_HOME (e.g /usr/lib/jvm/java-6-openjdk-i386) You need a JDK (version 1.6+, required 32bit) and you should also have this in your PATH.
  7. Configure Qt and skip unsupported modules:
    ./configure -xplatform android-g++ --disable-rpath -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -android-ndk-host <e.g. linux-x86_64> -android-toolchain-version <e.g. 4.9> -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors
  8. Build. Run the make command to build the configured Qt parts.
    make
  9. Install. Run the make install command to install the built Qt parts. If you have not used the configure option --prefix <install-dir> the installation is done under the directory path /usr/local/Qt-<version>. Under Debian/Ubuntu you yould prefix the make commd with the sudo command.
    make install
  10. Start the Qt Creator you built earlier.
  11. Go into Tools-> Options -> Android and set the right paths to the Android SDK and NDK, etc. For example:
    • Android SDK Location: /home/johnsmith/dev/android-sdk-linux
    • Android NDK Location: /home/johnsmith/dev/android-ndk-r10e
    • JDK Location: /usr/lib/jvm/java-6-openjdk-i386
  12. Add your newly built Qt version to Options -> Build & Run -> Qt Versions.
  13. At this point you should be able to create a project and configure it for the Android kit. In order to test, go into the Run settings for your project. Under Deploy Configuration, check the Use Qt libraries from local device option. Also select the Deploy local Qt libraries radio button.

References