最近為了使用掃碼和識別步悠,接入了google_ml_kit尚氛,記錄下踩過的盾饮。
功能
Vision
Feature | Android | iOS |
---|---|---|
Text Recognition | ? | ? |
Face Detection | ? | ? |
Pose Detection | ? | ? |
Selfie Segmentation | yet | yet |
Barcode Scanning | ? | ? |
Image Labelling | ? | ? |
Object Detection and Tracking | ? | yet |
Digital Ink Recognition | ? | ? |
Text Detector V2 | ? | yet |
Text Recognition V2 | ? | yet |
Natural Language
Feature | Android | iOS |
---|---|---|
Language Identification | ? | ? |
On-Device Translation | ? | yet |
Smart Reply | ? | yet |
Entity Extraction | ? | yet |
環(huán)境
iOS
- Minimum iOS Deployment Target: 10.0
- Xcode 12 or newer
- Swift 5
- ML Kit only supports 64-bit architectures (x86_64 and arm64). Check this list to see if your device has the required device capabilities.
接入
- 排除 armv7,不是必須步驟:
Xcode > Runner > Building Settings > Excluded Architectures > Any SDK > armv7
- 更改 IPHONEOS_DEPLOYMENT_TARGET土浸,不是必須步驟:
-
Firebase 創(chuàng)建項(xiàng)目:
官方教程不太準(zhǔn)確,可以參考到下載 GoogleService-Info.plist
在Firebase創(chuàng)建項(xiàng)目,添加 ios 應(yīng)用彭羹。
在軟件包 ID 字段中輸入應(yīng)用的軟件包 ID黄伊。
點(diǎn)擊注冊應(yīng)用。
點(diǎn)擊下載 GoogleService-Info.plist派殷,獲取 Firebase Apple 平臺配置文件 (
GoogleService-Info.plist
)还最。拷貝GoogleService-Info.plist到 ios/Runner/目錄下。右鍵 Runner毡惜,點(diǎn)擊 Add Files to "Runner",選擇GoogleService-Info.plist拓轻。
-
導(dǎo)包,初始化:
import UIKit
import Flutter
//添加這行
import FirebaseCore
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
//添加這行
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
如果找不到FirebaseCore
,在Podfile添加经伙,這種情況是不直接在項(xiàng)目里使用google_ml_kit,而是封裝為插件引入項(xiàng)目里:
target 'Runner' do
use_frameworks!
use_modular_headers!
# 添加這句話
pod 'Firebase'
-
運(yùn)行
pod install
:
如果 CocoaPods 版本過低悦即,請升級 CocoaPods。pod install
如果報錯執(zhí)行以下操作
退出Xcode.
刪除 ~/Library/Developer/Xcode/DerivedData
刪除 ProjectName.xcworkspace
刪除 Podfile.lock和 Pods 文件夾
pod install
大功告成
Android
環(huán)境
minSdkVersion: 21
targetSdkVersion: 29
接入
在 Firebase添加 Android 應(yīng)用
輸入包名注冊應(yīng)用
下載google-services.json
拷貝google-services.json到項(xiàng)目 android/app/目錄下
-
在
AndroidManifest.xml
里添加meta-data
:-
ica -
Image Labeling
-
ocr -
Barcode Scanning
-
face -
Face Detection
<!-- 添加這個,value 填入你用到的功能--> <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="ica,ocr,face" /> <meta-data android:name="flutterEmbedding" android:value="2" /> </application>
-
確保項(xiàng)目級 build.gradle(
android/build.gradle
)里包google
倉庫:buildscript { repositories { // 有這個 google() // Google's Maven repository*content_copy* } } allprojects { ... repositories { // 有這個: google() // Google's Maven repository*content_copy* ... } }
-
ica -
完事