顯示具有 qt android 標籤的文章。 顯示所有文章
顯示具有 qt android 標籤的文章。 顯示所有文章

2014年9月14日 星期日

qt 5.4 alpha for android

1st edition: 20131002
2nd edition: 20140914

qt 5.4 alpha

env:
debian 32 bit
ndk: android-ndk-r10
sdk: adt-bundle-linux-x86-20140702

為了 camera 的問題, 終於等到你。

../qt-everywhere-opensource-src-5.4.0-alpha/configure  -xplatform android-g++ -nomake tests -nomake examples -android-ndk /home/descent/and-dev/android-ndk-r10 -android-sdk /home/descent/and-dev/adt-bundle-linux-x86-20140702/sdk -android-ndk-host linux-x86 -android-toolchain-version 4.8 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples

不過在我辛苦 build 好 5.4 之後, camera app 還是無法正常在我的 kolin 7 吋平版上使用。

白作工了。

qt 5.2 alpha

env:
ubuntu 12.04 64bit
qtcreator : 2.8.0
g++ version: (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
ndk: android-ndk-r9
sdk: adt-bundle-linux-x86-20130522
android api 版本安裝了 10, 11, 16, 17, 18 有些沒裝會出錯, 這是我一一補齊的結果。

這次畫面總算對了。



qt 5.2 alpha 沒有 binary 可用, build from source.

get qt 5.2 alpha source code:
http://download.qt-project.org/development_releases/qt/5.2/5.2.0-alpha/single/

ref:
build android qt version from source code:
http://qt-project.org/wiki/Qt5ForAndroidBuilding

我自己用的 configure 參數:
export ANDROID_BUILD_TOOLS_REVISION=18.1.0
所以 build-tools path 是
adt-bundle-linux-x86-20130522/sdk/build-tools/18.1.0

../qt-everywhere-opensource-src-5.2.0-alpha/configure -developer-build -xplatform android-g++ -nomake tests -nomake examples -android-ndk /home/descent/android-dev/android-ndk-r8e -android-sdk /home/descent/android-dev/adt-bundle-linux-x86-20130522/sdk -android-ndk-host linux-x86 -android-toolchain-version 4.7 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples 

../qt-everywhere-opensource-src-5.2.0-alpha/configure  -xplatform android-g++ -nomake tests -nomake examples -android-ndk /home/descent/android-dev/android-ndk-r9 -android-sdk /home/descent/android-dev/adt-bundle-linux-x86-20130522/sdk -android-ndk-host linux-x86_64 -android-toolchain-version 4.8 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples 
-developer-build 會把 warnning 當成錯誤, 所以我拿掉了。
記得
make install
這步驟一定要做, 要不然設定 qtcreator 會怪怪的。

qt 5.2 安裝後的目錄結構:
ls /usr/local/Qt-5.2.0/
bin  doc  imports  include  jar  lib  mkspecs  plugins  qml  src
設定 qtcreator
tool/options/Build & Run/Qt Versions add qt5.2 qmake
tool/options/android 設定 sdk, ndk

使用 qtcreator 很容易有問題, 我搭配 adb 指令來把 a3.apk (自己寫的測試程式) 傳到模擬器上。

2014年8月1日 星期五

qt 5.3 for android - 編譯流程 (指令篇)

env:
linux debian unstable 32bit

  1. adt-bundle-linux-x86-20140702.zip
  2. android-ndk32-r10-linux-x86.tar.bz2
  3. qt-creator-opensource-src-3.1.2.tar.gz
  4. qt-opensource-linux-x86-android-5.3.1.run
  5. qt-everywhere-opensource-src-5.3.1.tar.gz
總共需要 1, 2, 3 (本篇不需要這個), 4, 第五項是 qt 5.3.1 source code, 如果想要自己編譯 qt for android, 才會需要這個, 不過 qt 預先編譯好的應該就夠用了。

第三項是因為 qt-opensource-linux-x86-android-5.3.1.run 內附的 qt-creator 我每次都無法正常開啟, 所以我需要從 source code 編譯。

設定 qtcreator
tool/options/Build & Run/Qt Versions add /home/descent/Qt5.3.1/5.3/android_armv7/bin/qmake。
tool/options/android 設定 sdk, ndk

不過還好, qtcreator 已經用不到了,以下是全指令的編譯方式, 我已經受夠了按按紐只得到錯誤訊息, 根本編不出任何東西來。

以 /media/winxp/android-dev/qt-everywhere-opensource-src-5.3.1/qtbase/examples/widgets/itemviews/dirview/ 範例來介紹編譯流程:

export ANDROID_NDK_ROOT=/home/descent/and-dev/android-ndk-r10/
/home/descent/Qt5.3.1/5.3/android_armv7/bin/qmake dirview.pro 

descent@debianlinux:dirview$ ls
android-libdirview.so-deployment-settings.json  dirview.pro  main.cpp  Makefile
descent@debianlinux:dirview$ 

make # 編譯出 libdirview.so, 一般的 qt 程式到這裡就結束了, android app 還有其他步驟要做。
make install INSTALL_ROOT=./android-build # 初使化 android build 目錄

/home/descent/and-dev/adt-bundle-linux-x86-20140702/sdk/tools/android
選擇 Tools/Manage AVDs, 先把模擬器執行起來。

/home/descent/Qt5.3.1/5.3/android_armv7/bin/androiddeployqt --input android-libdirview.so-deployment-settings.json  --output ./android-build --deployment bundled --install --ant /usr/bin/ant --android-platform android-20 --jdk /usr/lib/jvm/java-7-openjdk-i386 --device emulator-5554 # 先建立 build.xml 讓 ant 使用, 再去 call ant 建立 apk, 並把 apk 傳到模擬器中

descent@debianlinux:platform-tools$ ./adb devices
List of devices attached 
emulator-5554 device 

到這裡應該可以在模擬器執行這個 app 了。

也可以從 /home/descent/and-dev/dirview/android-build 下 ant 指令
ant clean release
編譯出 *.apk

/home/descent/and-dev/dirview/android-build/android-build/bin/*.apk

我有遇到以下紅色部份的錯誤訊息, 我不知道如何設定正確的路徑, 只好建立一個 symbolic link 到該路徑, 就沒有問題了, 也不用在啟動那個很大很慢的 qt creator 了。
Android build platform: android-20
Install to device: emulator-5554
Cannot find Android tool: /opt/android/sdk/tools/android

--android-platform android-17 android 4.2.2
--android-platform android-20 android 4.4w

我另外安裝了 api-17 for android 4.2.2。

你也許會好奇我怎麼知道這些指令的, 噢! 那個折磨我的 qt creator 裡頭有 log 可以看, 從裡頭挖出這些指令。

androiddeployqt 指令: http://qt-project.org/doc/qt-5/deployment-android.html

在手機上 (歌林 7 吋雙核雙卡手機平板) 的執行畫面 (3 apps):



檔案大小和所安裝需要的權限:


這是以 NDK 方式執行的, 應該有效率的優勢, 但是最近火紅的 zenfone 可能無法執行, 得要重編譯一個 x86 版本才行。

從 5.1, 5.2 到 5.3 總算讓我搞定開發環境了。

debian 64bit

env:
debian 64bit

for run /home/descent/android-dev/adt-bundle-linux-x86_64-20140624/sdk/platform-tools/adb
adb 還沒有 64bit 版本, 需要安裝相對應的 i386 套件。

sudo dpkg --add-architecture i386
apt-get update
sudo apt-get install libc6:i386 libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386

for android emulator
sudo apt-get install libsdl1.2debian:i386

ref: http://stackoverflow.com/questions/2710499/android-sdk-on-a-64-bit-linux-machine

若用舊版 qtcreator 可能遇到這問題 (我覺得直接用最新版的 source code 編譯解決這問題比較好):
Qt5 for Android: incompatible ABI
http://stackoverflow.com/questions/22238649/qt5-for-android-incompatible-abi
QtCreator -> Projects -> BuildEnvironment add the variable
ANDROID_TARGET_ARCH = default/armeabi-v7a

/home/descent/Qt5.3.1/5.3/android_armv7/bin/androiddeployqt --input android-liba1.so-deployment-settings.json  --output ./android-build --deployment bundled --install --ant /usr/bin/ant --android-platform android-17 --jdk /usr/lib/jvm/java-7-openjdk-amd64/ --device emulator-5554 --verbose

我很想測試一下 iOS 版本, 我也有 mac, 不過版本太舊, 無法執行 iOS toolchain, 所以等待未來購入新 mac 機器再來測試。

同樣的 source code, 可以產生 linux/X, windows, mac, android 這些平台的應用程式, 實在令人興奮, 這樣的投資很划算阿!

android 2.3.3 api 10

根據這份文件 Qt5.3 For Andoid 安装过程, 需要安裝Android armv5。



會多出一個 Qt5.3.1/5.3/android_armv5/, 不過我使用這目錄的 qmake, androiddeployqt, 還是無法成功編譯出 android 2.3.3 的 app。

~/Qt5.3.1/5.3/android_armv5/bin/qmake dirview.pro

/home/descent/Qt5.3.1/5.3/android_armv5/bin/androiddeployqt --input android-libdirview.so-deployment-settings.json   --output ./android-build --deployment bundled --install --ant /usr/bin/ant --android-platform android-10 --jdk /usr/lib/jvm/java-7-openjdk-i386 --verbose

--verbose 在有錯誤時可以印出多點訊息。

不管他了。

我似乎搞錯了,  查看 android-build/AndroidManifest.xml
41 <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
即可確認這個 android app 可以在哪個版本執行, 我在模擬器和真實機器 (twm amazing a1 android 2.3.3) 測試過, 可以正常執行。所以不需要特別下
--android-platform android-10 用 --android-platform android-20 就可以了。

ref:

2013年7月14日 星期日

打造 qt 5.1 for android 開發環境

the 1st edition: 20130714
the 2nd edition: 20160303

用 qt 來開發 android app 的支援已經有一陣子, 但我期待著 qt 官方的版本, 我是個有耐心的開發者, 終於讓我等到 qt 5.1 官方的版本。

但是該怎麼開始呢?照著這篇裝很多東西:
http://doc-snapshot.qt-project.org/qt5-stable/qtdoc/android-support.html
在 qtcreator 設定好這些路徑。

執行
adt-bundle-linux-x86-20130522/sdk/tools/android
安裝 android 2.3.3 (api 10)

download for android version.
http://qt-project.org/downloads

選 project android arm gcc 4.4.3



這比之前的版本設定的東西應該還更簡單, but, 如果你夠幸運的話才是這樣的結果。中途遇到很多小問題, 陸續亂 try, 總算有個結果。

我試過好幾個平台
  • ubuntu 10.04 64bit
  • debian 32bit
  • windows xp
遇到各式各樣的的小問題:
qtcreator 無法開啟:
strace 結果顯示卡在 clock_gettime
clock_gettime(CLOCK_MONOTONIC, {5315, 458918574}) = 0
clock_gettime(CLOCK_MONOTONIC, {5315, 459187882}) = 0
poll([{fd=3,   events=POLLIN}, {fd=6, events=POLLIN}, {fd=11, events=POLLIN}, {fd=13,   events=POLLIN}, {fd=16, events=POLLIN}, {fd=22, events=POLLIN}], 6,   169541) = 1 ([{fd=3, revents=POLLIN}])
read(3, "\1\0\0\0\0\0\0\0", 16)         = 8
clock_gettime(CLOCK_MONOTONIC, {5318, 204940484}) = 0
clock_gettime(CLOCK_MONOTONIC, {5318, 205176548}) = 0

Qt Creator 2.7.2:
http://qt-project.org/downloads
我自己 download 下載這版本, qt 5.1 裡頭的 qtcreator 不知道為什麼無法執行起來。

ant 無法正常工作:
http://stackoverflow.com/questions/17483682/qt-5-1-for-android-occurs-error-in-apache-ant/17538419#17538419

ant 和 jdk 並不容易搞定,交給 apt 就好, 我用 apt 安裝就沒遇到這問題了。
install jdk/ant:
sudo apt-get install openjdk-7-jre openjdk-7-jdk 
sudo apt-get install ant

模擬器:

有時候無法正常啟動模擬器執行程式, 很不穩定。

最後在 debian 32bit 環境成功:
uname -a
Linux debian-vm 3.9-1-686-pae #1 SMP Debian 3.9.8-1 i686 GNU/Linux

我已經很少用 IDE, 在 qtcreator 下, 直接按個 run 就通通搞定, 快樂是快樂, 不過 ide 下到底做了什麼事情, 不知道的感覺很不好。

稍微看了一下整個步驟, 大概就是用 ndk 編譯 qt 產生 .so, 然後 qtcreator 產生的 java 程式會使用 jni 來呼叫這個 .so, ant 會使用 qtcreator 產生的 build.xml 來完成剩下的步驟。我看了一下 build.xml, 要手工打造這個可能不容易, 看來還是需要 qtcreator。

ref: Java Native Interface(JNI) 簡介與教學

qtcreator option/android setting
這是 qtcreator 在 apt-get 後自己抓到的路徑:
ant location:  /usr/bin/ant
openjdk location: /usr/lib/jvm/java-7-openjdk-i386

這個沒什麼功能的程式占了 21.72 MB, 也很耗記憶體, 看來不太能用, 等 qt 5.2 了。

20130902 補充:

若是遇到這情形:
http://qt-project.org/forums/viewthread/29299

我的作法是選用 api 17 version 的 emulator。

使用以下指令可以將 apk 複製到 emulator 上。
./adb install -r /home/descent/app1/android/bin/App1-debug-unaligned.apk
ref: http://developer.android.com/tools/help/adb.html

我實在不喜歡操作 qtcreator 這個大怪物, 使用以下 command line 編譯產生 app1.apk:

export ANDROID_NDK_ROOT=/home/descent/android-dev/android-ndk-r8e
~/android-dev/qt51/5.1.0/android_armv7/bin/qmake ~/app1/app1.pro
ant clean debug

上傳到 emulator:
descent@descent-u:platform-tools$ ./adb devices
List of devices attached
emulator-5554    device

./adb install -r ~/app1/android/bin/App1-debug.apk
2620 KB/s (671473 bytes in 0.250s)
pkg: /data/local/tmp/App1-debug.apk
Success

qt 5.X alpha 出了, 來試試: qt 5.4 alpha for android