For this we need
A valid Google Play Developer account
Linux server with Docker preinstalled, in my case it's Ubuntu 16.04
Installed Android SDK
Jenkins - in this case, we'll deploy it using Docker
Gitea - A convenient service for our own Git repository (it is not necessary to use GItHub as well), we will also raise it on the basis of a Docker container
Setting up Google Play Account
Let's assume that you are already an existing developer and have published your applications in manual mode, which suggests that you know the main points of the process and should not be voiced, we will only touch on what we need for automatic deployment
Log in to Google Cloud Platform, if the project has not yet been created, then create it
In the IAM and administration section - Service accounts, click Create a service account
After filling in the appropriate fields, it will be created and will appear in the list, click on the three dots on the right and select create a key, select JSON, save it, we will need it to configure Jenkins
Log in to the Gooogle Play Developer Console
email , ( )
, .
Android SDK
# Install latest JDK
sudo apt install default-jdk
sudo apt install android-sdk
Android SDK PATH, ~/.bashrc
# Export the Android SDK path
export ANDROID_HOME=$HOME/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
# Fixes sdkmanager error with java versions higher than java 8
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
source ~/.bashrc
sdkmanager --list
sdkmanager "platform-tools" "platforms;android-28"
Android SDK , ,
Gitea
git GitHub , . ( gitea Telegram Bot`a )
https://docs.gitea.io/en-us/install-with-docker/
2
1) Gitea , Docker HUB
version: '2'
services:
web:
image: gitea/gitea:1.12.4
volumes:
- ./data:/data
ports:
- "3000:3000"
- "22:22"
depends_on:
- db
restart: always
db:
image: mariadb:10
restart: always
environment:
- MYSQL_ROOT_PASSWORD=changeme
- MYSQL_DATABASE=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=changeme
volumes:
- ./db/:/var/lib/mysql
2) docker-compose you_filename
3) Gitea URL http://you_IP:3000/
4) , , PUSH , ( , volume jenkins gradle , )
apk , keystore gradle ,
// Load keystore
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
// GenerateNameVersion
def getVersionNameTimestamp() {
return new Date().format('yy.MM.ddHHmm')
}
// GenerateVersionCode
def getVersionCodeTimestamp() {
def date = new Date()
def formattedDate = date.format('yyMMddHHmm')
def code = formattedDate.toInteger()
println sprintf("VersionCode: %d", code)
return code
}
......
android {
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
......
defaultConfig {
versionCode getVersionCodeTimestamp()
versionName "${getVersionNameTimestamp()}"
keystore.properties
storePassword=you_password_keystore keyPassword=you_password_key keyAlias=you_key_name storeFile=path_to_keystore_file
keystore.properties keystore , GitHub, OpenSource , .
Google Play , Gradle , , , - deploy (PUSH)
Jenkins
Docker , , ,
docker run -it -d -v jenkins_home:/var/jenkins_home -v /usr/lib/android-sdk:/usr/lib/android-sdk -p 8080:8080 -p 50000:50000 --env JENKINS_OPTS="--prefix=/jenkins" --restart always leganas/ls_repository:jenkins
volumes Android SDK
http://you_IP:8080/jenkins/
Jenkins ,
1) , System Configuration - , Environment variables ( )
2) - Git Gradle ( )
3) - , , API Token , , .
4) Git, Git client, Google OAuth Credentials plugin, Google Play Android Publisher
5) - Manage Credentials Configure credentials -Store - Jenkins - Global credentials (unrestricted)- 2 |
Git
.. Gitea login/password , GitHub
Google Play Market
JSON
6) Jenkins
- Git , Repository URL Credentials ( )
- Trigger builds remotely (e.g., from scripts), ( ) GIt huck
Invoke Gradle script , -
Release traack , , " "
7) Web Jenkins - Git /master , , Google Play.
Google Play , deploy Git PUSH /master
1) Gitea - - Git , post-receive ,
#!/bin/bash
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" = "$branch" ]; then
curl --user you_user_name:you_user_token http://you_url_jenkins/job/you_project/build?token=you_tocken_build
fi
done
you_user_name - jenkins
you_user_token -
you_url_jenkins Jenkins :
Jenkins PUSH master .
PS. If you use another Git system to store your code, then you can place the same code by hand in .git \ hooks \ post-update
Conclusion
In case of a positive feedback from the article, in the next part I will tell you how to write a Telegram bot to notify your testers about the availability of an application update on Google Play.
I hope this information was useful and will somehow make your life easier for setting up automatic publishing.