gentoo下编译arm64版本Qt5.5 for android

首先下载android sdk ndk 以及Qt源码qt-everywhere-opensource-src-5.5.1.tar.xz
解压到/home/gentoo/qt-everywhere-opensource-src-5.5.1,然后在源码外其他位置新建编译目录,首先

export ANDROID_API_VERSION=android-21

编译目标为android 5.0

/home/gentoo/qt-everywhere-opensource-src-5.5.1/configure -xplatform android-g++ -nomake tests -nomake examples -android-ndk  /opt/android-ndk/ -android-sdk /opt/android-sdk-update-manager -android-ndk-host linux-x86_64  -android-toolchain-version 4.9  -skip qtwebkit -skip qtserialport  -skip qttranslations -skip qtwebkit-examples -no-warnings-are-errors -android-ndk-platform android-21 -android-arch arm64-v8a --prefix=/home/gentoo/Qt5.5.1/5.5/android_arm64 -opensource  -confirm-license

make -j8


报错:

In file included from /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/random:38:0,
                 from /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/stl_algo.h:66,
                 from /opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/algorithm:62,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/include/QtCore/../../src/corelib/global/qglobal.h:85,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/include/QtCore/qglobal.h:1,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/include/QtCore/../../src/corelib/thread/qatomic.h:34,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/include/QtCore/qatomic.h:1,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh:45,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/src/3rdparty/harfbuzz-ng/src/hb-object-private.hh:37,
                 from /run/media/gentoo/sda5/qt-everywhere-opensource-src-5.5.1/qtbase/src/3rdparty/harfbuzz-ng/src/hb-blob.cc:34:
/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/cmath: In function 'constexpr int std::fpclassify(float)':
/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.9/include/cmath:562:33: error: 'FP_NAN' was not declared in this scope
   { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL,

解决:

修改qtbase/src/3rdparty/harfbuzz-ng/Makefile,将里面的-std=c++11删掉

继续make

报错:

qt-everywhere-opensource-src-5.5.1/qtimageformats/src/3rdparty/libwebp/src/dsp/dec.o:dec.c:function VP8DspInit: error: undefined reference to 'VP8DspInitNEON'

解决:

修改qt-everywhere-opensource-src-5.5.1/qtimageformats/src/3rdparty/libwebp/src/dsp/dsp.h

将#define WEBP_USE_NEON改为#define WEBP_USE_NEON1

android arm64似乎不支持neon。

继续make

报错:

qt-everywhere-opensource-src-5.5.1/qttools/src/assistant/3rdparty/clucene/src/CLucene/util/Misc.cpp:24:24: fatal error: sys/timeb.h: No such file or directory
 # include 

解决:

新版ndk移除了这个头文件,自己touch一个空文件即可

touch /opt/android-ndk/platforms/android-21/arch-arm64/usr/include/sys/timeb.h

继续make


接下来make install

报错:

mkdir: 无法创建目录"/libs": 权限不够

解决:

sudo mkdir /libs

sudo chmod 777 /libs

重新make install

/libs创建了目录arm64-v8a,里面有个文件libqtplugininfo.so,不知道有什么用。


现在可以在qt-creator中添加安装的Qt version了。

但是你会发现用这个版本的Qt编译出来的程序无法在android5.x下运行,这不是Qt的错,是android的bug.

在androidl下,如果一个app是arm64-v8a的,假设包名为org.qt.example,那么/data/data/org.qt.example/lib是一个无效的软链接,指向了错误的位置。

所以我们要在Qt中修复这个链接。

在安装目录android_arm64/src/android/java/src/org/qtproject/qt5/android/bindings/QtActivity.java文件中增加几行:

+++ QtActivity.java	2015-12-26 21:29:24.000000000 +0800
@@ -37,6 +37,7 @@
 package org.qtproject.qt5.android.bindings;
 
 import java.io.File;
+import android.system.Os;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.InputStream;
@@ -843,6 +844,11 @@
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        try{
+        Os.remove(getApplicationInfo().dataDir+"/lib");
+        Os.symlink(getApplicationInfo().nativeLibraryDir,getApplicationInfo().dataDir+"/lib");       
+       }catch(Exception e){}
+        
 
         try {
             m_activityInfo = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);


重新构建Qt工程,部署到手机上即可成功运行。


你可能感兴趣的:(gentoo下编译arm64版本Qt5.5 for android)