代码之家  ›  专栏  ›  技术社区  ›  Abhishek

如何为使用NDK和SDK构建的Android项目设置Travis CI

  •  0
  • Abhishek  · 技术社区  · 6 年前

    我已经搜索了很多地方,甚至在Travis CI文档页面,但我找不到问题的解决方案。问题是- 我已经在Travis CI上建立了一个Android项目,效果很好。现在,我需要为我的项目编译一些本机文件 .在我的本地机器中,设置工作正常 SDK NDK 已安装。当我按下密码时,Travis抱怨 NDK公司 .所以,我想知道如何设置 NDK公司 为了特拉维斯。我关注以下链接---

    https://github.com/googlesamples/android-ndk/blob/master/.travis.yml

    Travis: how to know android sdk/ndk path?

    https://github.com/travis-ci/travis-ci/issues/5395

    但以上都不起作用。我的 travis.yml 文件位于下面--

    # which language/platform is used
    language: android
    # JDK version
    jdk:
    - oraclejdk8
    
    # root permission required?
    sudo: required
    dist: precise
    
    # Environment variables
    env:
      global:
      - BRANCH_NAME=$TRAVIS_BRANCH
    
    # android components required to build code
    android:
      components:
      - tools
      - platform-tools
      - build-tools-25.0.3
      - android-24
      - extra-android-m2repository
      - extra-google-m2repository
      - extra-google-google_play_services
    
    # clean up old stuff before we get started
    before_cache:
    - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
    
    # cache directories to use
    cache:
      directories:
      - "$HOME/.gradle/caches/"
      - "$HOME/.gradle/wrapper/"
    
    # Configurations to set up Android NDK
    before_install:
        - rm -fr $HOME/android-ndk-r16b
        - curl -L http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O
        - unzip -oq android-ndk-r16b-linux-x86_64.zip
        - rm android-ndk-r16b-linux-x86_64.zip
        - export ANDROID_NDK_HOME=$HOME/android-ndk-r16b
        - export PATH=$PATH:${ANDROID_NDK_HOME}
    
    # Build script - which configs and creates the builds
    script: "./my_script.sh"
    

    通过此设置,Travis CI可以识别 NDK公司 但在运行我的构建脚本时,它无法找到它。下面是我的Travis构建日志--

    android.install
    Installing Android dependencies
    creating directory /home/travis/.gradle/caches
    adding /home/travis/.gradle/wrapper to cache
    creating directory /home/travis/.gradle/wrapper
    $ java -Xmx32m -version
    java version "1.8.0_111"
    Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
    $ javac -J-Xmx32m -version
    javac 1.8.0_111
    before_install.1
    $ rm -fr $HOME/android-ndk-r16b
    before_install.2
    $ curl -L http://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O
    before_install.3
    $ unzip -oq android-ndk-r16b-linux-x86_64.zip
    before_install.4
    $ rm android-ndk-r16b-linux-x86_64.zip
    before_install.5
    $ export ANDROID_NDK_HOME=$HOME/android-ndk-r16b
    before_install.6
    $ export PATH=$PATH:${ANDROID_NDK_HOME}
    $ ./build_cc_app.sh
    To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.3/userguide/gradle_daemon.html.
    Daemon will be stopped at the end of the build stopping after processing
    Parallel execution with configuration on demand is an incubating feature.
    NDK is missing a "platforms" directory.
    If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /home/travis/android-ndk-r16b.
    If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
    NDK is missing a "platforms" directory.
    FAILURE: Build failed with an exception.
    * What went wrong:
    A problem occurred configuring project ':client'.
    > NDK not configured. /home/travis/android-ndk-r16b
      Download it with SDK manager.
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    BUILD FAILED
    Total time: 29.479 secs
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   D-Dᴙum    6 年前

    错误消息表示缺少 platforms 目录您可能可以通过请求在存储库上启用调试来进一步调查:

    Running build in debug

    此功能可用于私有存储库和公共存储库 已启用该功能的存储库。要拥有该功能 已启用公共存储库,请发送电子邮件至 support@travis-ci。com指示哪些。推送访问 还需要存储库。

    我发现Travis反应很快,但您还需要设置您的命令行客户端:

    Travis commandline client

        2
  •  0
  •   Abhishek    6 年前

    因此,在Travis CI构建上进行了大量的麻烦和调试之后,我找到了解决此问题的方法。显然,违约 android 工具链搜索 NDK 在its中 SDK 目录由于找不到,它在抱怨 NDK公司 因此,我必须使用默认的工具链来获取 NDK公司 。下面是我的 .travis.yml 文件,该文件指向我为解决此问题所做的更改。

    enter image description here

    找到我为什么添加 tools 两次,你可以参考这个 link 。请参阅下图,以确定要参考文档的哪一部分以获取答案。

    enter image description here

    因此,正如Travis CI文档中提到的,当我们想用 SDK 数量 24 ,我们需要使用 工具 中的两个选项 yml 剧本

    然后当我使用 ndk-build 要构建本机文件,我只需在 yml公司 剧本

    # Configurations to set up Android NDK
    before_install:
      - echo y | sdkmanager "ndk-bundle"
    

    有一件事要记住。我在使用 C 本机项目的语言。如果您正在使用 C++ ,则可能需要安装 Cmake 为此。下面是代码--

     before_install:
       - echo y | sdkmanager "ndk-bundle"
       - echo y | sdkmanager "cmake;3.6.4111459" # (Check the Cmake version you want to use)