이 가이드에서는 Android용 Firebase용 ML Kit에서 이전하는 방법을 설명합니다.
Gradle 가져오기 업데이트
ML Kit SDK에는 각 ML Kit API에 대한 종속 항목이 하나만 필요합니다. firebase-ml-vision 또는 firebase-ml-natural-language과 같은 일반 라이브러리는 지정할 필요가 없습니다. ML Kit는 Google Play 서비스에 종속된 라이브러리에 com.google.android.gms 네임스페이스를 사용합니다.
Vision API
번들 모델은 애플리케이션의 일부로 제공됩니다. 씬 모델은 다운로드해야 합니다. 일부 API는 번들 형식과 씬 형식으로 모두 사용할 수 있지만, 다른 API는 한 가지 형식으로만 사용할 수 있습니다.
| API | 번들 | 가늘게 |
|---|---|---|
| 텍스트 인식 | x (베타) | x |
| 얼굴 인식 | x | x |
| 바코드 스캔 | x | x |
| 이미지 라벨 지정 | x | x |
| 객체 감지 및 추적 | x | - |
다음 표에 따라 모듈 (앱 수준) Gradle 파일 (일반적으로 app/build.gradle.kts)에서 ML Kit Android 라이브러리의 종속 항목을 업데이트합니다.
번들 모델
| API | 이전 아티팩트 | 새로운 아티팩트 |
|---|---|---|
| 바코드 스캔 | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-barcode-model:16.0.1 |
com.google.mlkit:barcode-scanning:17.3.0 |
| 얼굴 윤곽 | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-face-model:19.0.0 |
com.google.mlkit:face-detection:16.1.7 |
| 이미지 라벨 지정 | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-image-label-model:19.0.0 |
com.google.mlkit:image-labeling:17.0.9 |
| 객체 감지 | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-object-detection-model:19.0.3 |
com.google.mlkit:object-detection:17.0.2 |
얇은 모델
| API | 이전 아티팩트 | 새로운 아티팩트 |
|---|---|---|
| 바코드 스캔 | com.google.firebase:firebase-ml-vision:24.0.1 | com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1 |
| 얼굴 인식 | com.google.firebase:firebase-ml-vision:24.0.1 | com.google.android.gms:play-services-mlkit-face-detection:17.1.0 |
| 텍스트 인식 | com.google.firebase:firebase-ml-vision:24.0.1 | com.google.android.gms:play-services-mlkit-text-recognition:19.0.2 |
AutoMLVision Edge
| API | 이전 아티팩트 | 새로운 아티팩트 |
|---|---|---|
| 다운로드 없이 AutoML 사용 | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-automl:18.0.3 |
com.google.mlkit:image-labeling-custom:17.0.3 |
| 다운로드가 포함된 AutoML | com.google.firebase:firebase-ml-vision:24.0.1 com.google.firebase:firebase-ml-vision-automl:18.0.3 |
com.google.mlkit:image-labeling-custom:17.0.3
커스텀 모델을 호스팅하고 다운로드하려면 모델을 Cloud Storage로 이동하고 앱에 다운로드 로직을 추가하여 LocalModel를 사용해 로드합니다. 자세한 내용은
Firebase ML에서 Cloud Storage로 이전 가이드를 참고하세요. |
Natural Language API
번들 모델은 애플리케이션의 일부로 제공됩니다. 씬 모델을 다운로드해야 합니다.
| API | 번들 | 가늘게 |
|---|---|---|
| 언어 ID | x | x |
| 스마트 답장 | x | x (베타) |
다음 표에 따라 모듈 (앱 수준) Gradle 파일 (일반적으로 app/build.gradle.kts)에서 ML Kit Android 라이브러리의 종속 항목을 업데이트합니다.
번들 모델
| API | 이전 아티팩트 | 새로운 아티팩트 |
|---|---|---|
| 언어 ID | com.google.firebase:firebase-ml-natural-language:22.0.0 com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7 |
com.google.mlkit:language-id:17.0.6 |
| 스마트 답장 | com.google.firebase:firebase-ml-natural-language:22.0.0 com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.7 |
com.google.mlkit:smart-reply:17.0.4 |
얇은 모델
| API | 이전 아티팩트 | 새로운 아티팩트 |
|---|---|---|
| 언어 ID | com.google.firebase:firebase-ml-natural-language:22.0.0 com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7 |
com.google.android.gms:play-services-mlkit-language-id:17.0.0 |
| 스마트 답장 | com.google.firebase:firebase-ml-natural-language:22.0.0 com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.7 |
com.google.android.gms:play-services-mlkit-smart-reply:16.0.0-beta1 |
클래스 이름 업데이트
클래스가 이 표에 표시되면 표시된 변경사항을 적용합니다.
| 이전 수업 | 새 수업 |
|---|---|
| com.google.firebase.ml.common.FirebaseMLException | com.google.mlkit.common.MlKitException |
| com.google.firebase.ml.vision.common.FirebaseVisionImage | com.google.mlkit.vision.common.InputImage |
| com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector | com.google.mlkit.vision.barcode.BarcodeScanner |
| com.google.firebase.ml.vision.labeler.FirebaseVisionImageLabel | com.google.mlkit.vision.label.ImageLabeler |
| com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector | com.google.mlkit.vision.barcode.BarcodeScanner |
| com.google.firebase.ml.vision.automl.FirebaseAutoMLLocalModel | com.google.mlkit.common.model.LocalModel |
| com.google.firebase.ml.vision.automl.FirebaseAutoMLRemoteModel | com.google.mlkit.common.model.LocalModel 수동 다운로드가 필요합니다. Firebase 호스팅 원격 모델은 지원 중단되었습니다. 자세한 내용은 Firebase ML에서 Cloud Storage로의 이전 가이드를 참고하세요. |
| com.google.firebase.ml.vision.label.FirebaseVisionOnDeviceImageLabelerOptions | com.google.mlkit.vision.label.defaults.ImageLabelerOptions |
| com.google.firebase.ml.vision.label.FirebaseVisionImageLabel | com.google.mlkit.vision.label.ImageLabel |
| com.google.firebase.ml.vision.label.FirebaseVisionOnDeviceAutoMLImageLabelerOptions | com.google.mlkit.vision.label.custom.CustomImageLabelerOptions |
| com.google.firebase.ml.vision.objects.FirebaseVisionObjectDetectorOptions | com.google.mlkit.vision.objects.defaults.ObjectDetectorOptions |
다른 클래스의 경우 다음 규칙을 따르세요.
- 클래스 이름에서
FirebaseVision접두사를 삭제합니다. - 클래스 이름에서
Firebase프리픽스로 시작하는 다른 프리픽스를 삭제합니다.
또한 패키지 이름에서 com.google.firebase.ml 접두사를 com.google.mlkit로 바꿉니다.
업데이트 메서드 이름
코드 변경사항은 최소화됩니다.
- 감지기/스캐너/라벨러/번역기… 인스턴스화가 변경되었습니다. 이제 각 기능에는 자체 진입점이 있습니다. 예를 들어
BarcodeScanning,TextRecognition,ImageLabeling,Translation… Firebase 서비스getInstance()에 대한 호출은 기능 진입점의getClient()메서드에 대한 호출로 대체됩니다. - 중국어 및 한국어와 같은 다른 스크립트를 인식하기 위한 추가 라이브러리가 도입되었으므로
TextRecognizer의 기본 인스턴스화가 삭제되었습니다. 라틴어 스크립트 텍스트 인식 모델에서 기본 옵션을 사용하려면com.google.android.gms:play-services-mlkit-text-recognition에 대한 종속 항목을 선언하고TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)를 사용합니다. ImageLabeler및ObjectDetector의 기본 인스턴스화는 이 두 기능에 대한 커스텀 모델 지원을 도입했으므로 삭제되었습니다. 예를 들어ImageLabeling의 기본 모델과 함께 기본 옵션을 사용하려면com.google.mlkit:image-labeling에 대한 종속 항목을 선언하고 Java에서ImageLabeling.getClient(ImageLabelerOptions.DEFAULT_OPTIONS)를 사용합니다.- 모든 핸들 (감지기/스캐너/라벨러/번역기…)은 닫을 수 있습니다. 이러한 객체가 더 이상 사용되지 않을 때
close()메서드가 호출되는지 확인합니다.Fragment또는AppCompatActivity에서 사용하는 경우Fragment또는AppCompatActivity에서LifecycleOwner.getLifecycle()를 호출한 다음Lifecycle.addObserver를 호출하면 됩니다. - Vision API의
processImage()및detectInImage()는 일관성을 위해process()로 이름이 변경되었습니다. - 이제 Natural Language API는 '언어 코드' 대신 BCP 47 표준에 정의된 '언어 태그'라는 용어를 사용합니다.
xxxOptions클래스의 getter 메서드가 삭제되었습니다.InputImage클래스의getBitmap()메서드(FirebaseVisionImage대체)는 더 이상 공개 인터페이스의 일부로 지원되지 않습니다. ML Kit 빠른 시작 샘플의BitmapUtils.java를 참고하여 다양한 입력에서 변환된 비트맵을 가져옵니다.FirebaseVisionImageMetadata가 삭제되었으므로width,height,rotationDegrees,format와 같은 이미지 메타데이터를InputImage의 구성 메서드에 전달하면 됩니다.
다음은 이전 Kotlin 메서드와 새 Kotlin 메서드의 예입니다.
변경 전
// Construct image labeler with base model and default options. val imageLabeler = FirebaseVision.getInstance().onDeviceImageLabeler // Construct object detector with base model and default options. val objectDetector = FirebaseVision.getInstance().onDeviceObjectDetector // Construct face detector with given options val faceDetector = FirebaseVision.getInstance().getVisionFaceDetector(options) // Construct image labeler with local AutoML model val localModel = FirebaseAutoMLLocalModel.Builder() .setAssetFilePath("automl/manifest.json") .build() val autoMLImageLabeler = FirebaseVision.getInstance() .getOnDeviceAutoMLImageLabeler( FirebaseVisionOnDeviceAutoMLImageLabelerOptions.Builder(localModel) .setConfidenceThreshold(0.3F) .build() )
신규
// Construct image labeler with base model and default options. val imageLabeler = ImageLabeling.getClient(ImageLabelerOptions.DEFAULT_OPTIONS) // Optional: add lifecycle observer lifecycle.addObserver(imageLabeler) // Construct object detector with base model and default options. val objectDetector = ObjectDetection.getClient( ObjectDetectorOptions.DEFAULT_OPTIONS ) // Construct face detector with given options val faceDetector = FaceDetection.getClient(options) // Construct image labeler with local AutoML model val localModel = LocalModel.Builder() .setAssetManifestFilePath("automl/manifest.json") .build() val autoMLImageLabeler = ImageLabeling.getClient( CustomImageLabelerOptions.Builder(localModel) .setConfidenceThreshold(0.3F).build())
다음은 이전 Java 메서드와 새 Java 메서드의 몇 가지 예입니다.
변경 전
// Construct image labeler with base model and default options. FirebaseVisionImageLabeler imagelLabeler = FirebaseVision.getInstance().getOnDeviceImageLabeler(); // Construct object detector with base model and default options. FirebaseVisionObjectDetector objectDetector = FirebaseVision.getInstance().getOnDeviceObjectDetector(); // Construct face detector with given options FirebaseVisionFaceDetector faceDetector = FirebaseVision.getInstance().getVisionFaceDetector(options); // Construct image labeler with local AutoML model FirebaseAutoMLLocalModel localModel = new FirebaseAutoMLLocalModel.Builder() .setAssetFilePath("automl/manifest.json") .build(); FirebaseVisionImageLabeler autoMLImageLabeler = FirebaseVision.getInstance() .getOnDeviceAutoMLImageLabeler( FirebaseVisionOnDeviceAutoMLImageLabelerOptions.Builder(localModel) .setConfidenceThreshold(0.3F) .build());
신규
// Construct image labeler with base model and default options. ImageLabeler imageLabeler = ImageLabeling.getClient( ImageLabelerOptions.DEFAULT_OPTIONS ); // Optional: add lifecycle observer getLifecycle().addObserver(imageLabeler); // Construct object detector with base model and default options. ObjectDetector objectDetector = ObjectDetection.getClient( ObjectDetectorOptions.DEFAULT_OPTIONS ); // Construct face detector with given options FaceDetector faceDetector = FaceDetection.getClient(options); // Construct image labeler with local AutoML model LocalModel localModel = new LocalModel.Builder() .setAssetManifestFilePath("automl/manifest.json") .build(); ImageLabeler autoMLImageLabeler = ImageLabeling.getClient( new CustomImageLabelerOptions.Builder(localModel) .setConfidenceThreshold(0.3F).build());
API별 변경사항
바코드 스캔
Barcode Scanning API의 경우 이제 모델을 두 가지 방법으로 제공할 수 있습니다.
- Google Play 서비스('thin'이라고도 함)를 통해(권장) - 앱 크기가 줄어들고 애플리케이션 간에 모델이 공유됩니다. 하지만 개발자는 모델을 처음 사용하기 전에 모델이 다운로드되었는지 확인해야 합니다.
- 앱의 APK(일명 '번들') 사용 - 앱 크기가 증가하지만 모델을 즉시 사용할 수 있습니다.
두 구현은 약간 다르며 '번들' 버전은 '씬' 버전에 비해 여러 가지 개선사항이 있습니다. 이러한 차이점에 관한 자세한 내용은 Barcode Scanning API 가이드라인을 참고하세요.
얼굴 인식
얼굴 인식 API의 경우 모델을 전송하는 방법에는 두 가지가 있습니다.
- Google Play 서비스('thin'이라고도 함)를 통해(권장) - 앱 크기가 줄어들고 애플리케이션 간에 모델이 공유됩니다. 하지만 개발자는 모델을 처음 사용하기 전에 모델이 다운로드되었는지 확인해야 합니다.
- 앱의 APK(일명 '번들') 사용 - 앱 다운로드 크기가 증가하지만 모델을 즉시 사용할 수 있습니다.
구현의 동작은 동일합니다.
번역
- 이제
TranslateLanguage에서 언어 태그(EN) 대신 상수에 읽을 수 있는 이름(예:ENGLISH)을 사용합니다. 또한 이제@IntDef대신@StringDef이며 상수의 값은 일치하는 BCP 47 언어 태그입니다.
AutoML 이미지 라벨 지정 (지원 중단됨)
AutoML을 사용한 이미지 라벨 지정을 위한 커스텀 모델 다운로드는 지원 중단되었으며 2027년 6월 15일에 종료됩니다. 대신 Cloud Storage를 사용하여 모델을 호스팅하고 앱에 다운로드 로직을 추가하여 모델을 다운로드해야 합니다. 자세한 내용은 Firebase ML에서 Cloud Storage로의 이전 가이드를 참고하세요.
객체 감지 및 추적
앱에서 대략적인 분류와 함께 객체 감지를 사용하는 경우 새 SDK에서 감지된 객체의 분류 카테고리를 반환하는 방식이 변경되었습니다.
분류 카테고리는 정수 대신 DetectedObject.Label의 인스턴스로 반환됩니다. 대략적인 분류기에 가능한 모든 카테고리는 PredefinedCategory 클래스에 포함됩니다.
다음은 이전 Kotlin 코드와 새 Kotlin 코드의 예입니다.
변경 전
if (object.classificationCategory == FirebaseVisionObject.CATEGORY_FOOD) { ... }
신규
if (!object.labels.isEmpty() && object.labels[0].text == PredefinedCategory.FOOD) { ... } // or if (!object.labels.isEmpty() && object.labels[0].index == PredefinedCategory.FOOD_INDEX) { ... }
다음은 이전 Java 코드와 새 Java 코드의 예입니다.
변경 전
if (object.getClassificationCategory() == FirebaseVisionObject.CATEGORY_FOOD) { ... }
신규
if (!object.getLabels().isEmpty() && object.getLabels().get(0).getText().equals(PredefinedCategory.FOOD)) { ... } // or if (!object.getLabels().isEmpty() && object.getLabels().get(0).getIndex() == PredefinedCategory.FOOD_INDEX) { ... }
'알 수 없음' 카테고리가 삭제되었습니다. 객체 분류의 신뢰도가 낮으면 라벨이 반환되지 않습니다.
Firebase 종속 항목 삭제
마이그레이션 후 Firebase 종속 항목을 삭제합니다. 다음 단계를 따르세요.
- 앱의 모듈 (앱 수준) 디렉터리에서
google-services.json구성 파일을 삭제하여 Firebase 구성 파일을 삭제합니다. - 모듈 (앱 수준) Gradle 파일 (일반적으로
app/build.gradle.kts)의 Google 서비스 Gradle 플러그인을 엄격한 버전 일치 도구 플러그인으로 바꿉니다.
이전
plugins { id("com.android.application") id("com.google.gms.google-services") } android { // … }
이후
plugins { id("com.android.application") id("com.google.android.gms.strict-version-matcher-plugin") } android { // … }
- 프로젝트(루트 수준) Gradle 파일 (
build.gradle.kts)의 Google 서비스 Gradle 플러그인 클래스 경로를 엄격한 버전 일치 도구 플러그인의 클래스 경로로 바꿉니다.
이전
buildscript { dependencies { // ... classpath("com.google.gms:google-services:4.3.3") } }
이후
buildscript { dependencies { // ... classpath("com.google.android.gms:strict-version-matcher-plugin:1.2.1") } }
Firebase 지원 사이트의 안내에 따라 Firebase Console에서 Firebase 앱을 삭제합니다.
도움말 보기
문제가 발생하면 Google에 문의할 수 있는 채널이 설명되어 있는 커뮤니티 페이지를 확인하세요.