为Flutter插件添加依赖项会使Flutter App崩溃 [英] Adding dependencies for a Flutter plugin crashes my Flutter App
问题描述
当我按照hello-world方法创建Flutter插件并将其添加到另一个hello-world Flutter项目时,每当我尝试添加插件依赖项(使用path:
的本地或使用
我的步骤是:
- 我创建一个新的Flutter项目,在终端中执行以下操作:
flutter create hello_world_app
-
我在hello_world_app中添加了大资产(> 665 MB),因为我需要在应用程序中使用它.
-
我使用hello_world_app中的大量资产来构建和运行原型应用程序.它运行没有任何问题.
-
我确实使用以下终端命令创建了插件:
-
我创建了一个在终端内部编写的Flutter插件:
flutter create --org com.mycomp --template=plugin -i swift large_file_copy
-
我对新创建的插件做了一些小的更改.我可以在两个世界(iOS和Android)上运行新创建的插件"large_file_copy".我从plugin-example文件夹运行它.一切正常.
-
我从插件中制作了一个git repo,我提交了所有更改并将其推送到公共git repo.
但是现在,这才是出问题的地方:
- 我尝试将插件添加到hello-world项目的依赖项中,执行以下操作:
我的"hello_world_app"的pubspec.yaml
内部
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
large_file_copy:
git:
url: https://github.com/XXXXX/large_file_copy.git
输出端子说:
Running "flutter packages get" in my_app... 0.6s
exit code 0
然后我尝试运行我的项目.那就是应用崩溃的那一刻.
为什么增加插件依赖性使我的抖动项目崩溃?
实际上,我什至可以将插件包导入到我的flutter代码中并调用plugin方法.编译器此刻没有抱怨.但是,一旦我尝试构建并运行,那便是应用程序崩溃的时候...
上述方法有什么问题?
如何正确设置插件依赖项?
这是两个错误消息日志(一个用于iOS,一个用于Android world).同样,将插件依赖项添加到pubspec.yaml文件后,这些问题就会再次出现.
iOS的错误消息日志:
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/KZLinkedConsole.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ColorSenseRainbow.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/BBUDebuggerTuckAway.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.180 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET sqflite OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/user/Documents/flutter/.pub-cache/git/large_file_copy-5cc22b5c6d2345ba1ab23a44324b222c68d24ab4/ios/Classes/MyPluginName.m:2:9: fatal error: 'large_file_copy/large_file_copy-Swift.h' file not found
#import < large_file_copy/large_file_copy-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Could not build the application for the simulator.
Error launching application on iPhone XS.
Exited (sigterm)
. Android的错误消息日志:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:packageDebug'.
> Failed to obtain compression information for entry
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
原来,不是插件添加就是问题!
在Flutter应用程序中拥有的大量资产是导致异常的原因.
从我将插件添加到我的应用程序那一刻起,我的Flutter应用程序崩溃几乎一定是偶然的.这是误导. (因此,我认为这样做可能也是如此-稍后,当我构建Flutter应用并添加更多代码时,可能是某种内存问题...或者您告诉我!)
一旦我删除了大笔资产(665 MB),插件集成就会顺利进行,而不会发生任何异常.
该问题的难度转为另一个stackoverflow问题:
I add a large asset (> 665 MB) to my hello_world_app since I will need it inside my app. I build and run a prototype app using my large asset inside hello_world_app. It runs without any problems. I did create the plugin using the following terminal command: I create a Flutter plugin writing inside a terminal: I do some minor changes to the newly created plugin. I can run the newly created plugin "large_file_copy" on both worlds (iOS and Android). I run it from the plugin-example folder. All works well. I make a git repo out of the plugin and I commit all changes and push it to a public git repo. But now, that's when things go wrong: Inside The output terminal sais: Then I try to run my project. And that's the moment the App crashes. WHY IS ADDING THE PLUGIN DEPENDENCY MAKE MY FLUTTER PROJECT CRASH ?? In fact, I can even import the plugin-package to my flutter code and call the plugin method. The compiler does not complain at this moment. But as soon as I try to build and run, that's when the app crashes... What is wrong in the above approach ?? How do I correctly set the plugin dependency ?? Here are the two error message-logs (one for iOS and one for Android world). Again, these occur as soon as the plugin dependency is added to the pubspec.yaml file.... Error message-log for iOS: .
Error message-log for Android:
Turns out that not the plugin-adding is the problem ! It is rather my large asset that I have inside the Flutter app that causes the exception. And it must be more or less a coincidence that my Flutter app crashes from the moment I add the plugin to my app. It was misleading. (I therefore assume that it might have done so as well - later when I build-up my Flutter app and add more code. It might be a memory issue of some sort...or you tell me!) As soon as I remove my large asset (665 MB), the plugin integration works smoothly without any exception. The question shifts tough to another stackoverflow question: How to integrate a large asset in my Flutter app And this query can be closed. 这篇关于为Flutter插件添加依赖项会使Flutter App崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!flutter create --org com.mycomp --template=plugin -i swift large_file_copy
pubspec.yaml
of my "hello_world_app"dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
large_file_copy:
git:
url: https://github.com/XXXXX/large_file_copy.git
Running "flutter packages get" in my_app... 0.6s
exit code 0
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/KZLinkedConsole.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ColorSenseRainbow.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/BBUDebuggerTuckAway.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.180 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET sqflite OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/user/Documents/flutter/.pub-cache/git/large_file_copy-5cc22b5c6d2345ba1ab23a44324b222c68d24ab4/ios/Classes/MyPluginName.m:2:9: fatal error: 'large_file_copy/large_file_copy-Swift.h' file not found
#import < large_file_copy/large_file_copy-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Could not build the application for the simulator.
Error launching application on iPhone XS.
Exited (sigterm)
Launching lib/main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:packageDebug'.
> Failed to obtain compression information for entry
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 12s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)