You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before you can use any tools in the Google Cloud SDK, you must authorize `gcloud`. Google offers two types of authorization: user accounts and service accounts. Because you are installing the Cloud SDK on CircleCI, the service account is the appropriate choice.
38
38
39
-
### 1. Create a service account
39
+
### a. Create a service account
40
40
{: #create-a-service-account }
41
41
42
42
Create a service account by following Steps 1-3 of [Google's instructions](https://cloud.google.com/sdk/docs/authorizing#authorizing_with_a_service_account). Remember to download the JSON-formatted key file.
43
43
44
-
### 2. Add a key file
44
+
### b. Add a key file
45
45
{: #add-a-key-file }
46
46
47
47
Add the key file to CircleCI as a [project environment variable](/docs/set-environment-variable/#set-an-environment-variable-in-a-project). In this example, the variable is named `GCLOUD_SERVICE_KEY`. Using this particular name is not required, but it will be used throughout the examples in this document.
48
48
49
-
### 3. Add environment variables
49
+
### c. Add environment variables
50
50
{: #add-env-vars }
51
51
52
52
For convenience, add two more environment variables to your CircleCI project:
53
53
54
54
-`GOOGLE_PROJECT_ID`: the ID of your GCP project.
55
55
-`GOOGLE_COMPUTE_ZONE`: the default [compute zone](https://cloud.google.com/compute/docs/regions-zones/).
56
56
57
-
#### Add granular permissions
58
-
{: #add-granular-permissions }
59
-
60
57
If you are having issues pushing container images to GCR you may need more granular permissions than the default `service account` provides. You can grant permission changes in the Cloud Storage [IAM Console](https://console.cloud.google.com/iam-admin/iam/project).
61
-
58
+
<br/>
59
+
<br/>
62
60
Refer to the Cloud Storage [permission documentation](https://cloud.google.com/storage/docs/access-control/iam-permissions)
63
61
to learn more about Identity and Access Management (IAM) permissions.
62
+
{: class="alert alert-info" }
64
63
65
64
## 3. Authenticate to Google Container Registry
66
65
{: #authenticate-to-google-container-registry }
@@ -91,7 +90,7 @@ jobs:
91
90
password: $GCLOUD_SERVICE_KEY # JSON service account you created, do not encode to base64
92
91
```
93
92
94
-
**Note:** If base64 encoding is required for your particular workflow, use the following command:
93
+
If base64 encoding is required for your particular workflow, use the following command:
95
94
96
95
```shell
97
96
cat <file> | base64 -w 0
@@ -118,7 +117,6 @@ jobs:
118
117
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
119
118
```
120
119
121
-
**Note:**
122
120
If you are using a custom base image, ensure that you have the most recent components by adding the following command before authorizing the SDK.
Copy file name to clipboardExpand all lines: jekyll/_cci2/deploy-android-applications.adoc
+97-60Lines changed: 97 additions & 60 deletions
Original file line number
Diff line number
Diff line change
@@ -21,28 +21,33 @@ In this how-to guide, you will learn how to automatically deploy your Android ap
21
21
To complete this tutorial, you will need the following:
22
22
23
23
- An Android project, built using link:https://gradle.org/[Gradle].
24
-
- Your Android project set up in CircleCI. If this is your first time setting up a project in CircleCI, refer to our <<getting-started#,Quickstart Guide>> for a walkthrough.
24
+
- Your Android project set up in CircleCI. If this is your first time setting up a project in CircleCI, refer to our xref:getting-started#[Quickstart guide] for a walkthrough.
25
25
- Fastlane installed and granted access to Google Play Store using credentials from your Google Developers service account. You may follow the instructions to install, set up, and configure fastlane supply in the link:https://docs.fastlane.tools/getting-started/android/setup/[Fastlane Android setup documentation].
26
26
27
27
NOTE: In the Fastlane setup, you will download a credentials file from your Google Developers service account. This tutorial assumes that you have saved this file in the `fastlane` folder as `api.json`.
28
28
29
-
This tutorial also walks you through how to use the Android orb for deployment. You are not required to be familiar with the Android orb for this tutorial, but we recommend reading the <<orb-intro#,Orb introduction page>> if you have not used CircleCI orbs before. Alternatively, this tutorial also shows you how to deploy your project without using the orb.
29
+
This tutorial also walks you through how to use the Android orb for deployment. You are not required to be familiar with the Android orb for this tutorial, but we recommend reading the xref:orb-intro#[Orb introduction page] if you have not used CircleCI orbs before. Alternatively, this tutorial also shows you how to deploy your project without using the orb.
== 1. Configure Fastlane for deployment to Google Play Store
33
33
34
-
. Navigate to your `fastlane` directory and open `Fastfile`. This file is used to configure the tasks you can execute with Fastlane. If you open the file, you will observe four different blocks:
35
-
+
34
+
To configure Fastlane for deployment, you will need to configure tasks and update the Play Store lane.
35
+
36
+
[#configure-tasks]
37
+
=== a. Configure tasks
38
+
39
+
Navigate to your `fastlane` directory and open `Fastfile`. This file is used to configure the tasks you can execute with Fastlane. If you open the file, you will observe four different blocks:
40
+
36
41
- `before_all`: This is where you specify instructions to be performed before a lane is executed.
37
-
+
38
42
- `lane`: This is where you define an actual task you want to perform, such as deploying to the Play Store. You can define as many lanes as you want.
39
-
+
40
43
- `after_all`: This block is called when the executed lane was successful.
41
-
+
42
44
- `error`: This block will be called if an error occurs in any of the other blocks.
43
45
44
-
. The Fastfile already comes with a `playstore` lane that generates a release build and deploys it to the Play Store. You will modify this lane. In the Fastfile, update the `playstore` lane like so:
45
-
+
46
+
[#update-play-store-lane]
47
+
=== b. Update Play Store lane
48
+
49
+
The Fastfile already comes with a `playstore` lane that generates a release build and deploys it to the Play Store. You will modify this lane. In the Fastfile, update the `playstore` lane like so:
50
+
46
51
```
47
52
lane :playstore do
48
53
gradle(task: "bundle")
@@ -52,16 +57,19 @@ lane :playstore do
52
57
)
53
58
end
54
59
```
55
-
+
60
+
56
61
This lane will run `gradle bundle` and generate an `app-release.aab` (Android App Bundle), and then deploy the bundle to the internal track of your project in the Google Play Console.
57
62
58
63
[#prepare-your-app-for-deployment]
59
64
== 2. Prepare your app for deployment
60
65
61
-
Next, you will make some updates to your app to prepare it for deployment. You will have to add a release signing config to your app-module `build.gradle` file. This enables Fastlane to use the same keystore you used in generating earlier releases of your app to also generate subsequent releases.
66
+
To prepare your app for deployment, you will need to add a release signing configuration to your app-module `build.gradle` file. This enables Fastlane to use the same keystore you used in generating earlier releases of your app to also generate subsequent releases.
67
+
68
+
[#add-signingconfig-snippet]
69
+
=== a. Add signingConfigs snippet
70
+
71
+
Add the following `signingConfigs` snippet to your app-module `build.gradle` file:
62
72
63
-
. Add the `signingConfigs` snippet to your app-module `build.gradle`:
64
-
+
65
73
```
66
74
android {
67
75
signingConfigs {
@@ -75,11 +83,14 @@ android {
75
83
...
76
84
}
77
85
```
78
-
+
86
+
79
87
NOTE: For this tutorial, you will be generating a `keystore` and `keystore.properties` at runtime. You can replace the fields with your actual passwords and information for local deployment, but we strongly advise to *not* upload these credentials to a remote repository. If you need help generating a keystore for your application, you may refer to the link:https://developer.android.com/studio/publish/app-signing#generate-key[Android user guide].
80
88
81
-
. Update the `buildTypes` section of the `build.gradle` file like so:
82
-
+
89
+
[#update-buildtypes]
90
+
=== b. Update buildTypes
91
+
92
+
Update the `buildTypes` section of your `build.gradle` file:
93
+
83
94
```
84
95
buildTypes {
85
96
release {
@@ -88,11 +99,14 @@ buildTypes {
88
99
}
89
100
}
90
101
```
91
-
+
102
+
92
103
With this, you have configured the app to use a specific keystore. Next, you will create functions in your `build.gradle` file to help you generate build numbers for your app versions.
93
104
94
-
. Add the following snippet just before the `android` section of your app-module `build.gradle` file:
95
-
+
105
+
[#add-android-snippet]
106
+
=== c. Add snippet before android section
107
+
108
+
Add the following snippet just before the `android` section of your app-module `build.gradle` file:
In this snippet, you added variables that hold your app version values. You then added two methods, `generateVersionCode` and `generateVersionName` to generate the version code and version name based on how the app version value changes. This helps to give your app a unique and progressive way of generating your version code when you modify your app versions.
127
-
+
141
+
128
142
Note that you will need to update at least one parameter of the version for every deployment. Fastlane fails if a version code is reused.
129
143
130
-
. Update these properties in the `defaultConfig` section of the `build.gradle` file like so:
144
+
[#update-defaultconfig]
145
+
=== d. Update properties in defaultConfig
146
+
147
+
Update the following properties in the `defaultConfig` section of the `build.gradle` file:
131
148
132
149
```
133
150
defaultConfig {
@@ -141,32 +158,39 @@ defaultConfig {
141
158
Now your android app is able to be bundled and deployed on your local machine.
142
159
143
160
[#set-up-circleci-deployment]
144
-
== 3. Set up CircleCI Deployment
161
+
== 3. Set up CircleCI deployment
162
+
163
+
To set up CircleCI deployment, you will need to take a few security measures.
164
+
165
+
[#convert-keystore-to-base64]
166
+
=== a. Convert your keystore to base64
167
+
168
+
You need to convert your keystore to base64 to safely access it in CircleCI. You can do this conversion in the terminal using the following command:
145
169
146
-
. You need to convert your keystore to base64 to safely access it in CircleCI. You can do this conversion in the terminal using the following command:
147
-
+
148
170
```shell
149
171
$ base64 your_key_store
150
172
```
151
-
+
173
+
152
174
Save the output somewhere easily accessible for the next step.
153
175
154
-
. Next, you need to set <<env-vars#,environment variables>> for deployment through CircleCI.
155
-
+
176
+
[#set-env-vars]
177
+
=== b. Set environment variables
178
+
179
+
Next, you need to set xref:env-vars#[environment variables] for deployment through CircleCI.
180
+
156
181
Open your Android project in the link:https://app.circleci.com/[CircleCI web app] and select *Project Settings*. Navigate to *Environment Variables* and add the following variables:
157
-
+
182
+
158
183
- `$BASE64_KEYSTORE` - Your base64 keystore, generated in the previous step
159
-
+
160
184
- `$GOOGLE_PLAY_KEY` - The contents of your `api.json` file, generated from the Fastlane install before starting this tutorial
161
-
+
162
185
- `$RELEASE_KEY_ALIAS` - Your key alias
163
-
+
164
186
- `$RELEASE_KEY_PASSWORD` - Your key password
165
-
+
166
187
- `$RELEASE_STORE_PASSWORD` - Your keystore password
167
188
168
-
. Add the following snippet to your `build.gradle` file. This allows you to import your keystore properties from a `keystore.properties` that will be generated at runtime.
169
-
+
189
+
[#import-keystore-properties]
190
+
=== c. Import keystore properties
191
+
192
+
Add the following snippet to your `build.gradle` file. This allows you to import your keystore properties from a `keystore.properties` that will be generated at runtime.
You can also create a `keystore.properties` file in your project directory for local bundling and deployment, if you wish. Do *not* push this file or your keystore to a remote repository.
@@ -196,12 +220,12 @@ Now, you need to configure `.circleci/config.yml` to decrypt your keystore, gene
196
220
If you have not already done so, create a `.circleci` folder in the root of your project repository. Inside the `.circleci` folder, create a `config.yml` file.
197
221
198
222
[#set-up-config-with-the-android-orb]
199
-
== 4a. Set up config with the Android orb
223
+
== 4a. Set up configuration with the Android orb
200
224
201
-
Using the Android orb gives you two options for deploying to the Google Play Store. You can either use the deploy-to-play-store job from the orb, or run each command individually in a job.
225
+
Using the Android orb gives you two options for deploying to the Google Play Store. You can either use the `deploy-to-play-store` job from the orb, or run each command individually in a job.
202
226
203
227
[#use-the-deploy-to-play-store-job]
204
-
=== i. Use the deploy-to-play-store job
228
+
=== a. Use the deploy-to-play-store job
205
229
206
230
To deploy using the deploy-to-play-store job you just need to add a `android/deploy-to-play-store` job to your list of jobs in your workflow.
207
231
@@ -234,10 +258,10 @@ workflows:
234
258
fastlane-working-directory: '.'
235
259
```
236
260
237
-
NOTE: The executor has no default value and must be set in the config.
261
+
NOTE: The executor has no default value and must be set in the configuration.
238
262
239
263
[#run-each-command-individually]
240
-
=== ii. Run each command individually
264
+
=== b. Run each command individually
241
265
242
266
To run each command individually in your workflow, you will need to add the following commands:
243
267
@@ -250,7 +274,7 @@ Additionally, you need to run either `npm install` or `yarn install` using the N
250
274
251
275
As with the deploy-to-play-store approach, you will not need to set the parameters `base64-keystore`, `release-key-alias`, `release-key-password`, `release-store-password`, and `google-play-key`, if you had created environment variables as outlined earlier in this tutorial.
252
276
253
-
Below is an example config of this approach:
277
+
Below is an example configuration of this approach:
254
278
255
279
```yaml
256
280
orbs:
@@ -281,57 +305,70 @@ jobs:
281
305
lane-name: internal
282
306
```
283
307
[#set-up-config-without-the-android-orb]
284
-
== 4b. Set up config without the Android Orb
308
+
== 4b. Set up configuration without the Android orb
309
+
310
+
If you would prefer to not use the Android orb, you can follow the configuration directions below.
311
+
312
+
[#decrypt-keystore]
313
+
=== a. Decrypt keystore from base64
314
+
315
+
Add the following command to your deployment job in `.circleci/config.yml` to decrypt your keystore from the base64 environment variable set earlier (`$BASE64_KEYSTORE`).
285
316
286
-
. Add the following command to your deployment job in `.circleci/config.yml` to decrypt your keystore from the base64 environment variable set earlier (`$BASE64_KEYSTORE`).
. Finally, you need to create your Google Play API key from your `api.json` You have already saved the value with an environment variable `$GOOGLE_PLAY_KEY`, so you can refer to this variable and write the api.json file at runtime, instead of uploading it to a remote repository.
308
-
+
339
+
[#create-google-play-api-key]
340
+
=== c. Create Google Play API key
341
+
342
+
Finally, you need to create your Google Play API key from your `api.json` You have already saved the value with an environment variable `$GOOGLE_PLAY_KEY`, so you can refer to this variable and write the api.json file at runtime, instead of uploading it to a remote repository.
. To now deploy your app, you need to add your fastlane steps. To do this you only need to add a command that runs `fastlane my_deployment_lane`; in this case, the command looks like this:
318
-
+
352
+
[#deploy-app]
353
+
=== d. Deploy your app
354
+
355
+
To now deploy your app, you need to add your Fastlane steps. To do this you only need to add a command that runs `fastlane my_deployment_lane`; in this case, the command looks like this:
356
+
319
357
```yaml
320
358
run: fastlane playstore
321
359
```
322
-
+
360
+
323
361
NOTE: You may need to install Fastlane on the image you are running your pipeline on. To do this, run `sudo gem install fastlane`.
324
-
+
362
+
325
363
Fastlane recommends using Bundler in this step. If you choose to use Bundler, you will need to add another step to install Bundler:
326
-
+
364
+
327
365
```
328
366
run: sudo gem install fastlane
329
367
```
330
-
+
368
+
331
369
Then, replace the `run: fastlane playstore` step with `run: bundle exec fastlane playstore`.
332
370
333
371
[#next-steps]
334
372
== Next steps
335
373
336
-
- A <<deploy-ios-applications#,guide to deploying iOS apps>> is also available.
337
-
- Visit the xref:deployment-overview.adoc[Deployment overview] for a general introduction on deployment with CircleCI, as well as examples for specific deployment targets such as Google Cloud Platform, AWS, and Heroku.
Copy file name to clipboardExpand all lines: jekyll/_cci2/deploy-ios-applications.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -341,7 +341,7 @@ Once this is complete you will need to generate an API token to allow Fastlane t
341
341
5. Go to your project settings in CircleCI and create a new environment variable named `VS_API_TOKEN` with the value of the API Key.
342
342
343
343
### 3. Fastlane configuration
344
-
{: #fastlane-configuration }
344
+
{: #fastlane-configuration-vs-app }
345
345
346
346
Below is an example of a lane that distributes beta app builds to Visual Studio App Center. Both the username of your App Center account and an API Token with "Full Access" is required to upload the binary to App Center.
347
347
@@ -387,7 +387,7 @@ end
387
387
2. On the Preferences page, go to the API Key section and copy your API Key.
388
388
3. Go to your project settings in CircleCI and create a new environment variable named `TESTFAIRY_API_KEY` with the value of the API Key
389
389
390
-
### 1. Fastlane configuration
390
+
### Fastlane configuration
391
391
{: #fastlane-configuration }
392
392
393
393
To configure uploading to TestFairy within Fastlane, see the following example:
0 commit comments