LoginSignup
0

More than 3 years have passed since last update.

Flutterのtfliteを組み込んだサンプル(iOS)を動かす

Posted at

はじめに

Flutterを一年ぶりくらいに触ってほぼ初心者がmobilenetを使った学習データをつかうために利用したtfliteサンプルを動かす履歴です。
ハマりどころを覚えている限り残しており、抜けがあったらすみません。

環境

  • Mac(Mojave)
  • VSCode(1.43.1)
  • Xcode(11.3.1)

iOS開発者プログラムに無料版、有料版での登録が必要です。

VSCodeで新規プロジェクトをつくる前に

VSCodeでFlutterのプラグインで作る場合
スクリーンショット 2020-03-21 8.01.10.png

Objective-Cを指定します。swiftを指定だとエラーがでて、動作もおかしいアプリになりました。

そのため設定を変更し、ユーザータブで設定変更してますが、他でswiftを使う場合はワークスペースタブで指定して

スクリーンショット 2020-03-21 8.07.26.png

VSCodeで新規プロジェクト

https://github.com/shaqian/flutter_tflite#usage
より

assetsフォルダを作成

スクリーンショット 2020-03-21 8.22.59.png

サンプルにあるassetsのファイルを追加

スクリーンショット 2020-03-21 8.25.20.png

pubspec.yamlにassets,tfliteの記述を追加

スクリーンショット 2020-03-21 8.27.07.png
スクリーンショット 2020-03-21 8.27.15.png

lib/main.dart

丸コピーです
スクリーンショット 2020-03-21 8.30.40.png

Xcodeで修正

flutter build ios

などでpodまわりでのエラーが多発し、その対処をした結果次の手順になりました。

スクリーンショット 2020-03-21 8.42.31.png

Runner.xcworkspaceから起動します。

Signing & Capabilities

Teamには有料版でも無料版でもiOS開発者プログラムで発行されているものを指定します。
今回は無料版を設定しています(Personal Team)

スクリーンショット 2020-03-21 8.47.48.png

General

  • Bundle Identifier(任意)
  • Deployment target(iOS9以上に変更)

スクリーンショット 2020-03-21 8.47.23.png

出力されたエラー

  • DEPLOYMENT_TARGETが設定されていない気がして、iOS9に
  • Podfileのことを示唆されているとしてUncomment
# Uncomment this line to define a global platform for your project
 platform :ios, '9.0'

1

    Resolving dependencies of `Podfile`
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking
      is only perfomed in repo update
    [!] CocoaPods could not find compatible versions for pod "tflite":
      In Podfile:
        tflite (from `.symlinks/plugins/tflite/ios`)

    Specs satisfying the `tflite (from `.symlinks/plugins/tflite/ios`)` dependency were found,
    but they required a higher minimum deployment target.
    [!] Automatically assigning platform `iOS` with version `8.0` on target `Runner` because
    no platform was specified. Please specify a platform for this target in your Podfile. See
    `https://guides.cocoapods.org/syntax/podfile.html#platform`.

2

warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 4.3, but the
    range of supported deployment target versions is 8.0 to 13.2.99. (in target
    'image_picker' from project 'Pods')

その他

https://github.com/shaqian/flutter_tflite#ios
より

'tensorflow/lite/kernels/register.h' file not found

CONTRIB_PATHのコメント、アンコメント。これが一番格闘する相手になりました。

さいごに

サンプルは設定済みのiOSプロジェクトが入っているので、概ねMacでの環境設定ができればうまく行くのですが、VSCodeから作成されたプロジェクトはどうしてもうまく行きませんでした。

VSCodeでProject作成時にポップアップでflutterコマンドのオプションが表示されているのをみてswiftで作成されていることに気づきました。
あとはサンプルの中のプロジェクトとの差分を確認する作業がほとんどです。

自分のコードを書くのはこれからです。

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
0