-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Make app for Android
Tested on linux and OSX
Requirements:
- Qt (>= 5.2)
- ffmpeg (>= 2.2)
- QtCreator (3.1.0)
- QtAV (1.3.4 or last git)
Here we're skipping the standard steps for installation of Linux, SDK, NDK and Ant. Don't forget to update SDK Tools, Platform-Tools, Build-Tools.
I placed all these in /opt: SDK - /opt/Android/sdk/ NDK - /opt/Android/ndk/ Ant - /opt/apache-ant
Get the sources: Qt,(I build Qt 5.2.1) Note that Qt should be build for platform 19 unless it wouldn't be built. Subsequently, however, your custom applications can be built for any API version. Unpack qt-everywhere-opensource-src-5.2.1.tar.xz , go to the sources tree and launch the following script to build Qt itself for Android arm platform.
The script is:
#!/bin/sh
unset QTDIR
NDK_TOOLCHAIN_VERSION=4.8
PLATFORM=19
export JAVA_HOME=/usr/lib/jdk1.6.0_45
PATH=$JAVA_HOME/bin:$PATH
export ANDROID_SDK_ROOT=/opt/Android/sdk
export ANDROID_NDK_ROOT=/opt/Android/ndk
export ANDROID_API_VERSION=android-$PLATFORM
export ANDROID_PLATFORM=$PLATFORM
export ANDROID_NDK_PLATFORM=android-$PLATFORM
./configure -v \
-prefix /opt/qt5/arm \
-xplatform android-g++ \
-android-ndk /opt/Android/ndk \
-android-sdk /opt/Android/sdk \
-android-ndk-host linux-x86 \
-android-toolchain-version $NDK_TOOLCHAIN_VERSION \
-no-warnings-are-errors \
-confirm-license \
-opensource \
-skip qttranslations \
-skip qtwebkit \
-skip qtserialport \
-skip qtwebkit-examples \
-nomake tests \
-nomake examples
# use 'make -j <number of cpu cores>' for faster building
make
make install
If all went ok, the '/opt/qt5/arm' directory will be created. There will be the Qt built for Android there.
Get the sources: ffmpeg source I used version 2.2.1 Unpack the archive, and run the following build script. Configuration switches can be corrected, for your system can differ from mine. For example, I have Linux-32bit, so the config file contains linux-x86. For 64-bit system you should specify linux-x86_64.
#!/bin/bash
NDK=/opt/Android/ndk
SYSROOT=$NDK/platforms/android-14/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-programs \
--disable-doc \
--disable-symver \
--disable-encoders \
--enable-avdevice \
--enable-avresample \
--enable-runtime-cpudetect \
--enable-memalign-hack \
--enable-hwaccels \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=android \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" $ADDITIONAL_CONFIGURE_FLAG
make clean
# use 'make -j <number of cpu cores>' for faster building
make
make install
}
CPU=arm
PREFIX=/opt/qt5/arm
ADDI_CFLAGS="-marm"
build_one
Download the binary archive: QtCreator I used version 3.2.0
Unpack it where you like, e.g. '/opt/qtcreator'
The QtCreator customization is quite minimal. Only paths to sdk, ndk, ant should be specified. And also path to qmake, e.g. /opt/qt5/arm/bin/qmake
There many articles with screenshots explaining this on the Internet.
Now the main things!
Get QtAV:
git clone https://github.com/wang-bin/QtAV
Then launch QtCreator and open the project QtAV ( QtAV.pro). Add Android kit for armeabi-v7a and build the project with the button with a hammer The directory will appear like this: build-QtAV-Android_armeabi_v7a_GCC_4_8_Qt_5_2_1-Release
You would have different dependently on you compiler or if you have specified other name. So, we have two directories:
Run sdk_install.sh
in build dir. This will copy QtAV libraries to Qt dir to make sure we can create apk correctly.
qtcreator -> new project -> App -> App Qt Quick Choose, for example Qt Quick 2.2 Check Android kit in the checkbox.
An empty project will be created.
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
visible: true
width: 360
height: 360
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
}
Change the above into the following:
import QtQuick 2.2
import QtQuick.Window 2.1
import QtAV 1.3
Window {
id: window1
visible: true
width: 360
height: 360
Text {
height: 16
text: qsTr("Qt+QtAV+FFmpeg")
anchors.right: parent.right
anchors.rightMargin: 13
anchors.top: parent.top
anchors.topMargin: 8
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenterOffset: 68
}
VideoOutput {
anchors.right: parent.right
anchors.rightMargin: 13
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.top: parent.top
anchors.bottomMargin: 15
anchors.leftMargin: 14
anchors.topMargin: 60
source: player
}
AVPlayer {
id: player
source: "http://blablabla/video/test.mp4"
}
MouseArea {
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
onClicked: {
player.play();
}
}
}
Create AndroidManifest with QtCreator. The default settings are acceptable.
Add the following lines to the project file *.pro:
QT += av
Now we can launch it. There will appear the virtual device selection. We can choose any compatible device from the list, or create a new one.
After that there will be the APK-file in the build directory
build-XXXXXX-Android_armeabi_v7a_GCC_4_8_Qt_5_2_1-Release/android-build/bin/QtApp-debug.apk