Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS - App Crashes When Using RecognisedText #188

Closed
prafull2001 opened this issue Jan 13, 2022 · 15 comments
Closed

iOS - App Crashes When Using RecognisedText #188

prafull2001 opened this issue Jan 13, 2022 · 15 comments

Comments

@prafull2001
Copy link

I am trying to run a simple program that takes an image from a user's gallery and converts it into text. 'imageToText()' takes an image as input and is supposed to parse the detected text. As of now the program is able to print "loaded textDetector" but then immediately crashes when trying to set up the recognisedText object as shown below the code.

I have also included the Xcode Output that I get when trying to run the app on a physical device. I am not sure what the error could be at this point as I have followed everything in the official package documentation. Any help would be greatly appreciated since I've been stuck on this for days.

imageToText()
    Future imageToText(inputImage) async {
      print("starting");
      result = '';
  
      final textDetector = GoogleMlKit.vision.textDetector();
      print("loaded textDetector");
      final RecognisedText recognisedText = await textDetector.processImage(inputImage);
      print("loaded recognisedText");
  
      setState(() {
        String text = recognisedText.text;
        for (TextBlock block in recognisedText.blocks) {
          //each block of text/section of text
          final String text = block.text;
          print("block of text: ");
          print(text);
          for (TextLine line in block.lines) {
            //each line within a text block
            for (TextElement element in line.elements) {
              //each word within a line
              result += element.text + " ";
            }
          }
        }
        result += "\n\n";
      });
  }

Screen Shot 2022-01-13 at 2 08 26 PM

XCode Output 2022-01-13 13:53:48.202214-0500 Runner[21400:1972252] Metal GPU Frame Capture Enabled 2022-01-13 13:53:48.202333-0500 Runner[21400:1972252] Metal API Validation Enabled 2022-01-13 13:53:48.599642-0500 Runner[21400:1972526] flutter: Observatory listening on http://127.0.0.1:56271/miwaCqXFTX8=/ 2022-01-13 13:53:49.561937-0500 Runner[21400:1972513] fopen failed for data file: errno = 2 (No such file or directory) 2022-01-13 13:53:49.561998-0500 Runner[21400:1972513] Errors found! Invalidating cache... 2022-01-13 13:53:49.713065-0500 Runner[21400:1972513] fopen failed for data file: errno = 2 (No such file or directory) 2022-01-13 13:53:49.713167-0500 Runner[21400:1972513] Errors found! Invalidating cache... 2022-01-13 13:53:57.278499-0500 Runner[21400:1972499] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2022-01-13 13:53:57.354180-0500 Runner[21400:1972512] flutter: starting 2022-01-13 13:53:57.354418-0500 Runner[21400:1972512] flutter: loaded textDetector 2022-01-13 13:53:57.361475-0500 Runner[21400:1972508] 8.10.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://goo.gl/ctyzm8. 2022-01-13 13:53:57.365819-0500 Runner[21400:1972252] *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'The default Firebase app instance must be configured. To configure, call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).' *** First throw call stack: (0x19d09adc0 0x1b1bf77a8 0x19cf8fe74 0x101b1efe8 0x101b2085c 0x101b207dc 0x1009d1e8c 0x1009d20dc 0x1009d25fc 0x100b369f4 0x100b35e8c 0x100b360e4 0x100b34548 0x100b343ec 0x102467bcc 0x104954e4c 0x104954cd8 0x104950418 0x107c6594c 0x1077b6120 0x107b32aec 0x107a60204 0x107a63f5c 0x19d0158c0 0x19d0154bc 0x19d01490c 0x19d00e6c0 0x19d00d9f4 0x1b46e3734 0x19fa8c75c 0x19fa91fcc 0x1009d0abc 0x19ccc9cf8) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'The default Firebase app instance must be configured. To configure, call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).' terminating with uncaught exception of type NSException (lldb) ` 2022-01-13 13:53:48.202214-0500 Runner[21400:1972252] Metal GPU Frame Capture Enabled 2022-01-13 13:53:48.202333-0500 Runner[21400:1972252] Metal API Validation Enabled 2022-01-13 13:53:48.599642-0500 Runner[21400:1972526] flutter: Observatory listening on http://127.0.0.1:56271/miwaCqXFTX8=/ 2022-01-13 13:53:49.561937-0500 Runner[21400:1972513] fopen failed for data file: errno = 2 (No such file or directory) 2022-01-13 13:53:49.561998-0500 Runner[21400:1972513] Errors found! Invalidating cache... 2022-01-13 13:53:49.713065-0500 Runner[21400:1972513] fopen failed for data file: errno = 2 (No such file or directory) 2022-01-13 13:53:49.713167-0500 Runner[21400:1972513] Errors found! Invalidating cache... 2022-01-13 13:53:57.278499-0500 Runner[21400:1972499] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2022-01-13 13:53:57.354180-0500 Runner[21400:1972512] flutter: starting 2022-01-13 13:53:57.354418-0500 Runner[21400:1972512] flutter: loaded textDetector 2022-01-13 13:53:57.361475-0500 Runner[21400:1972508] 8.10.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://goo.gl/ctyzm8. 2022-01-13 13:53:57.365819-0500 Runner[21400:1972252] *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'The default Firebase app instance must be configured. To configure, call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).' *** First throw call stack: (0x19d09adc0 0x1b1bf77a8 0x19cf8fe74 0x101b1efe8 0x101b2085c 0x101b207dc 0x1009d1e8c 0x1009d20dc 0x1009d25fc 0x100b369f4 0x100b35e8c 0x100b360e4 0x100b34548 0x100b343ec 0x102467bcc 0x104954e4c 0x104954cd8 0x104950418 0x107c6594c 0x1077b6120 0x107b32aec 0x107a60204 0x107a63f5c 0x19d0158c0 0x19d0154bc 0x19d01490c 0x19d00e6c0 0x19d00d9f4 0x1b46e3734 0x19fa8c75c 0x19fa91fcc 0x1009d0abc 0x19ccc9cf8) libc++abi: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'FIRAppNotConfigured', reason: 'The default Firebase app instance must be configured. To configure, call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).' terminating with uncaught exception of type NSException (lldb)
Podfile
  # Uncomment this line to define a global platform for your project
  platform :ios, '10.0'
  
  # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
  ENV['COCOAPODS_DISABLE_STATS'] = 'true'
  
  project 'Runner', {
    'Debug' => :debug,
    'Profile' => :release,
    'Release' => :release,
  }
  
  def flutter_root
    generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
    unless File.exist?(generated_xcode_build_settings_path)
      raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
    end
  
    File.foreach(generated_xcode_build_settings_path) do |line|
      matches = line.match(/FLUTTER_ROOT\=(.*)/)
      return matches[1].strip if matches
    end
    raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
  end
  
  require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
  
  flutter_ios_podfile_setup
  
  target 'Runner' do
    use_frameworks!
    use_modular_headers!
  
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    pod 'GoogleMLKit/TextRecognition'
  end
  
  post_install do |installer|
    # add these lines:
    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=*]"] = "armv7"
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = $iOSVersion
    end
  
    installer.pods_project.targets.each do |target|
      flutter_additional_ios_build_settings(target)
  
      # add these lines:
      target.build_configurations.each do |config|
        if Gem::Version.new($iOSVersion) > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = $iOSVersion
        end
      end
    end
  end


@lala-naibova
Copy link

I also get the same error

@lala-naibova
Copy link

@prafull2001 , I did some changes in xcode,
I added FirebaseApp.configure() - to the AppDelegate (didFinishLaunchingWithOptions) and everything is Ok in this IDE,
but android studio doesn't see this changes

@lala-naibova
Copy link

@prafull2001 , change IDE from studio to Visual Code, everything will be okay then

@prafull2001
Copy link
Author

@lala-naibova why does that work for you? There should be no difference between IDEs especially if Android Studios is maintained by Google. Is the google_ml_kit plugin even maintained by google officially? It doesn't seem to have any official flutter support.

@lala-naibova
Copy link

Now everything is okay with all IDE for me, after doing some changes in xcode I had to close the project in studio,

@prafull2001
Copy link
Author

Are you talking about Android Studio? And could you please describe the changes you had to do?

@lala-naibova
Copy link

Open runner in xcode, and add FirebaseApp.configure(); -to the appdelegate ,
P.S : import FirebaseCore

@prafull2001
Copy link
Author

I am getting this error on my AppDelegate

Screen Shot 2022-01-19 at 2 26 45 PM

@lala-naibova
Copy link

Actually I didn't know why this happening, I also got this red lines ( I ll share with u if find some info about that). Anyway just try to build your app in xcode then go to android studio and continue coding , This error doesnt affect to build operation

@prafull2001
Copy link
Author

For me it does, my app crashes upon startup I'm not sure why, can't find anything relevant on the topic.

@renanyoy
Copy link

renanyoy commented Feb 1, 2022

adding FirebaseApp.configure() doesn't work for me, app crash with the error "firebase already configured" at launch.

@renanyoy
Copy link

renanyoy commented Feb 7, 2022

sry for it's for another reason #195

@kabilya
Copy link

kabilya commented Mar 3, 2022

Hi,
I had a similar problem and was crashing with RecognisedText.
The problem was the previous version was returning a Map class instead of TextBlock.
But TextDetectoV2 is now returning an actual TextBlock.

I edited the RecognisedText class and is working now.
Line 78 of text_detector.dart

class RecognisedText {
  RecognisedText._(this.text, this.blocks);

  factory RecognisedText.fromMap(Map<dynamic, dynamic> map) {
    var resText = map["text"];
    var textBlocks = <TextBlock>[];
    for (var block in map["blocks"]) {
      // var textBlock = TextBlock.fromMap(block);
      // textBlocks.add(textBlock);
      textBlocks.add(block);
    }
    return RecognisedText._(resText, textBlocks);
  }

@vasu2408
Copy link

I also faced the same issue.
But in my case it was Google-service.plist file, I forgot to add that file so it was giving me error.
Then I added it and added FirebaseApp.configure() and its done...

@fbernaly
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants