6

I am experimenting with GitLab's CI/CD and is figuring out how to generate a signed release APK.

I've read this article here.

and it suggested the following:

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

and storing the variables at Gitlab CI/CD variables.

But everytime I run the pipeline it always results to this:

* What went wrong:
Execution failed for task ':app:packageRelease'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: 
com.android.ide.common.signing.KeytoolException: Failed to read key key0 from store "/tmp/Lp7GrQLJ/0/XXXXX/sample-android-project/keystore": Keystore was tampered with, or password was incorrect

Can anyone please guide me here? What could I possible be doing wrong?

Archie G. Quiñones
  • 11,638
  • 18
  • 65
  • 107

1 Answers1

-4

May this will helps you.

image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "27"
  ANDROID_BUILD_TOOLS: "27.0.0"
  ANDROID_SDK_TOOLS: "24.4.1"

before_script:
  - 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_COMPILE_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
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  - export GRADLE_USER_HOME="$(pwd)/.gradle"
  - export ANDROID_HOME="$(pwd)/.android"
  - mkdir -p "${ANDROID_HOME}/licenses"
  - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e" > "${ANDROID_HOME}/licenses/android-sdk-license"
  - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "${ANDROID_HOME}/licenses/android-sdk-preview-license"
  - echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "${ANDROID_HOME}/licenses/intel-android-extra-license"
  #- ./gradlew --parallel --stacktrace --no-daemon build 
  - chmod +x ./gradlew

stages:
  - build

build:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

This code is for the Debug Build please replace the assembleDebug to assembleRelease in script.

Put it in your project main folder with the name .gitlab-ci.yml.

Shubham Sejpal
  • 3,556
  • 2
  • 14
  • 31
  • 3
    The config above generate a debugAPK.. If I change that to release I would need to specify the keystore file, alias, keystore password and password. That isnt shown in your config. – Archie G. Quiñones Jun 10 '19 at 05:10
  • Have you tried to make assembleRelease app by config the keystore details put it with your build.gradle file? may 99% they will works – Shubham Sejpal Jun 10 '19 at 05:13
  • 1
    as much as possible I would not want to place those information in the build.gradle file for security reasons. If you look at the article I linked that is exactly what he did. – Archie G. Quiñones Jun 10 '19 at 05:18
  • 1
    @ShubhamSejpal How to add the key and password? – Midhilaj Nov 18 '19 at 04:56
  • @Midhilaj please check this link for the Release build keystore path configuration in gradle file. https://stackoverflow.com/a/21020469/6096821 (OR) if you want to configure with CI than please follow this : https://android.jlelse.eu/android-gitlab-ci-cd-sign-deploy-3ad66a8f24bf – Shubham Sejpal Nov 18 '19 at 06:36