Commit 572bb826 authored by Gabriel Le Breton's avatar Gabriel Le Breton

Merge branch 'feature/fastlane-android' into 'master'

Feature/fastlane android

See merge request !34
parents 53cdf885 4205bb71
Pipeline #119983633 passed with stages
in 45 minutes
......@@ -99,6 +99,17 @@ build-android:
image: gableroux/unity3d:2019.2.11f1-android
variables:
BUILD_TARGET: Android
BUNDLE_VERSION_CODE: $CI_PIPELINE_IID
BUILD_APP_BUNDLE: "false"
#deploy-android:
# stage: deploy
# image: fastlanetools/fastlane
# script:
# - cd ./Builds/Android
# - echo $GPC_TOKEN > gpc_token.json
# - fastlane supply --aab $BUILD_NAME.aab --track internal --package_name com.youcompany.yourgame --json_key ./gpc_token.json
# needs: ["build-android"]
build-ios-xcode:
<<: *build
......
......@@ -10,6 +10,8 @@ static class BuildCommand
private const string KEY_ALIAS_NAME = "KEY_ALIAS_NAME";
private const string KEYSTORE = "keystore.keystore";
private const string BUILD_OPTIONS_ENV_VAR = "BuildOptions";
private const string ANDROID_BUNDLE_VERSION_CODE = "BUNDLE_VERSION_CODE";
private const string ANDROID_APP_BUNDLE = "BUILD_APP_BUNDLE";
static string GetArgument(string name)
{
......@@ -84,7 +86,11 @@ static class BuildCommand
if (buildTarget.ToString().ToLower().Contains("windows")) {
buildName += ".exe";
} else if (buildTarget == BuildTarget.Android && buildOptions == BuildOptions.None) {
#if UNITY_2018_3_OR_NEWER
buildName += EditorUserBuildSettings.buildAppBundle ? ".aab" : ".apk";
#else
buildName += ".apk";
#endif
}
return buildPath + buildName;
}
......@@ -143,6 +149,8 @@ static class BuildCommand
var buildTarget = GetBuildTarget();
if (buildTarget == BuildTarget.Android) {
HandleAndroidAppBundle();
HandleAndroidBundleVersionCode();
HandleAndroidKeystore();
}
......@@ -159,6 +167,41 @@ static class BuildCommand
Console.WriteLine(":: Done with build");
}
private static void HandleAndroidAppBundle()
{
if (TryGetEnv(ANDROID_APP_BUNDLE, out string value))
{
#if UNITY_2018_3_OR_NEWER
if (bool.TryParse(value, out bool buildAppBundle))
{
EditorUserBuildSettings.buildAppBundle = buildAppBundle;
Console.WriteLine($":: {ANDROID_APP_BUNDLE} env var detected, set buildAppBundle to {value}.");
}
else
{
Console.WriteLine($":: {ANDROID_APP_BUNDLE} env var detected but the value \"{value}\" is not a boolean.");
}
#else
Console.WriteLine($":: {ANDROID_APP_BUNDLE} env var detected but does not work with lower Unity version than 2018.3");
#endif
}
}
private static void HandleAndroidBundleVersionCode()
{
if (TryGetEnv(ANDROID_BUNDLE_VERSION_CODE, out string value))
{
if (int.TryParse(value, out int version))
{
PlayerSettings.Android.bundleVersionCode = version;
Console.WriteLine($":: {ANDROID_BUNDLE_VERSION_CODE} env var detected, set the bundle version code to {value}.");
}
else
Console.WriteLine($":: {ANDROID_BUNDLE_VERSION_CODE} env var detected but the version value \"{value}\" is not an integer.");
}
}
private static void HandleAndroidKeystore()
{
#if UNITY_2019_1_OR_NEWER
......
......@@ -47,6 +47,9 @@ This repository is hosted on multiple remotes to provide examples for [Gitlab-CI
- [Run tests locally](#run-tests-locally)
- [Gitlab-runner - register your mac](#gitlab-runner-register-your-mac)
- [Android support](#android-support)
- [Android app bundle](#android-app-bundle)
- [Bundle version code](#bundle-version-code)
- [Fastlane supply (deployement)](#fastlane-supply-deployement)
- [How to run scripts manually](#how-to-run-scripts-manually)
- [Test](#test)
- [Build](#build)
......@@ -432,6 +435,38 @@ Add following environment variables:
Note about _keystore security_, if you would like to use another solution for storage, see [HERE](https://android.jlelse.eu/where-to-store-android-keystore-file-in-ci-cd-cycle-2365f4e02e57).
#### Android app bundle
`BUILD_APP_BUNDLE` env var is defined in `gitlab-ci.yml`. Set it to `true` to build an `.aab` file.
Note: to build an android app bundle, you need an image with **Android NDK**. See [related issue gableroux/unity3d#61](https://gitlab.com/gableroux/unity3d/issues/61)
#### Bundle version code
The bundle version code must be increment for each deployed build.
To simplify the process, the `BUNDLE_VERSION_CODE` env var is used and set as bundle version code.
Currently, for gitlab, `BUNDLE_VERSION_CODE = $CI_PIPELINE_IID`. [Documentation](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
If you use another CI solution, set a CI env var incrementing for each pipeline.
#### Fastlane supply (deployement)
Follow [setup instructions](https://docs.fastlane.tools/actions/supply/) to get a google play console token, then, add the content to env var `GPC_TOKEN`.
Uncomment the `#deploy-android` job in gitlab-ci.yml and replace `com.youcompany.yourgame` by your package name.
You can change the track `internal` to `alpha`, `beta` or `production`.
That is the simplest way with command line but you can also make `fastlane/Fastfile` and `fastlane/Appfile`, with the following command after building a temporary gradle project (export gradle project option in Unity build settings):
```bash
fastlane init
```
Then run the following command:
```bash
fastlane supply init
```
and update all metadata, images, changelogs, etc... These will be uploaded to the store everytime. Refer to [fastlane supply documentation](https://docs.fastlane.tools/actions/supply/) for more details.
## How to run scripts manually
You can execute the local scripts and specify the path of your Unity executable using `UNITY_EXECUTABLE`. You may try this in your project before you setup the whole CI so you confirm it works with your current unity version :+1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment