简体   繁体   English

我应该如何为Android库配置Travis-CI?

[英]How should I configure Travis-CI for an Android library?

I am developing an Android library ( RateMyApp , which you can find on GitHub) but I can't see how I should setup Travis CI to build it every time I push new code. 我正在开发一个Android库( RateMyApp ,您可以在GitHub上找到它),但我无法看到每次推送新代码时我应该如何设置Travis CI来构建它。

The .travis.yml file I am using is the following: 我正在使用的.travis.yml文件如下:

language: java
script:
    - gradle bundleRelease

but it seems to be ignored because gradle bundleRelease is never invoked. 但它似乎被忽略,因为从不调用gradle bundleRelease Instead I get the following output that suggests me that gradle assemble is invoked instead. 相反,我得到以下输出,表明我调用了gradle assemble

Using worker: worker-linux-8-1.bb.travis-ci.org:travis-linux-5

travis_fold:start:git.1
$ git clone --depth=50 --branch=master git://github.com/mariosangiorgio/RateMyApp.git
[...]
mariosangiorgio/RateMyApp
Cloning into 'mariosangiorgio/RateMyApp'...
done.
travis_fold:end:git.1    
$ cd mariosangiorgio/RateMyApp
travis_fold:start:git.3
$ git checkout -qf 90faf4539c835136895ea92dd2bcc7da12ad1145
travis_fold:end:git.3
$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
$ javac -version
javac 1.7.0_45
travis_fold:start:install
$ gradle assemble
[...]
The command "gradle assemble" failed and exited with 1 during install.

Your build has been stopped.

I read the page linked in the documentation but unfortunately it wasn't much helpful to me. 我阅读了文档中链接页面,但遗憾的是它对我没什么帮助。

Here is mine yaml file which is building apk. 这是我的yaml文件正在构建apk。 But it should work also for library. 但它也适用于图书馆。

language: java
jdk: oraclejdk7
branches:
  only:
    - master
before_install:
  - chmod +x gradlew
  # Install base Android SDK
  - sudo apt-get update -qq
  - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch > /dev/null; fi
  - wget http://dl.google.com/android/android-sdk_r22.0.5-linux.tgz
  - tar xzf android-sdk_r22.0.5-linux.tgz
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
  # install android build tools
  - wget https://dl-ssl.google.com/android/repository/build-tools_r19.0.1-linux.zip
  - unzip build-tools_r19.0.1-linux.zip -d $ANDROID_HOME
  - mkdir -p $ANDROID_HOME/build-tools/
  - mv $ANDROID_HOME/android-4.4.2 $ANDROID_HOME/build-tools/19.0.1
  # Install required components.
  - echo yes | android update sdk --filter platform-tools --no-ui --force > /dev/null
  - echo yes | android update sdk --filter android-19 --no-ui --force > /dev/null
  - echo yes | android update sdk --filter extra-android-support --no-ui --force > /dev/null
  - echo yes | android update sdk --filter extra-android-m2repository --no-ui --force > /dev/null
install:
  - true
script:
  - TERM=dumb ./gradlew test assembleDebug

But be careful since this script doesn't push built artefact anywhere 但要小心,因为这个脚本不会在任何地方推动构建的人工制品

I use an SDK installer script in the .travis.yml for Hilt . 我在.travis.ymlHilt使用SDK安装程序脚本。

language: java
jdk: oraclejdk7
before_install:
    # Install base Android SDK and components
    - sudo apt-get update -qq
    - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect
    - export COMPONENTS=build-tools-19.0.3,android-19,extra-android-support,extra-android-m2repository,extra-google-m2repository
    - export LICENSES=android-sdk-license-bcbbd656
    - curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES
    - source ~/.android-sdk-installer/env

install:
    # Without TERM=dumb, we get mangled output in the Travis console
    - TERM=dumb ./gradlew clean assemble -PdisablePreDex

script:
    - TERM=dumb ./gradlew check -PdisablePreDex

EDIT: Travis-CI has implemented Android as a first class citizen - http://blog.travis-ci.com/2014-05-07-android-build-support-now-in-beta/ 编辑: Travis-CI已将Android作为一等公民实施 - http://blog.travis-ci.com/2014-05-07-android-build-support-now-in-beta/

To address why you're seeing gradle assemble instead of gradle bundleRelease : 要解决为什么你看到gradle assemble而不是gradle bundleRelease

gradle assemble is invoked by default in the install: stage of Travis (see Travis docs for description of stages, and this note ). 默认情况下,在Travis的install:阶段调用gradle assemble (有关阶段描述和本说明 ,请参阅Travis文档 )。

Since you don't have an install: section of your script to override the default, Travis is invoking gradle assemble . 由于您没有脚本的install:部分来覆盖默认值,因此Travis正在调用gradle assemble

You can prevent this by adding the following lines, which tells Travis not to do anything during the install stage: 您可以通过添加以下行来防止这种情况,这会告诉Travis在安装阶段不要做任何事情:

install:
    - true

I had a similar issue , with Travis executing gradle assemble when I wanted it to execute gradlew assembleDebug . 我有一个类似的问题 ,Travis在我希望它执行gradlew assembleDebug时执行gradle assemble gradlew assembleDebug

So, for me, a complete working script (as of May 1, 2014 with Android as a first class citizen ) is: 所以,对我来说,一个完整的工作脚本(截至2014年5月1日, Android作为一等公民 )是:

language: android
jdk: oraclejdk7

android:
  components:
    - build-tools-19.0.1

install:
    - true

script: TERM=dumb ./gradlew assembleDebug

Thanks to Austyn Mahoney for clarifying this for me here . 感谢Austyn Mahoney在这里为我澄清这一点

EDIT 编辑

As of May 8, 2014, Travis CI has removed the default install: stage for the Android beta, as discussed here . 截至2014年5月8日,特拉维斯CI已删除默认的install:阶段为Android测试版,为讨论在这里 Therefore, you should now be able to remove the install: stage from your script, and Travis shouldn't execute gradle assemble . 因此,您现在应该能够从脚本中删除install: stage,并且Travis不应该执行gradle assemble

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM