###### tags: `android`, `firebase`, `bundle`, `AAB` # 如何上傳AAB 到 firebase 上 [TOC] ## 前言 google store 要強制使用者上傳AAB 格式, 期限在 `2021/8`. 因應這個政策, 原本Firebase Distribution也有相對應的改動, 可以上傳 AAB 了, 在此跟各位簡單介紹一下 <font style="color:#ff0000; font-size:20px; text-align:left;">如何上傳AAB 到 firebase 上</font> ## 正篇 大約可以分成幾個步驟: - Firebase connect to Google Play Sotre - 首次上傳AAB - 查看 test 憑證, 更新各平台hash key (如果需要的話) ### Firebase connect to Google Play Sotre :::info 請先確定你的`帳號` 是Firebase & Google Play Store 專案的擁有者 否則你會沒有權限執行以下操作, 或連結失敗 ::: 1. 進入專案後點擊 設定 -> 專案設定 ![](https://i.imgur.com/XzpgEOr.png) 2. 點選`整合`, 裡面會有大量的平台可以點選. 若你尚未連結過 Google Play 項目, 右下角會顯示`連結`, 點擊即可. :::success 若已連結過, Google Play 項目 右下角會顯示`管理`, 建議你可以點進去查看是否有什麼條款需要按接受. ::: ![](https://i.imgur.com/1oVGg6w.png) 3. 連結成功 ![](https://i.imgur.com/fm92NC2.png) :::warning :warning::warning::warning: 我們有多個專案 1. 其中一個專案明明連結成功, 但還是無法發布AAB. 後來我們斷開連結, 重新再連接一次就行了 給各位參考~ 2. 另外一個專案, 畫面上會需要點選同意條款, 點擊後即可. ::: ### Upload AAB - 網頁 將AAB拖曳到畫面上進行上傳. 如果上傳成功的話會有以下畫面: ![](https://i.imgur.com/v0Pv9hA.png) > :warning: 注意, 上傳AAB後, 會給play store 重新sign 一次, 因此憑證相關設定都需要再重設, 像是 > - Facebook > - Google Map 點選查看憑證 (Option) ![](https://i.imgur.com/vbw1NNA.png) ### Upload AAB - [使用 gradle 上傳](https://firebase.google.com/docs/app-distribution/android/distribute-gradle?apptype=aab) 1. [gradle setup](https://firebase.google.com/docs/app-distribution/android/distribute-gradle?apptype=aab#step_1_set_up_your_android_project) > (root) build.gradle ```groovy= buildscript { repositories { // Check that you have Google's Maven repository (if not, add it). google() jcenter() } dependencies { // Add the App Distribution Gradle plugin // 至少2.1.2 以上 classpath 'com.google.firebase:firebase-appdistribution-gradle:2.1.2' } } ``` > (app) build.gradle ```groovy= apply plugin: 'com.android.application' // ... // Apply the App Distribution Gradle plugin apply plugin: 'com.google.firebase.appdistribution' // ... ``` 2. [Authenticate With Firebase](https://firebase.google.com/docs/app-distribution/android/distribute-gradle?apptype=aab#step_2_authenticate_with_firebase) 3. [Configure your distribution](https://firebase.google.com/docs/app-distribution/android/distribute-gradle?apptype=aab#step_3_configure_your_distribution_properties) > (app) build.gradle ```groovy= android { // ... buildTypes { release { firebaseAppDistribution { artifactType="AAB" // 可填選 "APK" or "AAB" releaseNotesFile="/path/to/releasenotes.txt" testers="ali@example.com, bri@example.com, cal@example.com" } } } // ... } ``` 最後再下gradle 指令: ```coffeescript= ./gradlew bundleDebug appDistributionUploadDebug -PappDistribution-artifactType="AAB" # 一樣可選"AAB" or "APK" ``` 就大功告成拉~ :100: :fireworks: