이 가이드에서는 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.1 |
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에 종속 항목을 선언하고 자바에서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클래스 (FirebaseVisionImage대체)의getBitmap()메서드는 더 이상 공개 인터페이스의 일부로 지원되지 않습니다. 다양한 입력에서 변환된 비트맵을 가져오려면 ML Kit 빠른 시작 샘플의BitmapUtils.java을 참고하세요.FirebaseVisionImageMetadata가 삭제되었습니다.width,height,rotationDegrees,format과 같은 이미지 메타데이터를InputImage의 생성 메서드에 전달하면 됩니다.
다음은 이전 및 새 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())
다음은 이전 및 새 자바 메서드의 몇 가지 예입니다.
이전
// 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별 변경사항
바코드 스캔
이제 바코드 스캔 API의 경우 모델을 제공하는 방법이 두 가지입니다.
- Google Play 서비스를 통해 '씬'(권장) - 이렇게 하면 앱 크기가 줄어들고 모델이 애플리케이션 간에 공유됩니다. 하지만 개발자는 모델을 처음 사용하기 전에 모델이 다운로드되었는지 확인해야 합니다.
- 앱의 APK와 함께 '번들' - 이렇게 하면 앱 크기가 늘어나지만 모델을 즉시 사용할 수 있습니다.
두 구현은 약간 다르며 '번들' 버전에는 '씬' 버전에 비해 여러 가지 개선사항이 있습니다. 이러한 차이점에 관한 자세한 내용은 바코드 스캔 API 가이드를 참고하세요.
얼굴 인식
얼굴 인식 API의 경우 모델을 제공하는 방법이 두 가지입니다.
- Google Play 서비스를 통해 '씬'(권장) - 이렇게 하면 앱 크기가 줄어들고 모델이 애플리케이션 간에 공유됩니다. 하지만 개발자는 모델을 처음 사용하기 전에 모델이 다운로드되었는지 확인해야 합니다.
- 앱의 APK와 함께 '번들' - 이렇게 하면 앱 다운로드 크기가 늘어나지만 모델을 즉시 사용할 수 있습니다.
구현의 동작은 동일합니다.
번역
TranslateLanguage는 이제 언어 태그 (EN) 대신 상수 (예:ENGLISH)에 읽을 수 있는 이름을 사용합니다. 또한 이제@IntDef대신@StringDef이며 상수의 값은 일치하는 BCP 47 언어 태그입니다.
AutoML Image Labeling (지원 중단됨)
AutoML을 사용하여 이미지 라벨 지정을 위한 커스텀 모델 다운로드는 지원 중단되었으며 2027년 6월 15일에 중단됩니다. 대신 Cloud Storage를 사용하여 모델을 호스팅하고 앱에 다운로드 로직을 추가하여 모델을 다운로드해야 합니다. 자세한 내용은 Firebase ML에서 Cloud Storage로의 이전 가이드를 참고하세요.
객체 감지 및 추적
앱에서 대략적인 분류로 객체 감지를 사용하는 경우 새 SDK는 감지된 객체의 분류 카테고리를 반환하는 방식을 변경했습니다.
분류 카테고리는 정수 대신 DetectedObject.Label의 인스턴스로 반환됩니다. 대략적인 분류기의 가능한 모든 카테고리는 PredefinedCategory 클래스에 포함됩니다.
다음은 이전 및 새 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) { ... }
다음은 이전 및 새 자바 코드의 예입니다.
이전
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 콘솔에서 Firebase 앱을 삭제합니다.
도움말 보기
문제가 발생하면 Google에 문의할 수 있는 채널을 설명하는 커뮤니티 페이지 를 확인하세요.