azihsoyn / flutter_mlkit

A Flutter plugin to use the Firebase ML Kit.
MIT License
391 stars 91 forks source link

Cannot get the example to work. Need to initialize the FirebaseApp (FirebaseVisionTextDetector)? #26

Open eduardkieser opened 6 years ago

eduardkieser commented 6 years ago

Hi there, thank you for this plugin. I'm having a hard time getting the example to work: Steps: -Create new flutter project -add mlkit: "^0.4.1" and image_picker: "^0.4.5" to dependencies -get Packages -copy pase code from main.dart in example folder to my project main.dart

run: The app opens up, when I select a file it shows the image in the container, but no text overlay and the text widget simply says 'Empty' even though the text is large and clear.

I get the following output (including error) from the Run console every time I select an image:

I/zygote64(17020): Do partial code cache collection, code=61KB, data=52KB
I/zygote64(17020): After code cache collection, code=61KB, data=52KB
I/zygote64(17020): Increasing code cache capacity to 256KB
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(65.1, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(281.3, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(65.1, 80.0, 346.3, 580.0)
I/FlutterActivityDelegate(17020): onResume setting current activity to this
E/MethodChannel#plugins.flutter.io/mlkit(17020): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mlkit(17020): java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.kieserengineering.mlkittest. Make sure to call FirebaseApp.initializeApp(Context) first.
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at com.google.firebase.FirebaseApp.getInstance(Unknown Source:59)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at com.google.firebase.ml.vision.FirebaseVision.getInstance(Unknown Source:0)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at com.azihsoyn.flutter.mlkit.MlkitPlugin.onMethodCall(MlkitPlugin.java:84)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:136)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at android.app.ActivityThread.main(ActivityThread.java:6753)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
E/MethodChannel#plugins.flutter.io/mlkit(17020):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I/flutter (17020): PlatformException(error, Default FirebaseApp is not initialized in this process com.kieserengineering.mlkittest. Make sure to call FirebaseApp.initializeApp(Context) first., null)
I/flutter (17020): original Image Size : Size(720.0, 1280.0)
I/flutter (17020): offset : Offset(205.7, 330.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(0.0, 0.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(205.7, 330.0, 205.7, 330.0)
I/flutter (17020): original Image Size : Size(1871.0, 2627.0)
I/flutter (17020): offset : Offset(27.7, 80.0)
I/flutter (17020): configuration : ImageConfiguration(bundle: PlatformAssetBundle#eefb9(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, size: Size(356.1, 500.0), platform: android)
I/flutter (17020): rect container : Rect.fromLTRB(27.7, 80.0, 383.8, 580.0)
eduardkieser commented 6 years ago

Also Tried Forking the project. After resolving gradle I try to build and run main.dart, but then I get: Task 'assemble' not found in root project 'flutter_mlkit-master'.

azihsoyn commented 6 years ago

Thanks reporting! I'll check it later.

azihsoyn commented 6 years ago

Hi, eduardkieser

This issue may help you. https://github.com/azihsoyn/flutter_mlkit/issues/6#issuecomment-393729454 https://github.com/azihsoyn/flutter_mlkit/issues/6#issuecomment-393880362

Default FirebaseApp is not initialized

This error message will cause by invalid gradle configuration.

Please ensure setting follow by this guide. https://firebase.google.com/docs/android/setup?authuser=1

CognitiveClouds-Prasad commented 5 years ago

I am getting the same error FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance() .getOnDeviceTextRecognizer(); gives me Make sure to call FirebaseApp.initializeApp(Context) first.

azihsoyn commented 5 years ago

Hi, @CognitiveClouds-Prasad

Recently, Google's maven repository has changed. https://firebase.google.com/docs/android/setup

Please try below gradle.

allprojects {
    // ...
    repositories {
        // ...
        google() // Google's Maven repository
    }
}

Thanks.

CognitiveClouds-Prasad commented 5 years ago

Thank you for such a quick response! :) I am struggling so much. But, no luck! :(

I am not using any cloud functionality. So, I removed google services. Then, I have added google() in gradle. I have shared my gradle files.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "x.x.x.x"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:18.0.2'
}
azihsoyn commented 5 years ago

Hi, @CognitiveClouds-Prasad

I am not using any cloud functionality. So, I removed google services.

This cause this.

If you don't use cloud detect function, MLKit requires firebase project.

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

This plugin parses google-services.json and initialize your Firebase app ( FirebaseApp.initializeApp(Context) )

Try adding gradle setting.

Thanks.

CognitiveClouds-Prasad commented 5 years ago

@azihsoyn Your suggestions are awesome! It worked for me!. So, thank you. :slightly_smiling_face:

I added classpath 'com.google.gms:google-services:4.1.0'. I also added apply plugin: 'com.google.gms.google-services'. I created a new Firebase app (from console.firebase.google.com) and then added that google-services.json as mentioned there (in 'app' folder). I am getting java.lang.IllegalStateException: Task is not yet complete. But, I think that is not related to this. I will figure the rest out.

AmrHussienM commented 5 years ago

error and also after i add apply plugin: 'com.google.gms.google-services' Error" File google-services.json is missing. The Google Services Plugin cannot function without it."

azihsoyn commented 5 years ago

Hi, @AmrHussienM !

Firebase app for android needs google-services.json.

Please try this 3rd step. https://firebase.google.com/docs/android/setup

AmrHussienM commented 5 years ago

@azihsoyn thank you for your suggestions; image iam already did the 3rd step and the error same

azihsoyn commented 5 years ago

🤔

Where is your google-services.json placed?

<flutter_root>
    android/app/google_services.json

sample: https://github.com/azihsoyn/flutter_mlkit_sample/tree/master/android/app