5
3

More than 3 years have passed since last update.

Flutterで作ったAndroidアプリをFirebaseで配布する

Posted at

目次

  1. アプリをビルドする
    1. 事前準備
    2. APKのビルド
  2. APKファイルをFirebaseコンソールから配布

参考

事前準備

1. build.gradleの変更

buildTypes {
  debug {
    resValue "string", "app_name", "(d)アプリ名"
    applicationIdSuffix ".debug"
    versionNameSuffix "-d"
  }
  release {
    resValue "string", "app_name", "アプリ名"
  }
}

2. マニフェストファイル変更

// AndroidManifest.xml

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher">

3. アプリアイコンの作成

// pubspec.yml
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_launcher_icons: "^0.8.0"

flutter_icons:
  ios: true
  android: true
  image_path: "assets/icon/launch_icon.png"
  • パッケージを実行
$ flutter pub get
$ flutter pub run flutter_launcher_icons:main
  • ファイルが生成される
    • android/app/src/main/res
    • ios/Runner/Assets.xcassets/AppIcon.appiconset

APKのビルド

1. アップロード鍵の用意(証明書の作成)

Image from Gyazo

  • 作成したkeyを android/app 下に配置する

2. 署名情報ファイルを作成

android/直下にkeystore.propertiesファイルを作成する

keystore.properties
storePassword=パスワード
keyPassword=パスワード
keyAlias=alias_name
storeFile=release.jks

3. build.gradleを編集

// 追加する
def keystorePropertiesFile = rootProject.file("keystore.properties") 

android{
   ...

    defaultConfig {
        ...
    }

    signingConfigs {
        release {
            if (keystorePropertiesFile.exists()) {
                def keystoreProperties = new Properties()
                keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            }
        }
    }

    buildTypes {
        debug {
            ...
        }
        release {
            resValue "string", "app_name", "アプリ名"

            // 以下を追加
            signingConfig signingConfigs.release
            // 追加ここまで
        }
    }
 ...
}

4. .gitignoreに追加

# Android key
*.jks
keystore.properties

5. APKビルド

$ flutter build apk

# main.dartを変えたい場合
$ flutter build apk --target lib/main_production.dart

APKファイルをFirebaseコンソールから配布

  1. Firebaseコンソールに接続
  2. (なければ)Androidアプリを登録(applicationIdが必要)
  3. AppDistribution > APKドラッグ&ドロップ > 配布

結び

  • Androidを配布&公開したことがなかったので知らないことが多かったです
  • ただ思っていたよりも記事も多かったのでサクサク進みました。皆々様に感謝。
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3