如何在Android上构建Qt5?

12

我有一台运行Ubuntu 12.04 LTS的服务器。

我想利用这个服务器为Android ARMv6平台构建Qt5。如何在无头服务器上操作?

2个回答

11

以下是在Ubuntu 12.04 LTS上编译Qt5适用于Android所需的步骤。为方便起见,我将假设所有下面的命令都在目录/opt/qt5-android中运行。如果不是这种情况,则需要相应地调整路径。

  1. 首先您需要确保安装了适当的软件包:

sudo apt-get install build-essential openjdk-6-jdk
  • 获取最新的Android SDK:

    wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz
    tar -xf android-sdk_r21.1-linux.tgz
    
  • SDK不附带任何平台,所以您需要获取它们:

  • android-sdk-linux/tools/android update sdk --no-ui
    
  • 获取最新的NDK版本:

    32位(i686):

    wget http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86.tar.bz2
    tar -xf android-ndk-r8e-linux-x86.tar.bz2
    

    64位(amd64):

    wget http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2
    tar -xf android-ndk-r8e-linux-x86_64.tar.bz2
    
  • 现在克隆以下Git存储库:

  • git clone git://gitorious.org/qt/qt5.git qt5
    cd qt5
    perl init-repository --no-webkit
    
  • 我们快到了。现在需要配置编译Qt5:

  • ./configure \
        -developer-build \
        -xplatform android-g++ \
        -nomake tests \
        -nomake examples \
        -android-ndk /opt/qt5-android/android-ndk-r8e \
        -android-sdk /opt/qt5-android/android-sdk-linux \
        -skip qttools \
        -skip qttranslations \
        -skip qtwebkit \
        -skip qtserialport \
        -skip qtwebkit-examples-and-demos
    make
    

    就这样!现在您应该已经拥有了适用于Android的Qt5构建。


    参考资料:


    5

    我不是要用答案回答另一个答案,但这是我的第一篇帖子 :-( 我认为这阻止了我在评论中发布此内容。(因此请将其视为对该答案的引用,而不是对其的回复)。

    Nathan上面提供的答案对我并没有完全起作用。

    我的配置行看起来更像这样:

    ./configure \
    -developer-build -platform linux-g++-64 \
    -xplatform android-g++ \
    -nomake tests \
    -nomake examples \
    -android-ndk /opt/qt5-android/android-ndk-r8e \
    -android-sdk /opt/qt5-android/android-sdk-linux \
    -skip qttools \
    -skip qttranslations \
    -skip qtwebkit \
    -skip qtserialport \
    -android-ndk-host linux-x86_64
    

    这是为什么:
    • -skip qtwebkit-examples-and-demos 在配置时导致错误... 它不喜欢我跳过一些无法构建的东西(抱歉,我丢失了确切的错误消息)

    • -android-ndk-host linux-x86_64 防止配置中止并显示“无法检测到 android 主机。请使用 -android-ndk-host 选项来指定一个

    • -platform linux-g++-64 是我对于配置是否会在工作时通过魔法添加 -m64 标志等的担心

    除此之外,Nathan 的步骤看起来非常完美。我的本地环境已经构建成功了(感谢提示,Osman 先生:-)


    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接