Travis CI build doesn't work with Android Constraint Layout

社会主义新天地 提交于 2019-11-30 01:43:20

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.

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-.+
  - '.+'

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.

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

albodelu

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!