只有当我使用
workmanager
软件包时才会发生这种情况,我认为与某些谷歌软件包或flutter_tesseract_ocr
有冲突
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) {
print('I dont know what happens so help');
return Future.value(true);
});
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_firebasePushHandler);
MobileAds.instance.initialize();
await CacheHelper.init();
await EasyLocalization.ensureInitialized();
await CacheHelper.removeData('isshown');
DioHelper.init();
//Work manager initializtion
Workmanager().initialize(
callbackDispatcher, // The top level function, aka callbackDispatcher
);
index = CacheHelper.getData(key: 'index') ?? 0;
String? uid = CacheHelper.getData(key: 'uid');
await NotificationApi.init();
BlocOverrides.runZoned(
() {
runApp(
EasyLocalization(
supportedLocales: const [Locale('en'), Locale('ar')],
path: 'assets/lang', // <-- change the path of the translation files
assetLoader: const CodegenLoader(),
fallbackLocale: const Locale('en'),
child: MyApp(uid)),
);
},
blocObserver: MyBlocObserver(),
);
}
///this is code where I register it
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
HapticFeedback.lightImpact();
setState(() {
controller!.forward();
});
// Workmanager().cancelAll();
Workmanager().registerOneOffTask('awsomeNotification', 'notify',
initialDelay: const Duration(seconds: 5));
},
child: CardStack(controller!, widget.slideNum, widget.slideText),
);
}
W/MediaSessionCompat(12770): Couldn't find a unique registered media button receiver in the given context.
W/FlutterJNI(12770): FlutterJNI.loadLibrary called more than once
I/ResourceExtractor(12770): Found extracted resources res_timestamp-1-1656733798661
W/FlutterJNI(12770): FlutterJNI.prefetchDefaultFontManager called more than once
W/FlutterJNI(12770): FlutterJNI.init called more than once
D/AndroidRuntime(12770): Shutting down VM
E/AndroidRuntime(12770): FATAL EXCEPTION: main
E/AndroidRuntime(12770): Process: com.areading.amaa, PID: 12770
E/AndroidRuntime(12770): java.lang.NullPointerException: Attempt to invoke virtual method 'void com.googlecode.tesseract.android.TessBaseAPI.recycle()' on a null object reference
E/AndroidRuntime(12770): at io.paratoner.flutter_tesseract_ocr.FlutterTesseractOcrPlugin.onDetachedFromEngine(FlutterTesseractOcrPlugin.java:42)
E/AndroidRuntime(12770): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:270)
E/AndroidRuntime(12770): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:280)
E/AndroidRuntime(12770): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:288)
E/AndroidRuntime(12770): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:121)
E/AndroidRuntime(12770): at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:425)
E/AndroidRuntime(12770): at be.tramckrijte.workmanager.BackgroundWorker.stopEngine$lambda-2(BackgroundWorker.kt:137)
E/AndroidRuntime(12770): at be.tramckrijte.workmanager.BackgroundWorker.lambda$u5fs2CPxJ29Hdjbap5WYUt2tGrg(Unknown Source:0)
E/AndroidRuntime(12770): at be.tramckrijte.workmanager.-$$Lambda$BackgroundWorker$u5fs2CPxJ29Hdjbap5WYUt2tGrg.run(Unknown Source:2)
E/AndroidRuntime(12770): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(12770): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(12770): at android.os.Looper.loopOnce(Looper.java:210)
E/AndroidRuntime(12770): at android.os.Looper.loop(Looper.java:299)
E/AndroidRuntime(12770): at android.app.ActivityThread.main(ActivityThread.java:8168)
E/AndroidRuntime(12770): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12770): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
E/AndroidRuntime(12770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
I/WM-WorkerWrapper(12770): Worker result SUCCESS for Work [ id=58f0ee16-1de5-42d8-ae78-1d789ea5125f, tags={ be.tramckrijte.workmanager.BackgroundWorker } ]
D/OOMEventManagerFK(12770): checkEventAndDumpForJE: 0
I/Process (12770): Sending signal. PID: 12770 SIG: 9
Lost connection to device.
Exited (sigterm)
由于启动了后台任务 - 调用了
onDetachedFromEngine
方法 - 在用于 Flutter 的 TessOCR 原始插件存储库中,没有空安全检查。
我通过分叉 TessOCR 存储库为此提供了一个简单的补丁: https://github.com/EthanKrimer/tesseract_ocr/compare/5510f1345089ae617744a401710e0ae7fb87c43a...923ebd1c302363e3de61e9693d6eb36617908073
为了在您的 flutter 应用程序中使用此修复程序: 将其添加到您的
pubspec.yaml
dependencies:
flutter_tesseract_ocr:
git:
url: https://github.com/EthanKrimer/tesseract_ocr.git
ref: master
然后运行
pub upgrade