facebook twitter hatena line email

Flutter/開発環境構築/共通

提供: 初心者エンジニアの簡易メモ
2019年11月13日 (水) 18:18時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「 ==AndroidStudioのインストール== https://developer.android.com/studio/install?hl=ja ==AndroidStudioのプラグインインストール== AndroidStudio/Preference...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

AndroidStudioのインストール

https://developer.android.com/studio/install?hl=ja

AndroidStudioのプラグインインストール

AndroidStudio/Preference/PluginsからFlutter、Dartを検索してインストール

プロジェクト作成

File/New Flutter Project がFile/New Projectの下に表示されるはずなので、そこから作成。

"New Flutter Project"が出ない場合は以下コマンドでプロジェクトを作ってAndroidStudioで開けば良い。

flutter create my_app
cd my_app
flutter run

gitignore

https://github.com/flutter/flutter/blob/master/.gitignore ここからコピーする

ios実行準備

xcode-select --install
brew update
sudo gem install cocoapods
sudo gem install -n /usr/local/bin cocoapods
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy

android・ios実行

  • 上部中央に実行ボタンがあるので、そこから実行できる。
  • 接続したandroid・iPhoneの端末が表示される
  • 基本hotreloadで2秒で更新が反映される。

androidのapk作成&インストール

flutter build apk
flutter install #これはアンインストール後にインストールされるので直で実行した端末のprefなどは消える。

↑はリリースビルドで、リリースビルドのときはデバッグビルド(1秒程度)と比べて起動速度が速い。

build/app/outputs/apk/release/app-release.apk

iosのipaファイル作成&インストール

flutter build ios
flutter install  #これはアンインストール後にインストールされるので直で実行した端末のprefなどは消える。

androidパッケージ名変更

  • android/app/src/main/AndroidManifest.xml
  • android/app/build.gradle
  • android/app/src/profile/AndroidManifest.xml
  • android/app/src/debug/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example1.hoge">
  • android/app/src/main/com/example1/hoge/MainActivity.java
package com.example1.hoge; 

2箇所変更とMainActivity.javaのdir変更

iosのbundleId変更

  • ios/Runner.xcodeprojを開いてbundleIdを変更する
  • podを使っていれば、コンソールでiosの下で、"pod update"を実行後ios/Runner.xcworkspaceを開いてbundleIdを変更する

iosで以下エラーが出るとき

flutter clang: error: linker command failed with exit code 1 (use -v to see invocation)

以下実行

$ flutter clean

参考:https://stackoverflow.com/questions/49612211/codesign-error-with-flutter-on-ios

androidのkeystore付きapk作成

  1. keystoreを作っておく
  2. android/key.properties を作成
storePassword=パスを入れる
keyPassword=パスを入れる
keyAlias=key
storeFile=keystoreのパスを入れる・・・key.jks
  1. android/app/build.gradle を追加する
+def keystorePropertiesFile = rootProject.file("key.properties")
+def keystoreProperties = new Properties()
+keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
  1. android/app/build.gradle の部分を修正
-buildTypes {
-    release {
-        // TODO: Add your own signing config for the release build.
-        // Signing with the debug keys for now, so `flutter run --release` works.
-        signingConfig signingConfigs.debug
-    }
-}
+signingConfigs {
+    release {
+        keyAlias keystoreProperties['keyAlias']
+        keyPassword keystoreProperties['keyPassword']
+        storeFile file(keystoreProperties['storeFile'])
+        storePassword keystoreProperties['storePassword']
+    }
+}
+buildTypes {
+    release {
+        signingConfig signingConfigs.release
+    }
+}

参考:https://qiita.com/rkowase/items/f1012ef0738791dd6084

Androidで64 ビット要件に準拠していませんが表示された場合

このリリースは Google Play の 64 ビット要件に準拠していません

flutter build apk --release --target-platform=android-arm64

もしくは、

build.gradle

buildTypes {
      release {
            ndk{
                   abiFilters "x86", "arm64-v8a", "android-arm64"
            }
       }
}

参考:https://github.com/flutter/flutter/issues/18494

ビルドは成功するが起動時に落ちてcouldn't find "libflutter.so"エラーが出る場合

上の項目のndkにabiFiltersが追加されてるかを確認

$ flutter build apk --release

releaseをつけてapkを作成する

abiFiltersで指定したものの確認

$ flutter build apk --release

apkをunzipで解凍して確認

unzip build/app/outputs/apk/release/app-release.apk
ls lib/arm64-v8a/libflutter.so
ls lib/armeabi-v7a/libflutter.so

参考:https://qiita.com/mkosuke/items/afa40c09078285034799

Androidのversion記述場所

pubspec.yaml

version: 1.0.1+2
$ flutter build apk

以下ファイルが以下の通り出力されればよい。

android/local.properties

flutter.versionName=1.0.1
flutter.versionCode=2

公式androidの64bit対応方法

https://developer.android.com/distribute/best-practices/develop/64-bit

64bit対応済み判定

  1. androidStudioでBuild/ApkAnalyzeでapkファイルを指定
  2. libの下に以下dirがあれば良い。
arm64-v8a
x86_64

"このリリースは Google Play の 64 ビット要件に準拠していません"が出る場合

flutter upgrade
flutter --version

Flutterのバージョンを1.7以上へ

https://algorithm.joho.info/flutter/flutter-erroe-google-play-64bit/

androidのaab対応

flutterの1.7でaab対応

flutter upgrade
flutter --version

apkからappbundleにするだけ

flutter build apk --release

flutter build appbundle --release

aabの出力先は build/app/outputs/bundle/release/app.aab

androidxの対応

build時に以下のような警告が出る。

[!] Your app isn't using AndroidX.
    To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.

pubspec.yamlの一番下のflutter:の下に追加

flutter:
  module:
    androidX: true
    androidPackage: com.example.hogehoge
    iosBundleIdentifier: com.example.hogehoge

buildしてみたが、やっぱり警告は出る・・・。

以下でandroidx対応のプロジェクトは作れるようなので、差分を追う良いかも。

flutter create --androidx -t module my_flutter_androidx

↑これandroidx対応かどうかは怪しい・・(調べてない。