android - Travis CI 失败,因为无法接受许可证约束布局

标签 android gradle travis-ci android-sdk-tools android-constraintlayout

在我写这个问题之前,我已经搜索过关于这个的相同问题,他们没有导出许可证,因为仍然使用约束布局的 alpha 版本。但是现在android已经发布了约束布局的稳定版本。我尝试了很多设置但仍然失败..

我最新的.travis.yml

language: android

jdk: oraclejdk8

android:
  components:
    - platform-tools
    - tools # to get the new `repository-11.xml`
    - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
    - build-tools-25.0.0
    - android-25

    # Additional components
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository

  licenses:
    - 'android-sdk-preview-license-52d11cd2'
    - 'android-sdk-license-.+'
    - 'google-gdk-license-.+'

script:
   - ./gradlew clean build

这是我的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.package.my"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 6
        versionName "1.3.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-database:10.2.0'
    compile 'com.google.firebase:firebase-messaging:10.2.0'
    compile 'com.firebaseui:firebase-ui-database:1.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.android.support:design:25.0.0'
    compile 'org.sufficientlysecure:html-textview:3.2'
    compile 'com.android.support:recyclerview-v7:25.2.0'

}

apply plugin: 'com.google.gms.google-services'

使用这个设置我得到了这个错误

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [ConstraintLayout for Android 1.0.1, Solver for ConstraintLayout 1.0.1].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
* 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: 1 mins 55.975 secs
The command "./gradlew clean build" exited with 1.
Done. Your build exited with 1.

有没有不使用导出许可证的解决方法的解决方案?

最佳答案

更新响应

is there any solution without workaround using export license?

是的,您可以使用新的 sdkmanagerinstall the constraint library and accept the license :

  - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
  - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"

否则,gradle 会检测到缺少的组件,并在不接受的情况下下载:

  # Show version and download Gradle Wrapper if it's not already cached
  - cd ${TRAVIS_BUILD_DIR}/${DIR} && ./gradlew --version
  # Clean project and download missing dependencies and components
  - cd ${TRAVIS_BUILD_DIR}/${DIR} && ./gradlew clean build

在这种情况下,如下所述,您需要通过变通办法第一次接受许可。

Full working sample using constraint-layout codelab repository for Android API level 22 to 25:

language: android
jdk: oraclejdk8
sudo: required # false for Container-Based Infrastructure, required for Sudo-enabled Infrastructure

before_cache:
  - rm -f ${TRAVIS_BUILD_DIR}/gradle/caches/modules-2/modules-2.lock # Avoid to repack it due locks
  - rm -f ${TRAVIS_BUILD_DIR}/gradle/caches/3.3/classAnalysis/classAnalysis.lock
  - rm -f ${TRAVIS_BUILD_DIR}/gradle/caches/3.3/jarSnapshots/jarSnapshots.lock

cache:
  directories:
    - ${TRAVIS_BUILD_DIR}/gradle/caches/
    - ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/

notifications:
  email: false

android:
  components: # Cookbooks version: https://github.com/travis-ci/travis-cookbooks/tree/9c6cd11
    - tools # Update preinstalled tools from revision 24.0.2 to 24.4.1
    - build-tools-25.0.2 # Match build-tools version used in build.gradle
    - platform-tools # Update platform-tools to revision 25.0.3+
    - tools # Update tools from revision 24.4.1 to 25.2.5

env:
  global:
    - DIR=constraint-layout-start # Project directory
    - API=25 # Android API level 25 by default
    - TAG=google_apis # Google APIs by default, alternatively use default
    - ABI=armeabi-v7a # ARM ABI v7a by default
    - QEMU_AUDIO_DRV=none # Disable emulator audio to avoid warning
    - GRADLE_USER_HOME="${TRAVIS_BUILD_DIR}/gradle" # Change location for Gradle Wrapper and cache
    - ANDROID_HOME=/usr/local/android-sdk-24.0.2 # Depends on the cookbooks version used in the VM
    - TOOLS=${ANDROID_HOME}/tools # PATH order matters, exists more than one emulator script
    - PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
    - ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)

matrix:
  include: # More Emulator API levels to build in parallel
    - env: API=24
    - env: API=23
    - env: API=22
  allow_failures:
    - env: API=23
    - env: API=22
  fast_finish: false

before_install:
  - export EMULATOR="system-images;android-${API};${TAG};${ABI}" # Used to install/create emulator
  - echo 'count=0' > /home/travis/.android/repositories.cfg # Avoid warning

