├── .github
└── workflows
│ ├── base-image.yaml
│ ├── lint-and-tests.yaml
│ ├── production.yaml
│ └── staging.yaml
├── .gitignore
├── .gitlab-ci.yml
├── Dockerfile
├── Gemfile
├── LICENSE.md
├── README.md
├── app
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-playstore.png
│ ├── java
│ └── codepath
│ │ └── demos
│ │ └── helloworlddemo
│ │ └── HelloWorldActivity.kt
│ └── res
│ ├── layout
│ └── activity_hello_world.xml
│ ├── menu
│ └── activity_hello_world.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ ├── ic_launcher_foreground.png
│ └── ic_launcher_round.png
│ ├── values-v11
│ └── styles.xml
│ ├── values-v14
│ └── styles.xml
│ └── values
│ ├── ic_launcher_background.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── docs
├── README_GOOGLE_PLAY.md
├── README_RU.md
├── android-ci-cd-CI-CD-flow.drawio.svg
├── android-ci-cd-tools.drawio.svg
├── android-ci-cd.drawio
├── badge_prod.png
├── badge_staging.png
├── gcp1.jpeg
├── gcp2.jpeg
├── gcp3.jpeg
├── gcp4.jpeg
├── gcp5.jpeg
├── gcp6.jpeg
├── gcp7.jpeg
├── googleplay1.jpeg
├── googleplay2.jpeg
├── googleplay3.jpeg
├── gp1.jpeg
├── gp2.jpeg
├── gp3.jpeg
├── gp4.jpeg
├── gp5.jpeg
└── gp6.jpeg
├── fastlane
├── Appfile
├── Fastfile
└── Pluginfile
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── project.properties
└── settings.gradle
/.github/workflows/base-image.yaml:
--------------------------------------------------------------------------------
1 | name: 'build and push base image'
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths:
8 | - 'Dockerfile'
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v2
15 | - uses: docker/metadata-action@v3
16 | with:
17 | images: ghcr.io/${{ github.repository }}
18 | - uses: docker/login-action@v1
19 | with:
20 | registry: ghcr.io
21 | username: ${{ github.actor }}
22 | password: ${{ secrets.GITHUB_TOKEN }}
23 | - uses: int128/kaniko-action@v1
24 | with:
25 | push: true
26 | tags: ghcr.io/${{ github.repository }}:latest
27 | cache: true
28 | cache-repository: ghcr.io/${{ github.repository }}/cache
29 |
30 |
--------------------------------------------------------------------------------
/.github/workflows/lint-and-tests.yaml:
--------------------------------------------------------------------------------
1 | name: 'lint and tests'
2 |
3 | on:
4 | pull_request_target:
5 | types: [opened, synchronize]
6 | branches:
7 | - main
8 | push:
9 | branches:
10 | - main
11 |
12 | env:
13 | GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
14 | APP_PACKAGE_NAME: ${{ secrets.APP_PACKAGE_NAME }}
15 |
16 | jobs:
17 | lint:
18 | runs-on: ubuntu-latest
19 | container:
20 | image: ghcr.io/${{ github.repository }}:latest
21 | credentials:
22 | username: ${{ github.actor }}
23 | password: ${{ secrets.github_token }}
24 | steps:
25 | - uses: actions/checkout@v3
26 | - uses: actions/cache@v2
27 | with:
28 | path: |
29 | ~/.gradle/caches
30 | ~/.gradle/wrapper
31 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
32 | restore-keys: |
33 | ${{ runner.os }}-gradle-
34 | - run: |
35 | echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
36 | bundle exec fastlane lint
37 |
38 | unit_tests:
39 | runs-on: ubuntu-latest
40 | container:
41 | image: ghcr.io/${{ github.repository }}:latest
42 | credentials:
43 | username: ${{ github.actor }}
44 | password: ${{ secrets.github_token }}
45 | steps:
46 | - uses: actions/checkout@v3
47 | - uses: actions/cache@v2
48 | with:
49 | path: |
50 | ~/.gradle/caches
51 | ~/.gradle/wrapper
52 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
53 | restore-keys: |
54 | ${{ runner.os }}-gradle-
55 | - run: |
56 | echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
57 | bundle exec fastlane unit_test
58 |
--------------------------------------------------------------------------------
/.github/workflows/production.yaml:
--------------------------------------------------------------------------------
1 | name: 'production'
2 |
3 | on:
4 | workflow_run:
5 | workflows: ['staging']
6 | branches: [main]
7 | types:
8 | - completed
9 |
10 | env:
11 | KEYSTORE_PW: ${{ secrets.KEYSTORE_PW }}
12 | KEYSTORE: ${{ secrets.KEYSTORE }}
13 | SA_JSON_KEY: ${{ secrets.SA_JSON_KEY }}
14 | ALIAS: ${{ secrets.ALIAS }}
15 | ALIAS_PW: ${{ secrets.ALIAS_PW }}
16 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
17 | GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
18 | APP_VERSION_NAME: ${{ secrets.APP_VERSION_NAME }}
19 | FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }}
20 | CI_PIPELINE_ID: ${{ github.run_number }}
21 | CI_COMMIT_BEFORE_SHA: ${{ github.event.before }}
22 | APP_PACKAGE_NAME: ${{ secrets.APP_PACKAGE_NAME }}
23 | CI_ENVIRONMENT_NAME: ${{ github.workflow }}
24 |
25 | jobs:
26 | prod_firebase:
27 | if: ${{ github.event.workflow_run.conclusion == 'success' }}
28 | runs-on: ubuntu-latest
29 | container:
30 | image: ghcr.io/${{ github.repository }}:latest
31 | credentials:
32 | username: ${{ github.actor }}
33 | password: ${{ secrets.github_token }}
34 | steps:
35 | - uses: actions/checkout@v3
36 | - uses: actions/cache@v2
37 | with:
38 | path: |
39 | ~/.gradle/caches
40 | ~/.gradle/wrapper
41 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
42 | restore-keys: |
43 | ${{ runner.os }}-gradle-
44 | - run: |
45 | echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
46 | echo $SA_JSON_KEY | base64 -d -i > key_firebase.json
47 | echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
48 | bundle exec fastlane firebase_distribution
49 | env:
50 | FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_PROD }}
51 | BUILD_TASK: "assemble" # Change to bundle if you need aab application
52 | BUILD_TYPE: "release"
53 |
54 | google_play:
55 | if: ${{ github.event.workflow_run.conclusion == 'success' }}
56 | needs: [prod_firebase]
57 | runs-on: ubuntu-latest
58 | container:
59 | image: ghcr.io/${{ github.repository }}:latest
60 | credentials:
61 | username: ${{ github.actor }}
62 | password: ${{ secrets.github_token }}
63 | steps:
64 | - uses: trstringer/manual-approval@v1
65 | with:
66 | secret: ${{ github.TOKEN }}
67 | approvers: ${{ secrets.APPROVERS }}
68 | - uses: actions/checkout@v3
69 | - run: |
70 | echo $SA_JSON_GP_KEY | base64 -d -i > /tmp/key_gp.json
71 | echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
72 | echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
73 | bundle exec fastlane google_beta
74 | env:
75 | BUILD_TASK: "bundle"
76 | BUILD_TYPE: "release"
77 | SA_JSON_GP_KEY: ${{ secrets.SA_JSON_GP_KEY }}
78 |
--------------------------------------------------------------------------------
/.github/workflows/staging.yaml:
--------------------------------------------------------------------------------
1 | name: 'staging'
2 |
3 | on:
4 | workflow_run:
5 | workflows: ['lint and tests']
6 | branches: [main]
7 | types:
8 | - completed
9 | workflow_dispatch:
10 |
11 | env:
12 | KEYSTORE_PW: ${{ secrets.KEYSTORE_PW }}
13 | KEYSTORE: ${{ secrets.KEYSTORE }}
14 | SA_JSON_KEY: ${{ secrets.SA_JSON_KEY }}
15 | ALIAS: ${{ secrets.ALIAS }}
16 | ALIAS_PW: ${{ secrets.ALIAS_PW }}
17 | SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
18 | GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
19 | APP_VERSION_NAME: ${{ secrets.APP_VERSION_NAME }}
20 | FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID_STG }}
21 | CI_PIPELINE_ID: ${{ github.run_number }}
22 | CI_COMMIT_BEFORE_SHA: ${{ github.event.before }}
23 | APP_PACKAGE_NAME: ${{ secrets.APP_PACKAGE_NAME }}
24 | BUILD_TASK: "assemble"
25 | BUILD_TYPE: "debug"
26 | CI_ENVIRONMENT_NAME: ${{ github.workflow }}
27 |
28 | jobs:
29 | staging_firebase:
30 | if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch' && github.event.workflow_run.conclusion != 'success') }}
31 | runs-on: ubuntu-latest
32 | container:
33 | image: ghcr.io/${{ github.repository }}:latest
34 | credentials:
35 | username: ${{ github.actor }}
36 | password: ${{ secrets.github_token }}
37 | steps:
38 | - uses: actions/checkout@v3
39 | - uses: actions/cache@v2
40 | with:
41 | path: |
42 | ~/.gradle/caches
43 | ~/.gradle/wrapper
44 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
45 | restore-keys: |
46 | ${{ runner.os }}-gradle-
47 | - run: |
48 | echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
49 | echo $SA_JSON_KEY | base64 -d -i > key_firebase.json
50 | echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
51 | bundle exec fastlane firebase_distribution
52 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .gradle/
3 | build/
4 | local.properties
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | default:
2 | image: $CI_REGISTRY_IMAGE:latest
3 | # tags:
4 | # - my-tag
5 |
6 | before_script:
7 | - export GRADLE_USER_HOME=cache/.gradle
8 | - echo $KEYSTORE | base64 -d -i > /tmp/my-release-key.keystore
9 | - echo $SA_JSON_KEY | base64 -d -i > key_firebase.json
10 | - echo $GOOGLE_SERVICES_JSON | base64 -d -i > app/google-services.json
11 |
12 | cache:
13 | key:
14 | files:
15 | - gradle/wrapper/gradle-wrapper.properties
16 | paths:
17 | - $PWD/cache/.gradle/
18 |
19 | stages:
20 | - build_base_image
21 | - tests
22 | - deploy_staging
23 | - deploy_prod
24 |
25 | build_base_image:
26 | rules:
27 | - if: $CI_COMMIT_REF_NAME == "main"
28 | changes:
29 | - Dockerfile
30 | stage: build_base_image
31 | image:
32 | name: gcr.io/kaniko-project/debug:769
33 | entrypoint: [""]
34 | before_script:
35 | - mkdir -p /kaniko/.docker
36 | - echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
37 | script:
38 | - >-
39 | /kaniko/executor
40 | --context "${CI_PROJECT_DIR}"
41 | --dockerfile "${CI_PROJECT_DIR}/Dockerfile"
42 | --destination $CI_REGISTRY_IMAGE:latest
43 |
44 |
45 | lints:
46 | rules:
47 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
48 | - if: $CI_COMMIT_REF_NAME == "main"
49 | stage: tests
50 | script:
51 | - bundle exec fastlane lint
52 |
53 | unit_test:
54 | rules:
55 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
56 | - if: $CI_COMMIT_REF_NAME == "main"
57 | stage: tests
58 | script:
59 | - bundle exec fastlane unit_test
60 |
61 | staging_firebase:
62 | rules:
63 | - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
64 | when: manual
65 | - if: $CI_COMMIT_REF_NAME == "main"
66 | stage: deploy_staging
67 | script:
68 | - bundle exec fastlane firebase_distribution
69 | environment:
70 | name: staging
71 |
72 | prod_firebase:
73 | rules:
74 | - if: $CI_COMMIT_REF_NAME == "main"
75 | stage: deploy_prod
76 | script:
77 | - bundle exec fastlane firebase_distribution
78 | artifacts:
79 | paths:
80 | - app/build/outputs/bundle/release/app-release.aab
81 | expire_in: 1 day
82 | environment:
83 | name: prod
84 |
85 | google_play:
86 | rules:
87 | - if: $CI_COMMIT_REF_NAME == "main"
88 | when: manual
89 | stage: deploy_prod
90 | script:
91 | - echo $SA_JSON_GP_KEY | base64 -d -i > /tmp/key_gp.json
92 | - bundle exec fastlane google_beta
93 | dependencies:
94 | - prod_firebase
95 | environment:
96 | name: prod-gp
97 | when: manual
98 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:11-jdk-slim-buster
2 |
3 | # Just matched `app/build.gradle`
4 | ENV ANDROID_COMPILE_SDK "30"
5 |
6 | # Just matched `app/build.gradle`
7 | ENV ANDROID_BUILD_TOOLS "30.0.2"
8 |
9 | # Version from https://developer.android.com/studio/releases/sdk-tools
10 | ENV ANDROID_SDK_TOOLS "7583922"
11 | ENV ANDROID_HOME /android-sdk-linux
12 | ENV PATH="${PATH}:/android-sdk-linux/platform-tools/"
13 |
14 | # Install OS packages
15 | RUN apt-get --quiet update --yes && \
16 | apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 build-essential ruby ruby-dev graphicsmagick
17 |
18 | # Install Android SDK
19 | RUN wget --quiet --output-document=android-sdk.zip "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip" && \
20 | unzip -d ${ANDROID_HOME} android-sdk.zip && \
21 | yes | ./android-sdk-linux/cmdline-tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" --sdk_root=android-sdk-linux/ && \
22 | yes | ./android-sdk-linux/cmdline-tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" --sdk_root=android-sdk-linux && \
23 | # Clean cache
24 | apt-get clean autoclean && \
25 | apt-get autoremove --yes && \
26 | rm -rf /var/lib/{apt,dpkg,cache,log}/ android-sdk.zip
27 |
28 | # Install Fastlane
29 | COPY Gemfile .
30 | RUN gem install bundler && \
31 | bundle install && \
32 | gem install fastlane-plugin-firebase_app_distribution fastlane-plugin-badge
33 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | gem "fastlane"
4 |
5 | plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
6 | eval_gemfile(plugins_path) if File.exist?(plugins_path)
7 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Boilerplate to Prepare a CI/CD for Android Applications
2 |
3 | [](https://maddevs.io?utm_source=github&utm_medium=madboiler)
4 | [](https://github.com/maddevsio/android-ci-cd/blob/main/LICENSE.md)
5 |
6 | #### README Languages
7 | * [Russian](docs/README_RU.md)
8 |
9 | Stop publishing your Android apps manually and start doing this in a fully automated fashion to any stage (test, beta, and prod).
10 |
11 | 👇 Watch this 5 min explanation video to get a deeper understanding of the approach and benefits 👇
12 | [](https://youtu.be/poSugKUtBPU)
13 |
14 | ---
15 |
16 | ## Advantages of this boilerplate
17 |
18 | * **Quick start CI/CD**: With this boilerplate, you can easily build the CI/CD for your android app based on Fastlane.
19 | * **Easy adaptation to external CI/CD tools**: We use GitLab-ci or GitHub actions as the executor of Fastlane commands and the construction of the workflow.
20 | * **Notification**: Pipeline operation Slack notifications, notifications about successful operations or errors in the pipeline process.
21 | * **No special build machine setup is required**: We build the application inside a docker container with all the dependencies installed; this provides portability and the ability to use standard GitHub agents or GitLab runners.
22 |
23 | ## CI/CD
24 |
25 | * Let's try to answer some questions:
26 | * [What is CI/CD](https://en.wikipedia.org/wiki/CI/CD)?
27 | * Above all, CI/CD allows you to increase productivity through automation. As in the manufacturing industry,
28 | you can automate the repetitive assembly process (application assembly) with automated workers, allowing developers to focus on value-added design and development processes.
29 | * What are the benefits of using CI/CD in mobile development?
30 | 1. `Faster release cycles`
31 | * With CI/CD, developers get used to make even the smallest code changes, as they will be built and delivered automatically in the background. This automated flow ensures that there is always an alpha or beta release ready for testing with the latest code.
32 | 2. `Faster feedback/response with "continuous integration"`
33 | * With a faster release cycle with fewer changes, it becomes possible to pinpoint the source of a bug when a problem is identified. This is especially important for large teams where code conflicts can cause significant problems.
34 | 3. `Improve coding discipline with query-based assembly and automated tests`
35 | * With a pull request commit, the build occurs before the merge, followed by automatic unit testing and code verification after each merge; the code itself is tested more thoroughly before it becomes part of the release.
36 | 4. `Early warning and increased testing with "continuous deployment"`
37 | * By testing each individual change with multiple steps in the testing workflow, problems can be identified faster.
38 | 5. `Isolation from the complexities associated with application delivery`
39 | * Every development discipline has its own set of complexities, and mobile apps are no exception. Android has completely independent and different processes for creating, signing, distributing, and installing apps. CI/CD helps to automate this process.
40 |
41 | ### CI/CD description
42 |
43 | * This diagram describes the flow which we use
44 |
45 | 
46 |
47 | * Step descriptions
48 |
49 | ```
50 | - build base image - Step for build base image which used for build application.
51 | - tests and lints - Step for run tests and lints.
52 | - build and deploy to firebase - Step for build and deploy application to Firebase.
53 | - build and deploy to google play - Step for build and deploy application and Google Play.
54 | ```
55 |
56 | * It is worth explaining what several builds are used for.
57 |
58 | Terms and conditions:
59 | * Applications in `apk` format cannot be uploaded to Google Play
60 | * Applications in `aab` format can be uploaded in Firebase and Google Play
61 |
62 | Because of it, we have to build several builds.
63 |
64 | * For the convenience of testing, at the stage of `Merge Request`, we give the opportunity to build the application on demand and send it to `Firebase`.
65 | * It is convenient to check your application without merging code to the main branch.
66 | * The application in `apk` format upload to the Firebase.
67 |
68 | ### Feature
69 |
70 | * GitLab:
71 | * We have a manual step to deploy an application to Google Play.
72 | * We have a manual step for building and deploying an application to staging `Firebase`; this step is available on `Merge Request1`.
73 | * GitHub:
74 | * We use [trstringer/manual-approval](https://trstringer.com/github-actions-manual-approval/) action, which helps to create manual approval in the deployment to Google Play.
75 | * We use a manual job - `workflow_dispatcher` for building and deploying an application from any branch.
76 | * Fastlane plugin badge
77 | * This gem helps to add a badge to your Android app icon.
78 | * More info [here](https://docs.fastlane.tools/actions/badge/)
79 | * You can always configure it for your project, but here are examples of how we did it.
80 |
81 |  
82 |
83 | ### Tools and services
84 |
85 | * [Fastlane](https://fastlane.tools/) - Fastlane is a tool for iOS and Android developers to automate tedious tasks like generating screenshots, dealing with provisioning profiles, and releasing your application.
86 | * [GitLab-ci](https://docs.gitlab.com/ee/ci/) or [GitHub Actions](https://docs.github.com/en/actions) - CI/CD systems are used to build the pipeline logic and to execute Fastlane lanes.
87 | * [docker](https://www.docker.com/) - Docker is used as the build environment for the application.
88 | * [CGP](https://cloud.google.com/)
89 | * [Firebase](https://firebase.google.com/docs/app-distribution) - Testing environment for the application.
90 | * [Google Play](https://play.google.com/console/about/) - Production environment for the application.
91 |
92 | ### Description of main components
93 |
94 | 
95 |
96 | ### Repository structure
97 |
98 | ```commandline
99 | .
100 | ├── app - Folder which contains example application
101 | │ ├── build.gradle - File for android project configuration
102 | │ └── src
103 | ├── build.gradle
104 | ├── Dockerfile - Dockerfile for base image which used in build step
105 | ├── docs - Folder for documentation
106 | ├── fastlane - Folder with fastlane configuration
107 | │ ├── Appfile - File for main fastlane configuration
108 | │ ├── Fastfile - File for configuration fastlane actions
109 | │ └── Pluginfile - File for configuration fastlane dependencies
110 | ├── Gemfile
111 | ├── gradle - Folder for gradle build tool
112 | ├── gradle.properties - File for gradle configuration
113 | ├── gradlew
114 | ├── gradlew.bat
115 | ├── ic_launcher-web.png
116 | ├── libs
117 | ├── proguard-project.txt
118 | ├── project.properties
119 | ├── README.md
120 | └── settings.gradle - File for graddle setting
121 | ```
122 |
123 | ### From scratch
124 |
125 | 1. [Create an account in the Google cloud platform](https://cloud.google.com/)
126 | 2. [Create a Google cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects)
127 | 3. [Create a Firebase project and activate app distribution](https://cloud.google.com/firestore/docs/client/get-firebase)
128 | 4. [Create a Google Play developer account](https://play.google.com/console/about/)
129 |
130 | #### Preparation keys and environment variables
131 |
132 | 1. Json file with configuration for Firebase
133 | * You must add a json file with the Firebase project settings encoded to base64 to the environment variable.
134 | > https://firebase.google.com/docs/android/setup - Step 3
135 | ```bash
136 | base64 google-services.json > firebase_setting
137 | ```
138 |
139 | 2. Service account with access to Firebase
140 | * Create Service Account for the release application to Firebase
141 | > Choose your Firebase account --> Project Overview --> Project setting --> Service Account --> create service account
142 | * Add SA key encoded to base64 to an environment variable.
143 | ```bash
144 | base64 sa.json > key_firebase
145 | ```
146 |
147 | 3. Service account with access to Google Play
148 | * Create Service Account for release application to [Google Play](docs/README_GOOGLE_PLAY.md)
149 | * Add SA key encoded to base64 to an environment variable
150 | ```bash
151 | base64 google_play.json > google_play
152 | ```
153 |
154 | 4. Keystore for signing an application
155 | * To sign an application, you need a key, which can be generated with the command.
156 | ```bash
157 | keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
158 | ```
159 | * Add signing keystore encoded to base64 to an environment variable.
160 | ```bash
161 | base64 my-release-key.keystore > keystore
162 | ```
163 |
164 | ##### GitLab CI/CD
165 |
166 | * We use `Environments` in our pipeline to divide our variables by environments; before you start please create 3 environments in `gitlab-ci-cd`:
167 |
168 | ```
169 | GitLab --> Deployments --> Environment --> New Environment
170 | ```
171 |
172 | * We need to create three environments:
173 | * staging
174 | * prod
175 | * prod-gp
176 |
177 | ##### GitHub Actions
178 |
179 | * We can use environments in GitHub Actions, but the environments are available only in public repositories or in corporate subscriptions.
180 | * In this boilerplate, we don't use environments in GitHub Actions.
181 |
182 | ##### Prepare environment variables
183 |
184 | 1. Copy content of this file `firebase_setting`:
185 | ```
186 | GitLab --> Settings --> CI/CD --> Variables --> Add variable
187 | ```
188 | or
189 | ```
190 | GitHub --> Settings --> Secrets --> Actions --> New repository secret
191 | ```
192 |
193 | > In the key field paste `GOOGLE_SERVICES_JSON` in the value field paste your `google-services.json` encoded to base64.
194 |
195 | 2. Copy content of this file `key_firebase`:
196 | ```
197 | GitLab --> Settings --> CI/CD --> Variables --> Add variable
198 | ```
199 | or
200 | ```
201 | GitHub --> Settings --> Secrets --> Actions --> New repository secret
202 | ```
203 |
204 | > In the key field paste `SA_JSON_KEY` in the value field paste your `sa.key` encoded to base64.
205 |
206 | 3. Copy content of this file `google_play`:
207 |
208 | ```
209 | GitLab --> Settings --> CI/CD --> Variables --> Add variable
210 | ```
211 | or
212 | ```
213 | GitHub --> Settings --> Secrets --> Actions --> New repository secret
214 | ```
215 |
216 | > In the key field paste `SA_JSON_GP_KEY` in the value field paste your `google_play.json` encoded to base64.
217 |
218 | 4. Copy content of this file `keystore`:
219 |
220 | ```
221 | GitLab --> Settings --> CI/CD --> Variables --> Add variable
222 | ```
223 | or
224 | ```
225 | GitHub --> Settings --> Secrets --> Actions --> New repository secret
226 | ```
227 | > In the key field paste `KEYSTORE` in the value field paste your `my-release-key.keystore` encoded to base64.
228 |
229 | ##### Environment variables
230 |
231 | | NAME | ENVIRONMENT | DESCRIPTION |
232 | |-----------------------------|:--------------------:|-----------------------------------------------------------------------------------------------------------------------------------------------:|
233 | | KEYSTORE | ALL | Encoded to base64 signing keystore (base64) |
234 | | KEYSTORE_PW | ALL | Password for signing keystore |
235 | | ALIAS | ALL | Keystore alias |
236 | | ALIAS_PW | ALL | Password for keystore alias |
237 | | SA_JSON_KEY | STAGING/PROD | Service Account key for Firebase (base64) |
238 | | SA_JSON_GP_KEY | PROD-GP | Service account key for Google Play Console (base64) |
239 | | GOOGLE_SERVICES_JSON | ALL | Main configuration file for Firebase |
240 | | APP_VERSION_NAME | STAGING/PROD/PROD-GP | Application version |
241 | | FIREBASE_APP_ID | STAGING/PROD | Application ID in Firebase |
242 | | BUILD_TASK | STAGING/PROD/PROD-GP | Task name in gradle (assemble, bundle, test) |
243 | | BUILD_TYPE | STAGING/PROD/PROD-GP | Build type (assemble, release) |
244 | | SLACK_WEBHOOK_URL | ALL | Slack webhook |
245 | | FIREBASE_TESTER_GROUP_NAME | STAGING/PROD | Name of testers group in Firebase |
246 | | APPROVERS | ALL | List of approvers for Google Play release, used only in GitHub Actions |
247 | | CI_PIPELINE_ID | ALL | Pipeline ID used for `versionCode`, by default declared in the GitLab, in the GitHub Actions used github.run_number |
248 | | CI_COMMIT_BEFORE_SHA | ALL | Previous commit, used for build changelog, by default declared in the GitLab, in the GitHub Actions used github.event.before |
249 | | FIREBASE_ARTIFACT_TYPE | STAGING/PROD | Artifact type for Firebase distribution |
250 | | PROJECT_DIR | ALL | If the project is not in the main directory, you can specify the path to the project directory through the `PROJECT_DIR` variable in Fastfile. |
251 | | APP_PACKAGE_NAME | ALL | The default android package name for example we use `com.boiler.android.hello` |
252 | | CI_ENVIRONMENT_NAME | STAGING/PROD | Used in fastlane badge, to display env in icon. |
253 |
254 | * When you complete all this preparation, you can start to build and release the application to Firebase
255 |
256 | ### Additional configuration
257 |
258 | #### Configuration plugins for Fastlane
259 |
260 | * We have `Pluginfile` in this file we can configure plugins for Fastlane, by default we use [fastlane-plugin-firebase_app_distribution](https://github.com/fastlane/fastlane-plugin-firebase_app_distribution) and [fastlane-plugin-badge](https://github.com/HazAT/fastlane-plugin-badge)
261 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | id 'com.google.gms.google-services'
5 | }
6 |
7 | def getVersionCode = { ->
8 | def code = project.hasProperty('versionCode') ? versionCode.toInteger() : Integer.MAX_VALUE
9 | println "VersionCode is set to $code"
10 | return code
11 | }
12 |
13 | repositories {
14 | mavenCentral()
15 | }
16 |
17 | android {
18 | compileSdk 32
19 |
20 | defaultConfig {
21 | applicationId System.env.APP_PACKAGE_NAME
22 | minSdk 24
23 | targetSdk 32
24 | versionCode getVersionCode()
25 | versionName System.env.APP_VERSION_NAME
26 |
27 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28 |
29 | }
30 |
31 | buildTypes {
32 |
33 | release {
34 | debuggable false
35 | minifyEnabled true
36 |
37 | resValue "string", "app_name", "boiler"
38 | }
39 |
40 | debug {
41 | debuggable true
42 | minifyEnabled false
43 |
44 | resValue "string", "app_name", "staging boiler"
45 |
46 | applicationIdSuffix ".staging"
47 | versionNameSuffix "-S"
48 | }
49 | }
50 |
51 | buildFeatures {
52 | viewBinding true
53 | }
54 |
55 | compileOptions {
56 | sourceCompatibility JavaVersion.VERSION_1_8
57 | targetCompatibility JavaVersion.VERSION_1_8
58 | }
59 |
60 |
61 | flavorDimensions 'app'
62 |
63 | }
64 |
65 | dependencies {
66 | implementation "androidx.core:core-ktx:1.8.0"
67 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |