如何自动化将全新公开Android应用上传至Google Play?
Great question—this is a common pain point for white-label app developers since Fastlane's Supply doesn't handle initial public app creation out of the box. Here's how you can automate the end-to-end workflow:
First, clarify: the Custom App API you referenced is for private apps only, but the standard Google Play Developer API supports creating new public apps via the Apps.insert endpoint. You can pair this with Fastlane to build a full automated pipeline.
Step 1: Set Up API Access
- Create a service account in your Google Cloud Project with either the
OwnerorApp Managerrole in the Google Play Console. - Download the service account's JSON key file and store it securely (e.g.,
play-store-key.jsonin your repo, or use environment variables to avoid hardcoding).
Step 2: Automate App Creation
Fastlane doesn't have a built-in action for creating new apps, so you have two straightforward options:
Option A: Custom Ruby Script in Fastlane
Add a lane that uses Google's official API client gem to call the Apps.insert endpoint:
lane :create_new_app do require 'google/apis/androidpublisher_v3' require 'googleauth' # Initialize the API client android_publisher = Google::Apis::AndroidpublisherV3::AndroidPublisherService.new android_publisher.authorization = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open("play-store-key.json"), scope: 'https://www.googleapis.com/auth/androidpublisher' ) # Define your app's core details app_details = Google::Apis::AndroidpublisherV3::App.new( title: "My New Public App", package_name: "com.example.mynewapp", default_language: "en-US" ) # Send the request to create the app response = android_publisher.insert_app(app_details) puts "App created successfully! Draft status confirmed: #{response.draft}" end
Option B: Use Fastlane's google_play_api Action
Fastlane's built-in google_play_api action lets you make direct API calls without writing full Ruby scripts:
lane :create_new_app do google_play_api( api_version: 'v3', endpoint: 'apps', http_method: 'post', params: { "title": "My New Public App", "packageName": "com.example.mynewapp", "defaultLanguage": "en-US" }, json_key: "play-store-key.json" ) end
Step 3: Upload Build & Metadata with Supply
Once the app is created (it may take 1-2 minutes for the Play Console to register it), use your standard Supply lane to push the AAB/APK and metadata:
lane :upload_to_play do supply( package_name: "com.example.mynewapp", json_key: "play-store-key.json", track: "internal", aab: "path/to/app-release.aab", metadata_path: "fastlane/metadata" ) end
Step 4: Chain Lanes for a Single Workflow
Combine the steps into one lane to run the full automation with a single command:
lane :deploy_new_app do create_new_app # Add a short delay to ensure the app is ready in the Play Console sleep(30) upload_to_play end
Key Notes
- Permissions: Double-check your service account has the right roles—without
App ManagerorOwner, the API will reject your app creation request. - Draft Status: The app starts in draft mode. You can automate moving it to public via the API's
tracks.updateendpoint once you're ready, or handle it manually after review. - Retry Logic: If you hit race conditions where Supply can't find the app immediately, add retry logic to the
upload_to_playlane instead of a fixed sleep.
内容的提问来源于stack exchange,提问作者omri tal