install:
  # List and delete unnecessary components to free space
  - sdkmanager --list || true
  - sdkmanager --uninstall "system-images;android-15;default;armeabi-v7a"
  - sdkmanager --uninstall "system-images;android-16;default;armeabi-v7a"
  - sdkmanager --uninstall "system-images;android-17;default;armeabi-v7a"
  - sdkmanager --uninstall "system-images;android-18;default;armeabi-v7a"
  - sdkmanager --uninstall "system-images;android-19;default;armeabi-v7a"
  - sdkmanager --uninstall "system-images;android-21;default;armeabi-v7a"
  - sdkmanager --uninstall "extras;google;google_play_services"
  - sdkmanager --uninstall "extras;android;support"
  - sdkmanager --uninstall "platforms;android-10"
  - sdkmanager --uninstall "platforms;android-15"
  - sdkmanager --uninstall "platforms;android-16"
  - sdkmanager --uninstall "platforms;android-17"
  - sdkmanager --uninstall "platforms;android-18"
  - sdkmanager --uninstall "platforms;android-19"
  - sdkmanager --uninstall "platforms;android-20"
  - sdkmanager --uninstall "platforms;android-21"
  - sdkmanager --uninstall "build-tools;21.1.2"
  # Update sdk tools to latest version and install/update components
  - echo yes | sdkmanager "tools"
  - echo yes | sdkmanager "platforms;android-25" # Latest platform required by SDK tools
  - echo yes | sdkmanager "platforms;android-${API}" # Android platform required by emulator
  - echo yes | sdkmanager "extras;android;m2repository"
  - echo yes | sdkmanager "extras;google;m2repository"
  - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
  - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
  - echo yes | sdkmanager "$EMULATOR" # Install emulator system image
  # Create and start emulator
  - echo no | avdmanager create avd -n acib -k "$EMULATOR" -f --abi "$ABI" --tag "$TAG"
  - emulator -avd acib -engine classic -no-window -camera-back none -camera-front none -verbose -qemu -m 512 &
  # Start adbd, wait for device connected and show android serial
  - adb wait-for-device get-serialno
  # Show version and download Gradle Wrapper if it's not already cached
  - cd ${TRAVIS_BUILD_DIR}/${DIR} && ./gradlew --version
  # Clean project and download missing dependencies and components
  - cd ${TRAVIS_BUILD_DIR}/${DIR} && ./gradlew clean build
  # Check components status
  - sdkmanager --list || true

before_script:
  # Wait for emulator fully-booted and disable animations
  - android-wait-for-emulator
  - adb shell settings put global window_animation_scale 0 &
  - adb shell settings put global transition_animation_scale 0 &
  - adb shell settings put global animator_duration_scale 0 &
  - sleep 30
  - adb shell input keyevent 82 &

script:
  # Run all device checks
  - cd ${TRAVIS_BUILD_DIR}/${DIR} && ./gradlew connectedCheck

after_script:
  # Show tests and lint results
  - cat ${TRAVIS_BUILD_DIR}/${DIR}/*/build/outputs/androidTest-results/connected/*
  - cat ${TRAVIS_BUILD_DIR}/${DIR}/*/build/reports/lint-results.xml

另外两个使用 sdkmanageravdmanager 的示例,没有 ${DIR} 解决方法:

引用资料

Auto-download missing packages with Gradle相关的官方文档

new Emulator Start the Emulator from the Command Line 中解释了选项

avdmanager explained hereSDK tools version 25.3.0 以来替换 android avd

sdkmanager explained here还增强了从命令行查看和接受所有许可证


上一个回复:由于sdkmanager替换了android脚本

我对 Travis-ci 有点过时了,现在似乎需要额外的工作,所以你最好检查一下:

In your .travis.yml file add:

before_install:
  - mkdir "$ANDROID_HOME/licenses" || true
  - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
  - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"

Do not forgot to accept all the licences on the main android object:

android:
  components:
    # ...
  licenses:
    - android-sdk-license-.+
    - '.+'

If you are getting "Please install the missing components using the SDK manager in Android Studio." error you can just install the missing component with the sdkmanager command line tool:

echo y | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.0-beta4"
echo y | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.0-beta"
  • This article解释 Circle-ci 和 Travis-ci 的约束布局问题

  • Documentation关于Android SDK工具包(25.2.3+)中提供的sdkmanager


过时的解决方案:在 android 脚本弃用之前

我不使用默认的 Travis-ci 脚本来安装 Android 组件和接受许可,from here :

# Install and update SDK
function install-and-update-sdk {
    # Keep SDK packages up-to-date (only missing suggested updates are installed).
    ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk -u -t \
        ${UPDATE_PKGS:-'platform-tools,tools,extra-android-m2repository,extra-google-m2repository'}
    # Install or reinstall SDK packages (if empty, all packages are installed).
    ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk -a -u -t \
        ${INSTALL_PKGS:-'build-tools-23.0.3,android-23'},${TARGET_PKGS:-}
}

如果你像this那样做,你可以同时接受所有的许可。 :

# THE SETUP STAGE
# ---------------
# If you comment out this section, Travis CI will install for you the components you define here.
# Check your project requirements and the components included by default on Travis-ci VM images.
# Check required: https://github.com/google/iosched/blob/master/doc/BUILDING.md
# Check defaults: http://docs.travis-ci.com/user/languages/android/#Pre-installed-components

android:
  components:
    # Check Android SDK tools: http://developer.android.com/tools/sdk/tools-notes.html
    # Check Android SDK Platform-tools: http://developer.android.com/tools/revisions/platforms.html
    # Comment the lines below if the latest revisions of Android SDK Tools are included by default.
    # - tools
    # - platform-tools
    # ...
  licenses:
    # Check licenses: http://docs.travis-ci.com/user/languages/android/#Dealing-with-Licenses
    # By default Travis will accept all the licenses, but it's also possible to define a white list:
    # White list current android-sdk-license revision.
    # - 'android-sdk-license-5be876d5'
    # White list all android-sdk-license revisions.
    # - 'android-sdk-license-.+'
    # White list all the licenses.
    - '.+'

关于android - Travis CI 失败,因为无法接受许可证约束布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42731625/

相关文章:

Android:如何禁止在扫描 NFC 标签时重新打开您的应用程序?

gradle - gradle如何导入外部资源

git - 我如何将 git lfs 与 Travis CI gh-pages 部署一起使用?

git - Travis 从单个仓库构建多个 Docker 镜像

npm - 为什么TravisCI构建会在npm安装期间由于文件锁定而失败

android - 动画监听器和 Intent

android - SQLiteConstraintException 不要进入 catch

java - R.id 无法解析

gradle - 将Gradle 3升级到Gradle 4后“unable to resolve class”错误

android - 无法使用最新的gradle版本制作android项目