Build android apk sometimes fails

when I build the android apk using travis, it sometimes encounters fail. The issue is pretty random. 80% works, 20% fail. Please see the error message below:

  • What went wrong:
    A problem occurred configuring project ‘:flutter_picker’.

Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: /usr/local/android-sdk

Here is my travis script

* stage: deploy
name: "Deploy Android"
os: linux
dist: xenial
addons:
apt:
sources:
- ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version
packages:
- libstdc++6
- fonts-droid
before_install:
  * openssl aes-256-cbc -K $encrypted_885114b78094_key -iv $encrypted_885114b78094_iv -in secrets.tar.enc -out secrets.tar -d
  * tar xvf secrets.tar
  * gem update --system
  * gem install bundler -v 1.17.3
before_script:
  * sh bin/clone-flutter-if-not-exists.sh
  * ./flutter/bin/flutter doctorlanguage: android
licenses:
  * 'android-sdk-preview-license-.+'
  * 'android-sdk-license-.+'
  * 'google-gdk-license-.+'
android:
components:
    * tools
    * platform-tools

# The BuildTools version used by your project

    * build-tools-28.0.3

# The SDK version used to compile your project

    * android-28
    * add-on
    * extrajdk: oraclejdk8
script:
  * source bin/env.sh
  * ./flutter/bin/flutter build apk --flavor $APP_FLAVOR --release --build-number $TRAVIS_BUILD_NUMBER -t $APP_ENTRY
  * cd android/
  * bundle update
  * bundle exec fastlane deploy_alpha

This looks mighty suspicious.

Please link to the build. Copying stuff here selectively gives insufficient information for diagnostics.

Imprint