We are trying to integrate our android app with travis CI. But it always fails with cannot access ‘gradlew’: No such file or directory. We can run the gradlew script from our local computer and the file is tracked by git. What can the problem be?
Our .travis.yml file:
sudo: false
language: android
jdk: oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
before_script:
- cd TreasurePleasure
- echo no | android create avd --force -n test -t "android-"$ANDROID_EMULATOR_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
android:
components:
- tools
- tools # Running this twice get's the latest build tools (https://github.com/codepath/android_guides/wiki/Setting-up-Travis-CI)
- platform-tools
- build-tools-27.0.3
- android-27
- android-$ANDROID_EMULATOR_LEVEL
- sys-img-armeabi-v7a-google_apis-$ANDROID_EMULATOR_LEVEL
licenses:
- '.+'
env:
global:
- ANDROID_API_LEVEL=27
- ANDROID_EMULATOR_LEVEL=21
- ANDROID_BUILD_TOOLS_VERSION=27.0.3
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20
before_install:
- chmod +x gradlew
- yes | sdkmanager "platforms;android-27"
script:
- "./gradlew clean build connectedCheck -PdisablePreDex --stacktrace"
# run tests against the emulator
- ./gradlew connectedAndroidTest
# run tests against the JVM
- ./gradlew test
Most of this is copy paste since this is the first project for us that are using Travis CI.
Our error:
This is how it works in my scripts:
before_script:
- cd ${TRAVIS_BUILD_DIR}/TreasurePleasure
- chmod +x ./gradlew
script: "./gradlew assemble"
Related
When I push to remote Travis CI starts a build, but it does never finish because licences are not accepted. I get to Accept? (y/N): line in the Travis build and it waits until timeout.
Travis file:
sudo: required
language: android
jdk: oraclejdk8
dist: trusty
android:
components:
- tools
- tools
- platform-tools
- build-tools-28.0.3
- android-28
- add-on
- extra
before_install:
- echo yes | sdkmanager "build-tools;28.0.3"
- echo yes | sdkmanager "platforms;android-28"
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\ " > "$ANDROID_HOME/licenses/android-sdk-preview-license"
- sdkmanager "system-images;android-28;google_apis;x86"
- echo no | avdmanager create avd --force -n emulatorApi28 -k "system-images;android-28;google_apis;x86"
- emulator -avd test -no-audio -no-window &
- ./gradlew dependencies || true
before_script:
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew build connectedCheck
- "./gradlew clean build connectedCheck -PdisablePreDex --stacktrace"
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
Any suggestions on why it never accepts licenses?
Just add - yes | sdkmanager --licenses >/dev/null to your before_install stage.
My Travis build keeps failing because apparently it does not recognize the arm abi. Here's my full .travis.yml:
language: android
sudo: required
env:
global:
- ANDROID_API_LEVEL=28
- ANDROID_BUILD_TOOLS_VERSION=28.0.3
- ANDROID_ABI=armeabi-v7a
- ANDROID_EMU_API_LEVEL=27
android:
components:
- tools
- platform-tools
- tools # appears twice as per Travis docs
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
- android-$ANDROID_EMU_API_LEVEL
- extra-android-m2repository
- sys-img-${ANDROID_ABI}-android-${ANDROID_EMU_API_LEVEL}
licenses:
- 'android-sdk-preview-license-52d11cd2'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
before_script:
- echo no | android create avd --force -n test -t android-$ANDROID_EMU_API_LEVEL --abi $ANDROID_ABI -c 100M
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- chmod +x gradlew
script:
- android list target
- ./gradlew clean build
- ./gradlew test
- ./gradlew connectedCheck
I have also tried to change the abi in the emulator to google_apis/armeabi-v7a to no avail. Also tried to add google_apis in the system image download. I have currently tried API_LEVEL 22, 27 and 28.
What is the issue here?
You can try ANDROID_ABI=arm64-v8ainstead of ANDROID_ABI=armeabi-v7a
I don't know if this is still relevant since it was asked 4 months ago, but I also just recently had this same issue. I tried many different things people suggested and none of it worked till I set it up this way:
language: android
sudo: required
jdk: oraclejdk8
env:
global:
- ANDROID_API_LEVEL=28
- ANDROID_BUILD_TOOLS_VERSION=28.0.3
- ANDROID_ABI=armeabi-v7a
android:
components:
- tools
- platform-tools
- tools
- extra-android-m2repository
licenses:
- 'android-sdk-preview-license-52d11cd2'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
before_install:
- touch $HOME/.android/repositories.cfg
- yes | sdkmanager "platforms;android-28"
- yes | sdkmanager "build-tools;28.0.3"
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
before_script:
- chmod +x gradlew
script:
- ./gradlew clean build
- ./gradlew test
i just want travis ci check my project not have error (i don't have test case). But when i commit my code,travis ci always run fail or error (my project not have error). Someone can help me.
My travis.yml file content:
language: android
android:
components:
- build-tools-23.0.2
- android-23
- extra
licenses:
- 'android-sdk-preview-license-52d11cd2'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
before_script:
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: ./gradlew connectedAndroidTest
Chmod:
Output:
I want to test my code from android-15 to android-23, but unfortunately build fails for android-20 and android-22.
Error: Invalid --tag default for the selected target.
The command "echo no | android create avd --force -n test -t
$ANDROID_TARGET --abi $ANDROID_ABI" failed and exited with 1 during .
travis file :
language: android
sudo: false
jdk: oraclejdk7
os:
- linux
android:
components:
- platform-tools
- tools
- build-tools-23.0.3
- android-23
# Additional components
- extra
- extra-google-m2repository
- extra-android-m2repository
- extra-android-support
# Images
- sys-img-${ANDROID_ABI}-${ANDROID_TARGET}
env:
matrix:
- ANDROID_SDKS=android-15 ANDROID_TARGET=android-15 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-16 ANDROID_TARGET=android-16 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-17 ANDROID_TARGET=android-17 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-18 ANDROID_TARGET=android-18 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-20 ANDROID_TARGET=android-20 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-21 ANDROID_TARGET=android-21 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-22 ANDROID_TARGET=android-22 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-23 ANDROID_TARGET=android-23 ANDROID_ABI=armeabi-v7a
global:
# wait up to 10 minutes for adb to connect to emulator
- ADB_INSTALL_TIMEOUT=10
cache:
directories:
- $HOME/.gradle/caches/2.10
- $HOME/.gradle/caches/jars-1
- $HOME/.gradle/daemon
- $HOME/.gradle/native
- $HOME/.gradle/wrapper
before_install:
- chmod +x gradlew
before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
script:
- android-wait-for-emulator
- adb devices
- adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
- adb shell input keyevent 82 &
- ./gradlew connectedCheck
travis result
How fix it?
The Android 20 SDK target is for KitKat4.4 wearables and has a slightly different system image with abi prefix that is causing the error.
Under the #images you can add the image provided by Travis-CI
- sys-img-armeabi-v7a-android-wear-20
In the android 20 matrix script you will have to add android-wear/armeabi-v7
- ANDROID_SDKS=android-20 ANDROID_TARGET=android-20 ANDROID_ABI=android-wear/armeabi-v7a
I have been researching this for multiple days now and dug up some good resources like this user guide. I can also build and install just fine thanks to this article. However, I cannot, for the life of me, figure out how to run my instrumentation tests without having a connected device.
Is it simply not possible to run the tests under app/src/androidTest (where I have most of my tests) without using the command ./gradlew connectedAndroidTest?
Also, I've seen it's recommended to put jUnit tests under app/src/test and Instrumentation tests under the gradle preconfigured app/src/androidTest. Is this a good way to set up the app's tests, even though that means creating two different testing directories?
I'm asking all of this because I'm using a Jenkins CI job to build the Android project upon the code being updated and I'd like Jenkins to run all of my tests along with building the project, but I'd hope I wouldn't have to concern myself with creating some sort of emulator/device for Jenkins to run the tests on (as required by ./gradlew connectedAndroidTest).
Yes, it is the proper way to set up app's test as JUnit tests (in app/src/test) run on JVM and Instrumentation tests run on connected device.
http://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
Possible solution - In pre-build step on Jenkins, run emulator/Genymotion from commandline and run all tests with
./gradlew cAT
OR keep the Genymotion/emulator setup running always.
https://www.genymotion.com/#!/
For those who have found this topic same as I and are thinking about running Android from terminal, possibly in CI.
I have been working with CI on GitLab lately. I have figured out a better way without gennymotion, with mere android avd created by avdmanager. New Android Tools are optimized to run from terminal, which can be used in docker images for example.
More info in this tutorial and update the gitlab compose script as below.
image: openjdk:8-jdk
variables: # such as ..
ANDROID_SDK_TOOLS_URL: "https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip" # https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
ANDROID_SDK_VERSION: "26" # 26
ANDROID_BUILD_TOOLS: "26.0.2" # 26.0.1
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-tools.zip ${ANDROID_SDK_TOOLS_URL}
- unzip android-tools.zip -d android-sdk-linux
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" --verbose # SDK Platform-Tools
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_SDK_VERSION}" --verbose # SDK Platform
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" --verbose # SDK Build-Tools
- echo y | android-sdk-linux/tools/bin/sdkmanager "extras;android;m2repository" --verbose # Support Repository
- echo y | android-sdk-linux/tools/bin/sdkmanager "extras;google;m2repository" --verbose # Google Repository
- echo y | android-sdk-linux/tools/bin/sdkmanager "extras;google;google_play_services" --verbose # Google Play services
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
stages:
- build
- test
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
unitTests:
stage: test
script:
- ./gradlew test
functionalTests:
stage: test
script:
- wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
- chmod +x android-wait-for-emulator
- echo y | android-sdk-linux/tools/bin/sdkmanager --verbose --update
- echo y | android-sdk-linux/tools/bin/sdkmanager --verbose "system-images;android-${ANDROID_SDK_VERSION};google_apis;x86"
- echo no | android-sdk-linux/tools/bin/avdmanager create avd -n test -k "system-images;android-${ANDROID_SDK_VERSION};google_apis;x86" # no custom HW profile
- android-sdk-linux/tools/emulator -avd test -no-window -no-audio & # run headless "test" AVD
- ./android-wait-for-emulator # if ran fast enough it will catch cange of state on Boot Animation ~ init.svc.bootanim
- adb shell input keyevent 82 # some dummy input
- ./gradlew cAT