android fastlane 사용법
안드로이드는 gradle이라는 충분이 만족스러운 도구가 있어서 굳이 fastlane으로 빌드를 대체할 필요는 없다
하지만 appcenter,s3등으로 업로드 하기 위해선 fastlane의 도움을 받는것이 빠르고 좋다.
아래는 당사에서 진행하는 안드로이드의 fastlane 기본 템플릿이다.
1.fastlane init
➜ MyApplication fastlane init
[✔] 🚀
[✔] Looking for iOS and Android projects in current directory...
[13:19:22]: Created new folder './fastlane'.
[13:19:22]: Detected an Android project in the current directory...
[13:19:22]: -----------------------------
[13:19:22]: --- Welcome to fastlane 🚀 ---
[13:19:22]: -----------------------------
[13:19:22]: fastlane can help you with all kinds of automation for your mobile app
[13:19:22]: We recommend automating one task first, and then gradually automating more over time
[13:19:22]:
[13:19:22]: To avoid re-entering your package name and issuer every time you run fastlane, we'll store those in a so-called Appfile.
[13:19:22]: Package Name (com.krausefx.app): com.mintsoft.android
To automatically upload builds and metadata to Google Play, fastlane needs a service account json secret file
Follow the Setup Guide on how to get the Json file: https://docs.fastlane.tools/actions/supply/
Feel free to press Enter at any time in order to skip providing pieces of information when asked
[13:20:15]: Path to the json secret file:
[13:20:25]:
[13:20:25]: Do you plan on uploading metadata, screenshots, and builds to Google Play using fastlane?
[13:20:25]: We will now download your existing metadata and screenshots into the `fastlane` folder so fastlane can manage it
[13:20:25]: Download existing metadata and setup metadata management? (y/n)
n
[13:20:28]: You can run `fastlane supply init` to set up metadata management at a later point.
[13:20:28]: Installing dependencies for you...
[13:20:28]: $ bundle update
[13:20:55]: --------------------------------------------------------
[13:20:55]: --- ✅ Successfully generated fastlane configuration ---
[13:20:55]: --------------------------------------------------------
[13:20:55]: Generated Fastfile at path `./fastlane/Fastfile`
[13:20:55]: Generated Appfile at path `./fastlane/Appfile`
[13:20:55]: Gemfile and Gemfile.lock at path `Gemfile`
[13:20:55]: Please check the newly generated configuration files into git along with your project
[13:20:55]: This way everyone in your team can benefit from your fastlane setup
[13:20:55]: Continue by pressing Enter ⏎
[13:21:12]: fastlane will collect the number of errors for each action to detect integration issues
[13:21:12]: No sensitive/private information will be uploaded, more information: https://docs.fastlane.tools/#metrics
[13:21:12]: ----------------------
[13:21:12]: --- fastlane lanes ---
[13:21:12]: ----------------------
[13:21:12]: fastlane uses a `Fastfile` to store the automation configuration
[13:21:12]: Within that, you'll see different lanes.
[13:21:12]: Each is there to automate a different task, like screenshots, code signing, or pushing new releases
[13:21:12]: Continue by pressing Enter ⏎
[13:21:13]: --------------------------------------
[13:21:13]: --- How to customize your Fastfile ---
[13:21:13]: --------------------------------------
[13:21:13]: Use a text editor of your choice to open the newly created Fastfile and take a look
[13:21:13]: You can now edit the available lanes and actions to customize the setup to fit your needs
[13:21:13]: To get a list of all the available actions, open https://docs.fastlane.tools/actions
[13:21:13]: Continue by pressing Enter ⏎
[13:21:14]: ------------------------------
[13:21:14]: --- Where to go from here? ---
[13:21:14]: ------------------------------
[13:21:14]: 📸 Learn more about how to automatically generate localized Google Play screenshots:
[13:21:14]: https://docs.fastlane.tools/getting-started/android/screenshots/
[13:21:14]: 👩✈️ Learn more about distribution to beta testing services:
[13:21:14]: https://docs.fastlane.tools/getting-started/android/beta-deployment/
[13:21:14]: 🚀 Learn more about how to automate the Google Play release process:
[13:21:14]: https://docs.fastlane.tools/getting-started/android/release-deployment/
[13:21:14]:
[13:21:14]: To try your new fastlane setup, just enter and run
[13:21:14]: $ fastlane test
2.appcenter 플러그인 생성
MyApplication fastlane add_plugin appcenter
[✔] 🚀
[13:24:35]: fastlane detected a Gemfile in the current directory
[13:24:35]: However, it seems like you didn't use `bundle exec`
[13:24:35]: To launch fastlane faster, please use
[13:24:35]:
[13:24:35]: $ bundle exec fastlane add_plugin appcenter
[13:24:35]:
[13:24:35]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[13:24:37]: Plugin 'fastlane-plugin-appcenter' was added to './fastlane/Pluginfile'
[13:24:37]: It looks like fastlane plugins are not yet set up for this project.
[13:24:37]: fastlane will modify your existing Gemfile at path '/Users/choiks14/Workspace/MyApplication/Gemfile'
[13:24:37]: This change is necessary for fastlane plugins to work
[13:24:37]: Should fastlane modify the Gemfile at path '/Users/choiks14/Workspace/MyApplication/Gemfile' for you? (y/n)
y
[13:25:07]: Successfully modified '/Users/choiks14/Workspace/MyApplication/Gemfile'
[13:25:07]: Make sure to commit your Gemfile, Gemfile.lock and Pluginfile to version control
Installing plugin dependencies...
Successfully installed plugins
위의 플러그인을 추가할때 Gemfile을 Plugin으로 구분할것인지 물어보는데 y를 눌러서 fastlane 디렉터리 안의 Pluginfile로 플러그인이 추가된다.
3.s3 플러그인 추가
MyApplication fastlane add_plugin aws_s3
[✔] 🚀
[13:27:43]: fastlane detected a Gemfile in the current directory
[13:27:43]: However, it seems like you didn't use `bundle exec`
[13:27:43]: To launch fastlane faster, please use
[13:27:43]:
[13:27:43]: $ bundle exec fastlane add_plugin aws_s3
[13:27:43]:
[13:27:43]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
+---------------------------+---------+-------------------------------------------------------------+
| Used plugins |
+---------------------------+---------+-------------------------------------------------------------+
| Plugin | Version | Action |
+---------------------------+---------+-------------------------------------------------------------+
| fastlane-plugin-appcenter | 2.0.0 | appcenter_codepush_release_react, appcenter_fetch_devices, |
| | | appcenter_fetch_version_number, appcenter_upload |
+---------------------------+---------+-------------------------------------------------------------+
[13:27:44]: Plugin 'fastlane-plugin-aws_s3' was added to './fastlane/Pluginfile'
[13:27:44]: Make sure to commit your Gemfile, Gemfile.lock and Pluginfile to version control
Installing plugin dependencies...
Successfully installed plugins
4.fastfile을 열어서 아래와 같이 편집하자.
(1).appcenter apk 파일을 릴리즈 빌드를 하여 appcenter.ms에 업로드 하는 기능이다.
(2).release 빌드는 aab 빌드를 진행하여 aws의 s3로 업로든 하는 기능이다.
개발자는 s3로 업로드 된 aab 파일을 다운로드 받아서 플레이 스토어에 업로드 하면 된다.
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
update_fastlane
default_platform(:android)
platform :android do
# slack message
def send_slack(url,message)
slack(
slack_url: url,
message: message,
success: true,
payload: {
"Build Date" => Time.new.to_s,
},
default_payloads: [:git_branch, :git_author, :last_git_commit]
)
end
lane :appcenter do
version = android_get_version_code
versionName = android_get_version_name
slack = "slack_incomming_webhook_url"
send_slack(slack,"앱센터 빌드를 시작합니다.(BETA).\nversion:#{versionName},build_number:#{version}")
gradle(task: "clean assembleRelease")
appcenter_upload(
api_token: "appcenter_api_key",
owner_name: "owner",
owner_type: "organization",
app_name: "appname",
file: "app/build/outputs/apk/release/app-release.apk",
notify_testers: true
)
send_slack(slack,"앱센터 배포했습니다.\nversion:#{versionName},build_number:#{version}")
end
lane :release do
version = android_get_version_code
versionName = android_get_version_name
slack = "slack_incommint_webhook_url"
send_slack(slack,"배포 빌드를 시작합니다.(RELEASE).\nversion:#{versionName},build_number:#{version}")
gradle(task: "clean bundleRelease --refresh-dependencies")
aws_s3(
access_key: "access_key",
secret_access_key: "secret_access_key",
bucket: "bucket_name",
region: "ap-northeast-2",
acl: "public-read",
path: "#{versionName}/",
ipa: './app/build/outputs/bundle/release/app-release.aab',
upload_metadata: false,
)
message = "s3 업로드 하였습니다.플레이 스토어로 배포해주세요.\nversion:#{versionName},build_number:#{version}\n s3_url/#{versionName}/app-release.aab"
send_slack(slack,message)
end
end
github action,circleci,jenkins등을 사용하여 각 서비스에서 제공하는 기본 안드로이드 빌드툴을 사용하게 되면 서비스마다 코드를 재구현해야되는 번거로움이 있어서 fastlane을 통해서 사용하는게 좋다.
그렇게 되면 github action,circleci,jenkins 등을 자유자재로 이동할수 있어서 편리하다.
민트소프트는 모바일 앱 개발 전문회사입니다. 하이브리드앱,크로스플랫폼,네이티브영역 전반에 걸친 모바일 앱을 개발하고 있습니다.
하이브리드는 민트앱이라는 솔루션을 보유하고 있어서 Time To Market에 매우 유리합니다.
언제는 찾아주시면 신속하고 빠른 상담을 진행하도록 하겠습니다.