GitLab CI를 사용한 자동 안드로이드 빌드
CI/CD를 설정하는 Capacitor 앱에 대한 모든 것을 알아보세요.
준비물
시작하기 전에 다음을 설정해야 합니다.
- A GitLab 계정에 관리자 권한이 있습니다.
- Google Play Store에 이미 올려져 있는 올바른 서명이 있는 앱이 있습니다.
- Android 서명 키 및 키 스토어 파일이 있습니다.
- Google Cloud Console 프로젝트에 Play Store API이 활성화되어 있습니다.
- 서비스 계정에 적절한 권한이 있습니다.
- GitLab CI/CD 워크플로우를 이해합니다.
- Fastlane 구성에 대한 지식이 있습니다.
- pipeline 유지 및 디버깅에 필요한 시간이 있습니다.
Capgo CI/CD에 의해 Capgo로 빌드합니다.
Fastlane, Gradle 런너, 키 스토어, 업로드 스크립트 유지 관리를 생략합니다. Capgo 빌드 __CAPGO_KEEP_0__ CI/CD pipeline에서 이미 존재하는 빌드 파이프라인에서 서명된 네이티브 Android 빌드를 실행합니다.
- 자동 빌드와 함께 작동합니다.: GitLab CI, Capgo Actions, Jenkins, 또는 로컬 스크립트에서 웹 빌드 후에 GitHub 빌드를 트리거합니다.
npx cap sync. - CI 비밀에서 서명합니다.: Android 키 스토어, 키 별칭, 비밀번호, 및 Play Console 서비스 계정 JSON을 CI 비밀에서 유지합니다.
- 자연어 런너 유지 관리가 필요하지 않습니다.: Capgo 빌드는 유지 관리가 필요한 Android 빌드 환경을 제공하므로 SDK 이미지를 관리하거나 Gradle 캐시 문제, 또는 Fastlane 레인과 같은 문제를 해결할 필요가 없습니다.
- 아티팩트 및 제출: QA를 위해 서명된 아티팩트를 다운로드하거나 Capgo CLI를 통해 릴리스 빌드를 제출할 수 있습니다.
가격
- : Capgo 계획은 $12/월부터 시작됩니다.
- : OTA 업데이트와 약 15개의 네이티브 빌드가 포함됩니다.
- : 추가 빌드 분량은 분당 크레딧으로 청구됩니다.
수동 설정 안내서
다음과 같은 단계를 수행해야 합니다.
이 포스트에서 따르는 단계
- Fastlane 파일 복사
- GitLab 암호화된 비밀 저장
- Google Play 서비스 계정 키 생성 및 저장
- Android 서명 키 저장
- GitLab 워크플로우 (.yml) 설정
1. Fastlane 파일 복사
Fastlane은 안드로이드 모바일 개발을 자동화하는 루비 라이브러리입니다. Fastlane을 사용하면 안드로이드 스튜디오에서 수행하는 일반적인 작업을 자동화할 수 있습니다. Fastlane을 사용하면 사용자 정의 '로드'을 구성할 수 있으며, 이 로드에는 '액션'이 포함되어 있습니다. 액션은 일반적으로 안드로이드 스튜디오에서 수행하는 작업을 수행합니다. Fastlane은 많은 기능을 제공하지만, 이 튜토리얼에서는 Fastlane의 핵심 액션만 사용할 것입니다.
프로젝트의 루트 폴더에 Fastlane 폴더를 생성하고 다음 파일을 복사하세요: Fastlane
default_platform(:android)
KEYSTORE_KEY_ALIAS = ENV["KEYSTORE_KEY_ALIAS"]
KEYSTORE_KEY_PASSWORD = ENV["KEYSTORE_KEY_PASSWORD"]
KEYSTORE_STORE_PASSWORD = ENV["KEYSTORE_STORE_PASSWORD"]
platform :android do
desc "Deploy a beta version to the Google Play"
private_lane :verify_changelog_exists do |version_code: |
changelog_path = "android/metadata/en-US/changelogs/#{version_code}.txt"
UI.user_error!("Missing changelog file at #{changelog_path}") unless File.exist?(changelog_path)
UI.message("Changelog exists for version code #{version_code}")
end
private_lane :verify_upload_to_staging do |version_name: |
UI.message "Skipping staging verification step"
end
lane :beta do
keystore_path = "#{Dir.tmpdir}/build_keystore.keystore"
File.write(keystore_path, Base64.decode64(ENV['ANDROID_KEYSTORE_FILE']))
json_key_data = Base64.decode64(ENV['PLAY_CONFIG_JSON'])
previous_build_number = google_play_track_version_codes(
package_name: ENV['DEVELOPER_PACKAGE_NAME'],
track: "internal",
json_key_data: json_key_data,
)[0]
current_build_number = previous_build_number + 1
sh("export NEW_BUILD_NUMBER=#{current_build_number}")
gradle(
task: "clean bundleRelease",
project_dir: 'android/',
print_command: false,
properties: {
"android.injected.signing.store.file" => "#{keystore_path}",
"android.injected.signing.store.password" => "#{KEYSTORE_STORE_PASSWORD}",
"android.injected.signing.key.alias" => "#{KEYSTORE_KEY_ALIAS}",
"android.injected.signing.key.password" => "#{KEYSTORE_KEY_PASSWORD}",
'versionCode' => current_build_number
})
upload_to_play_store(
package_name: ENV['DEVELOPER_PACKAGE_NAME'],
json_key_data: json_key_data,
track: 'internal',
release_status: 'completed',
skip_upload_metadata: true,
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
)
end
lane :build do
gradle(
task: "clean bundleRelease",
project_dir: 'android/',
print_command: false,
properties: {
"android.injected.signing.store.file" => "#{keystore_path}",
"android.injected.signing.store.password" => "#{KEYSTORE_STORE_PASSWORD}",
"android.injected.signing.key.alias" => "#{KEYSTORE_KEY_ALIAS}",
"android.injected.signing.key.password" => "#{KEYSTORE_KEY_PASSWORD}",
})
end
lane :prod_release do
build_gradle = File.read("../android/app/build.gradle")
verify_changelog_exists(version_code: build_gradle.match(/versionCode (\d+)/)[1])
verify_upload_to_staging(version_name: build_gradle.match(/versionName '([\d\.]+)'/)[1])
supply(
track_promote_to: 'beta',
skip_upload_apk: true,
skip_upload_aab: true,
skip_upload_metadata: false,
skip_upload_changelogs: false,
skip_upload_images: false,
skip_upload_screenshots: false
)
end
end
비밀을 GitLab CI/CD 변수에 저장하세요
GitLab은 CI/CD 변수를 암호화하여 저장하는 방법을 제공합니다. 이는 GitHub의 저장소 비밀과 유사합니다._sensitive 정보를 안전하게 저장하려면
- GitLab 프로젝트의 설정으로 이동하세요
- CI/CD > 변수로 이동하세요
- 다음 변수를 추가하세요
- ANDROID_KEYSTORE_FILE: base64 인코딩된
.jks또는.keystoreAndroid 빌드에 사용되는 키스토어 파일입니다. Play App Signing을 사용하는 경우 업로드 키와 관련된 키스토어 파일이거나 앱 서명 키가 될 수 있습니다. - KEYSTORE_KEY_PASSWORD: 키스토어 파일과 관련된 암호
- KEYSTORE_KEY_ALIAS: 키스토어 별칭
- KEYSTORE_STORE_PASSWORD: 개인 키 암호
- DEVELOPER_PACKAGE_NAME: Android 앱 ID와 유사한 com.example.app
- PLAY_CONFIG_JSON: Google Play 서비스 계정 키 JSON을 base64로 인코딩한 것입니다.
Google Play 서비스 계정 키를 생성하는 방법
secret을 생성하려면 다음 단계를 따르세요: PLAY_CONFIG_JSON Google Cloud Console로 이동하세요.
- 새로운 프로젝트를 생성하거나 기존 프로젝트를 선택하세요. Google Play Android Developer를 활성화하세요.
- 서비스 계정 생성:
- Enable the Google Play Android Developer API
- ‘서비스 계정 생성’ 버튼을 클릭하세요.
- 이름과 설명을 입력하세요.
- __CAPGO_KEEP_0__
- Give it a name and description
- Click “Create and Continue”
- 역할 assign 할 필요 없이 "완료" 버튼을 클릭하세요.
- JSON 키 생성:
- 서비스 계정 목록에서 서비스 계정을 찾으세요.
- 세개의 점 메뉴를 클릭하세요 > "키 관리"
- Click “새 키 추가” > “새 키 생성”
- JSON 형식 선택
- 프로젝트를 생성하세요
- 플레이 콘솔에서 앱에 서비스 계정에 대한 접근 권한을 부여하십시오.
- 자동으로 생성된 Capacitor Android 빌드 GitLab으로 이동하세요. Play Console
- 사용자 및 권한으로 이동하세요
- Click "새로운 사용자 초대"
- 서비스 계정 이메일 (*.iam.gserviceaccount.com로 끝나야 함)을 입력하세요
- "제품 출시" 권한 부여
- 사용자 초대
- JSON 키를 base64로 변환하세요:
base64 -i path/to/your/service-account-key.json | pbcopy - GitLab에 base64로 인코딩된 문자열을 추가하세요
PLAY_CONFIG_JSONGitLab CI/CD Pipeline 설정
프로젝트 루트에 .gitlab-ci.yml 파일을 생성하여 CI/CD pipeline을 정의하세요. 아래는 pipeline 구조 예시입니다.
pipeline 실행
image: mingc/android-build-box:latest
stages:
- build
- upload_to_capgo
- build_and_upload_android
build:
stage: build
tags:
- saas-linux-xlarge-amd64
cache:
- key:
files:
- bun.lockb
paths:
- .node_modules/
script:
- npm install
- npm run build
artifacts:
paths:
- node_modules/
- dist/
only:
- master
upload_to_capgo:
stage: upload_to_capgo
tags:
- saas-linux-xlarge-amd64
script:
- npx @capgo/cli@latest bundle upload -a $CAPGO_TOKEN -c dev
dependencies:
- build
when: manual
only:
- master
build_and_upload_android:
tags:
- saas-linux-xlarge-amd64
stage: build_and_upload_android
cache:
- key:
files:
- android/gradle/wrapper/gradle-wrapper.properties
paths:
- ~/.gradle/caches/
script:
- npx cap sync android
- npx cap copy android
- bundle exec fastlane android beta # We do create a tag for the build to trigger XCode cloud builds
dependencies:
- build
when: manual
only:
- master
GitLab 저장소에 새로운 태그를 푸시할 때마다 GitLab CI/CD는 정의된 pipeline을 실행하여 Android 앱을 Fastlane을 통해 빌드 및 배포합니다.
프로젝트 구조 및 요구 사항에 따라 경로 및 의존성을 조정하세요. 이 설정은 GitLab CI/CD를 통해 Android 앱의 자동 배포를 지원합니다.
Create a .gitlab-ci.yml file at the root of your project to define your CI/CD pipeline. Below is an example of how you can structure your pipeline:
결론
GitLab CI/CD를 mingc/android-build-box Docker 이미지를 구성하여 Android 앱 빌드 프로세스를 자동화할 수 있습니다. 이 자동화는 개발 워크플로우의 효율성과 신뢰성을 향상시켜 개발자가 앱 개발의 핵심 부분에 집중할 수 있도록 시간을 절약합니다. 또한 개발자가 더 효율적으로 고품질의 Android 앱을 출시할 수 있도록 도와줍니다.
GitLab에서 Capacitor Android 빌드를 자동화하세요
__CAPGO_KEEP_0__ GitLab을 사용 중이라면 Capacitor GitLab을 사용하여 CI/CD 자동화를 계획하고 Capacitor CI/CD와 연결하세요. __CAPGO_KEEP_0__ CI/CD에서 __CAPGO_KEEP_0__ CI/CD 제품 워크플로우를 관리하세요. Capgo Native Builds에서 Capgo Native Builds 제품 워크플로우를 관리하세요. Capgo Integrations에서 Capgo Integrations 제품 워크플로우를 관리하세요. Capgo Integrations Capgo Integrations에서 제품 워크플로우를 관리하세요. Capgo Integrations Capgo Integrations CI/CD 연동 CI/CD 연동 구현 세부 사항에 대해 GitHub 액션 연동 for the implementation detail in GitHub Actions Integration.