22

I am trying to make Travis build my Android project. It fails when it tries to download the library for ConstraintLayout. Do you know what I have to do to make it work?

My .travis.yml is this:

language: android
jdk:
  - oraclejdk8
android:
  components:
    - platform-tools
    - tools
    - build-tools-23.0.2
    - android-23
    - extra-android-support
    - extra-android-m2repository
    - extra-google-m2repository

My build.gradle is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "my.example.bdd"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support:support-annotations:23.4.0'
}

And the error I get on Travis is:

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
   > Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha2.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.pom
         https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.jar
         file:/usr/local/android-sdk/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.pom
         file:/usr/local/android-sdk/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.jar
         file:/usr/local/android-sdk/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.pom
         file:/usr/local/android-sdk/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha2/constraint-layout-1.0.0-alpha2.jar

Any idea how to fix this? Is it even possible to build ConstraintLayout with Travis?

pRaNaY
  • 24,642
  • 24
  • 96
  • 146
Terry
  • 14,529
  • 13
  • 63
  • 88
  • 2
    FWIW, I don't see `1.0.0-alpha2` in my copy of `extras/android/m2repository/com/android/support/constraint/constraint-layout`. I see only `1.0.0-alpha1`. And according to the SDK Manager, my setup is up to date (Rev 32 of Android Support Repository). – CommonsWare Jun 03 '16 at 13:16
  • Works. Seems like `1.0.0-alpha2` is not there yet. If you post this as the answer, I'll accept it. – Terry Jun 03 '16 at 13:33
  • I tried pulling the .aar/.jar out of my local SDK, but couldn't quite get it to work. If someone does, that might be a temporary workaround until things get sorted out? – virtualandy Jun 03 '16 at 23:17
  • 1
    If you look at the [bug report](http://stackoverflow.com/questions/37615379/travis-ci-build-doesnt-work-with-android-constraint-layout#comment62731460_37615872) mentioned by @CommonsWare, it has additional info that should help resolve this. The gist: Gradle will pull down the constraint-layout deps since they are unbundled. You'll need a license file in your `$ANDROID_HOME`/SDK to do that. You may also need to make your SDK writeable on your CI instance. HTH. – virtualandy Jun 09 '16 at 23:26
  • @virtualandy which license file is required? Any straightforward alternative solution? Thanks! – fasteque Jun 10 '16 at 21:11
  • @fasteque Sorry, I wasn't clear. Check out [Response's #19-21](https://code.google.com/p/android/issues/detail?id=212128#c19) in the [bug report](https://code.google.com/p/android/issues/detail?id=212128). They specify that you should accept the licenses via Android Studio/SDK UI, then go into your AS/SDK and grab a directory (with 2 plain text files in it) out of there. That directory will need to be copied to the headless/CI instance's SDK. – virtualandy Jun 13 '16 at 23:26

6 Answers6

18

After the new release of the Support Library version 25.0.0, the Constraint Layout Alpha1 library apparently doesn't work anymore on TravisCI. Using that version was the only workaround at the moment.

Now I found a new workaround to use the new Alpha9 version. 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:

licenses:
  - android-sdk-license-.+
  - '.+'
amouly
  • 453
  • 4
  • 10
13

Your build.gradle is attempting to pull in com.android.support.constraint:constraint-layout:1.0.0-alpha2. My SDK Manager only offers me 1.0.0-alpha1 (Rev 32 of the Android Support Repository). Perhaps Travis CI also only has 1.0.0-alpha1 as well.

Since I presume that you have 1.0.0-alpha2 working on your development machine, I am not quite certain what is going on here. There might be a glitch in the distribution packaging of the Android Support Repository or something.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 2
    the `1.0.0-alpha2` comes with preview 2 of Studio 2.2. Not sure how they make it available to the gradle build... I have a similar issue on my jenkins server (not finding 1.0.0-alpha2) – Dodge Jun 03 '16 at 14:10
  • Same here re: jenkins. I tried a bunch of options, including using http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz and it's able to then resolve alpha1, but not alpha2. – virtualandy Jun 03 '16 at 22:14
  • 1
    FWIW, I have filed [a bug report](https://code.google.com/p/android/issues/detail?id=212128) about this. – CommonsWare Jun 03 '16 at 22:50
  • @CommonsWare Thanks! Note https://code.google.com/p/android/issues/detail?id=185638#c4 talks about the command line SDK updater not seeing any more development. :( – virtualandy Jun 03 '16 at 23:02
7

There is an open issue https://code.google.com/p/android/issues/detail?id=212128

In short, com.android.support.constraint:constraint-layout:1.0.0-alpha1 is bundled into Google Repository but 1.0.0-alpha2 and later version is only available from gradle plugin which expects a license text being placed in $HOME/.android/license/ (if not found, try $ANDROID_HOME/licenses).

You can copy the license text file from your local machine (after agreed to the license from SDK Manager provided by Android Studio 2.2) to the CI server as mentioned in the issue. Or downgrade to 1.0.0-alpha1 to fix the problem.

kamikat
  • 71
  • 4
1

I have the same issue with com.android.support.constraint:constraint-layout:1.0.0-alpha9. In my case I directly tried to create the license file in Travis this way:

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

But since I don't have permissions to write on $ANDROID_SDK and there is no support for sudo, I have no idea what to do next.

The only option I see is to wait until Google includes it in the license or downgrade to alpha1...

Gnzlt
  • 4,383
  • 2
  • 22
  • 24
  • I copied the licenses forlder of my machine into my repo and `dependencies: pre: - scp -r ${HOME}/${CIRCLE_PROJECT_REPONAME}/licenses $ANDROID_HOME` – oldergod Oct 06 '16 at 23:39
  • 1
    @gonzalo check my proposed solution, it's the same as yours but added a the new license for Preview scope. It's working fine with TravisCI. No need to rollback to Alpha1. – amouly Oct 20 '16 at 02:30
1

Workaround to accept the license is no longer required as explained here if you directly accept it:

  - 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"

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

Community
  • 1
  • 1
albodelu
  • 7,931
  • 7
  • 41
  • 84
0

Sadly, adding the licence hashes don't work anymore.

The simplest solution that worked for me (in 2018 ) was to copy the SDK licenses to my project from SDK and then tell Travis to copy them to itself while building.

There's already a closed issue for this on Travis's Github page and one of the mentioned solutions on it is definitely working currently.

Solution

  1. Copy the licenses folder found in Android SDK's root directory.
  2. Paste it in the root directory of your own project on the same hierarchy where .travis.yml file is.
  3. Add these commands to your .travis.yml's before_install block:

.travis.yml:

before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- cp ./licenses/* "$ANDROID_HOME/licenses/"

Exact link to solution: https://github.com/travis-ci/travis-ci/issues/6617#issuecomment-369580270

Link to my original answer on another SO question: https://stackoverflow.com/a/49050480/1402616

MiaN KhaLiD
  • 1,478
  • 1
  • 16
  • 28