NB: I new in gitlab CI CD
Found errors in your .gitlab-ci.yml:
assembleRelease job: stage parameter should be .pre
build
test
deploy
.post
You can also test your .gitlab-ci.yml in CI Lint
My .gitlab-ci.yml code
image: openjdk:8-jdk
variables: ANDROID_COMPILE_SDK: "29" ANDROID_BUILD_TOOLS: "29.0.2" ANDROID_SDK_TOOLS: "4333796"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew # temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
lintDebug: stage: build script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug: stage: build script:
- ./gradlew assembleDebug artifacts:
paths:
- app/build/outputs/
debugTests: stage: test script:
- ./gradlew -Pci --console=plain :app:testDebug
assembleRelease:
stage: release script:
- echo $KEYSTORE_FILE | base64 -d > my.keystore
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD artifacts:
paths:
- app/build/outputs/apk/release
- CHANGELOG
NB: Please share pipeline build test and release cd code for android
Maybe I'm too late, but our .gitlab-ci.yml format is wrong. You missed several new lines.
For example, in assembleRelease after the stage: release you need a new line, script: should be on a new line
the ident in .yaml file is important. You have mixed 2 spaces and 4 spaces indent. you should make them same. normally it should be 2 spaces.
the stage, script, and artifact should be in a new line, not in same line.
here is a possible fix
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.3"
ANDROID_SDK_TOOLS: "6609375_latest"
before_script:
- echo ANDROID_COMPILE_SDK ${ANDROID_COMPILE_SDK}
- echo ANDROID_BUILD_TOOLS ${ANDROID_BUILD_TOOLS}
- echo ANDROID_SDK_TOOLS ${ANDROID_SDK_TOOLS}
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- export ANDROID_SDK_ROOT=$PWD/android-sdk-linux
- export SDK_MANAGER="${ANDROID_SDK_ROOT}/tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT}"
- echo y | ${SDK_MANAGER} "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | ${SDK_MANAGER} "platform-tools" >/dev/null
- echo y | ${SDK_MANAGER} "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- echo y | ${SDK_MANAGER} --licenses
- set -o pipefail
stages:
- build
- test
- release
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
assembleRelease:
stage: release
script:
- echo $KEYSTORE_FILE | base64 -d > my.keystore
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/my.keystore
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD
-Pandroid.injected.signing.key.alias=$KEY_ALIAS
-Pandroid.injected.signing.key.password=$KEY_PASSWORD
artifacts:
paths:
- app/build/outputs/apk/release
- CHANGELOG
Related
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
release: "android"
release_notes: "orange-apk-release"
notify: false
# install the android sdk
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip
- unzip -d android-sdk-linux android-sdk.zip
- mv android-sdk-linux/cmdline-tools android-sdk-linux/latest
- mkdir -p android-sdk-linux/cmdline-tools
- mv android-sdk-linux/latest android-sdk-linux/cmdline-tools/
- echo y | android-sdk-linux/cmdline-tools/latest/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/cmdline-tools/latest/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/cmdline-tools/latest/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/cmdline-tools/latest/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- upload
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
upload-job:
stage: upload
before_script:
- export INSTALL_DIR=$CI_PROJECT_DIR
- curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
script:
- $CI_PROJECT_DIR/ta-cli publish --api_token=$TESTAPPIO_API_TOKEN --app_id=$TESTAPPIO_APP_ID --release=$release --apk=$CI_PROJECT_DIR/app/build/outputs/apk/debug/app-debug.apk --release_notes=$release_notes --notify=$notify --source="Gitlab"
ERROR MSG :
echo y | android-sdk-linux/cmdline-tools/latest/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
199 Warning: Failed to download any source lists
please guys any help and thanks in advance.
I have been trying to build the app in pipeline to run just unit tests but I am getting error which i cannot find anywhere else can you guys look and tell me what I an doing wrong here.
here is what I am getting as an error.
Preparing to unpack .../lib32z1_1%3a1.2.11.dfsg-2_amd64.deb ...
Unpacking lib32z1 (1:1.2.11.dfsg-2) ...
Setting up libc6-i386 (2.31-13+deb11u2) ...
Setting up lib32z1 (1:1.2.11.dfsg-2) ...
Setting up lib32gcc-s1 (10.2.1-6) ...
Setting up lib32stdc++6 (10.2.1-6) ...
Processing triggers for libc-bin (2.31-13+deb11u2) $ wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
here is my .gitlab-ci.yml file:
image: openjdk:11-jdk
variables:
ANDROID_COMPILE_SDK: "31"
ANDROID_BUILD_TOOLS: "32.0.0"
ANDROID_SDK_TOOLS: "7583922"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
I think that URL you are constructing here .. does not exist anymore .. hence fails
wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
Output:
PS C:\Users\Sayan> curl https://dl.google.com/android/repository/sdk-tools-linux-7583922.zip
curl :
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 404 (Not Found)!!1</title>
I have setup a very basic CI on gitlab for my android project and I was wondering if there was a way to send the apk that is built to a google drive somewhere so an email can be sent with a link to the apk? I was also wondering if there was a way to only do the build if pushed/merged on a particular branch.
I used the template yml file in the gitlab example.
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
I follow this link to implement a simple Gitlab ci in my sample project.
this is my Gitlab ci config
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- build
- test
lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
but it cannot find the gradlew and it always shows this error
$ chmod +x ./gradlew
chmod: cannot access './gradlew': No such file or directory
ERROR: Job failed: exit code 1
If you want to run ./gradlew, you must have this file tracked in Git or generating/installing it in the before_script. Which does not seem like it is happening.
Most probably you aren't tracking the gradlew file, either by not adding it to Git, or by ignoring it in a .gitignore file.
Make sure you are tracking gradlew file in your VCS.
In your variables, add this:
ANDROID_GRADLE_VERSION: "gradle-5.1.1"
And in your before_script, add this before chmod +x ./gradlew:
- wget --quiet --output-document=gradle.zip https://services.gradle.org/distributions/${ANDROID_GRADLE_VERSION}-bin.zip
- unzip -q gradle.zip
I'm new to Gitlab CI and I'm trying to use cache in .gitlab-ci.yml file (on Android platform). The gitlab ci works well but everytime I'm pushing code into gitlab, the CI will download all the data to run it again (It's will take about 30 minutues for each run code pushed).
I'm creating the Gitlab CI with method 1 in this tutorial : http://www.greysonparrelli.com/post/setting-up-android-builds-in-gitlab-ci-using-shared-runners/
I'm trying with many solutions on StackOverflow and another results on Google but still cannot cache.
Here is my .gitlab-ci.yml file:
image: openjdk:8-jdk
variables:
ANDROID_TARGET_SDK: "24"
ANDROID_BUILD_TOOLS: "24.0.3"
ANDROID_SDK_TOOLS: "24.4.1"
MAVEN_OPTS: -Dmaven.repo.local=/cache/maven.repository
before_script:
- export GRADLE_USER_HOME=/cache/.gradle
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
- tar --extract --gzip --file=android-sdk.tgz
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK}
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
- echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=$PWD/android-sdk-linux
- chmod +x ./gradlew
cache:
key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"
paths:
- .gradle/
- build/
- .m2/
- $HOME/.gradle/caches/
untracked: true
build:
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
And my result:
Running with gitlab-ci-multi-runner 1.5.2 (76fdacd)
Using Docker executor with image openjdk:8-jdk ...
Pulling docker image openjdk:8-jdk ...
Running on runner-060bf058-project-212-concurrent-0 via gitlab-runner...
Fetching changes...
Removing .gradle/
Removing android-sdk-linux/
Removing android-sdk.tgz
Removing app/build/
Removing build/
HEAD is now at d9b483e text commit here
From my gitlab project here master -> origin/master
Checking out b18798df as master...
Checking cache for build/master...
$ export GRADLE_USER_HOME=/cache/.gradle
$ apt-get --quiet update --yes
Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [402 kB]
Get:4 http://deb.debian.org jessie-backports InRelease [166 kB]
Get:5 http://deb.debian.org jessie Release.gpg [2373 B]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:7 http://deb.debian.org jessie Release [148 kB]
Get:8 http://deb.debian.org jessie-backports/main amd64 Packages [959 kB]
Get:9 http://deb.debian.org jessie/main amd64 Packages [9064 kB]
Fetched 11.0 MB in 22s (485 kB/s)
Reading package lists...
$ apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
Reading package lists...
Building dependency tree...
Reading state information...
unzip is already the newest version.
wget is already the newest version.
Suggested packages:
ncompress tar-scripts
The following NEW packages will be installed:
lib32gcc1 lib32stdc++6 lib32z1 libc6-i386
The following packages will be upgraded:
tar
.....
.....
.....
BUILD SUCCESSFUL
Creating cache build/master...
.gradle/: found 9 matching files
build/: found 4 matching files
WARNING: .m2/: no matching files
WARNING: /root/.gradle/caches/: no matching files
untracked: found 28180 files
Uploading artifacts...
app/build/outputs/: found 7 matching files
Uploading artifacts to coordinator... ok id=643 responseStatus=201 Created token=nGX6FDZD
Build succeeded
How can I do ? Thank you all
# This file is a template, and might need editing before it works on your project.
# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
cache:
untracked: false
key: ${CI_PROJECT_ID}
paths:
- android-sdk-linux
- .m2/
- .gradle/
- android-sdk.zip
- /var/cache/apt/
- android.keystore
- keystore.properties
stages:
- init
- test
- build
downloadAndroidSDK:
stage: init
script:
- KS_PASS=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
- export GRADLE_USER_HOME=$(pwd)/.gradle
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --continue --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -o -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- rm -f $CI_PROJECT_DIR/android.keystore
- echo y | keytool -genkeypair -keyalg RSA -ext KeyUsage:critical=digitalSignature -ext ExtendedkeyUsage:critical=codeSigning -dname "ou=Wdes, c=FR" -alias wdes -keypass $KS_PASS -keystore $CI_PROJECT_DIR/android.keystore -storepass $KS_PASS -validity 1 -deststoretype pkcs12
- keytool -list -storepass $KS_PASS -v -keystore $CI_PROJECT_DIR/android.keystore
- echo -e "release.key.alias=wdes\nrelease.key.password=$KS_PASS\nrelease.storeFile=$CI_PROJECT_DIR/android.keystore\nrelease.password=$KS_PASS\n\ndebug.key.alias=wdes\ndebug.key.password=$KS_PASS\ndebug.storeFile=$CI_PROJECT_DIR/android.keystore\ndebug.password=$KS_PASS\n" > keystore.properties
assembleDebug:
stage: build
dependencies: [ 'downloadAndroidSDK' ]
script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/
assembleRelease:
stage: build
dependencies: [ 'downloadAndroidSDK' ]
script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
- ./gradlew assembleRelease
artifacts:
paths:
- app/build/outputs/
lintDebug:
stage: test
dependencies: [ 'downloadAndroidSDK' ]
script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
lintFiles:
stage: test
dependencies: [ 'downloadAndroidSDK' ]
script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
- ./gradlew ktlint
debugTests:
stage: test
dependencies: [ 'downloadAndroidSDK' ]
script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- chmod +x ./gradlew
- ./gradlew -Pci --console=plain :app:testDebug