目次
- アプリをビルドする
- 事前準備
- APKのビルド
- 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. アプリアイコンの作成
- flutter_launcher_icons パッケージを利用する
// 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. アップロード鍵の用意(証明書の作成)
- 作成した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コンソールから配布
- Firebaseコンソールに接続
- (なければ)Androidアプリを登録(applicationIdが必要)
- AppDistribution > APKドラッグ&ドロップ > 配布
結び
- Androidを配布&公開したことがなかったので知らないことが多かったです
- ただ思っていたよりも記事も多かったのでサクサク進みました。皆々様に感謝。