简体   繁体   English

Flutter插件无法在Android下运行

[英]Flutter plugins not working under Android

In my Flutter App, I make usage of many plugins. 在我的Flutter应用程序中,我使用了许多插件。

However, there are some of them that simply won't work under Android (ie under iOS they work perfectly fine). 但是,其中有些根本无法在Android下运行(即,在iOS下它们可以正常运行)。

Inside pubspec.yaml File I have the following list of packages that I intend to use in my Flutter app. pubspec.yaml文件中,我具有以下打算在Flutter应用中使用的软件包列表。

The ones commented-out do not work under Android ! 被注释掉的那些在Android下不起作用!

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.2+1
  sqflite: ^1.1.5
  intl: ^0.15.8
  tuple: ^1.0.2
  material_design_icons_flutter: ^3.2.3695
  launch_review: ^2.0.0
  fit_image: ^0.1.2
  datetime_picker_formfield: ^0.1.8
  flutter_screenutil: ^0.5.2
  path_provider: ^1.1.0
  # image_picker: ^0.6.0+8
  # url_launcher: ^5.0.2
  # permission_handler: ^3.1.0
  # flutter_downloader: ^1.1.7
  large_file_copy: ^0.0.1
  flutter_localizations:
    sdk: flutter
  cupertino_icons: ^0.1.2

I work with Android SDK 28 我使用Android SDK 28

My Flutter project, I create with: 我使用以下方法创建的Flutter项目:

flutter create --org ch.myorg -i swift -a kotlin <my_app_name>

How can I get these packages to work under Android ???? 我如何才能使这些软件包在Android下工作?

  image_picker: ^0.6.0+8
  url_launcher: ^5.0.2
  permission_handler: ^3.1.0
  flutter_downloader: ^1.1.7

I did the following trials: 我做了以下试验:

  • typed flutter clean flutter clean
  • typed flutter packages get 键入的flutter packages get
  • opened Android Studio to see if it cleans the bugs - but no chance 打开Android Studio看看是否可以清除错误-但没有机会
  • migrated to AndroidX (but this is the biggest mess you can imagine since corrupting the other packages that worked fine before the migration) 迁移到AndroidX(但这是您可以想象的最大混乱,因为在迁移之前破坏了其他可以正常工作的软件包)
  • I created a completely new Flutter project and added no code whatsoever (ie work with the hello-world app) and keep adding packages to the pubspec.yaml file to see which packages crash the Android version. 我创建了一个全新的Flutter项目,不添加任何代码(即与hello-world应用程序一起使用),并继续将软件包添加到pubspec.yaml文件中,以查看哪些软件包使Android版本崩溃。 Then for the first one crashing, I try to step back versions in order to find any package-version that might not crash. 然后对于第一个崩溃,我尝试回退版本,以便找到可能不会崩溃的任何软件包版本。 But this is like finding a needle in a haystack... No chance either... 但这就像在大海捞针中...也不可能...
  • I went to get the package-creator's GitHub project and tried their example app (ie each package has an example) - but the same issue: Android does not work ! 我去了包创建者的GitHub项目,并尝试了他们的示例应用程序(即每个包都有一个示例)-但存在相同的问题:Android无法正常工作!
  • I created a completely new Flutter app and took the main.dart content of a package-provider-example main.dart code (in order to have all the android\\local.properties etc. in a correct state given by the flutter create) and then I added the pubspec.yaml content form the package also into the new flutter app in order to get the necessary dependency. 我创建了一个全新的Flutter应用,并获取了包提供者示例main.dart代码的main.dart内容(以使所有android \\ local.properties等处于flutter创建的正确状态),然后我将包中的pubspec.yaml内容也添加到了新的flutter应用中,以获取必要的依赖关系。 But same, thing: Android does not work !! 但是同样的事情:Android无法正常运行! (iOS works always..) (iOS始终可以运行。)
  • I uninstalled Android Studio and re-installed it. 我卸载了Android Studio,然后重新安装了它。 I uninstalled Flutter and Dart and re-installed it. 我卸载了Flutter和Dart并重新安装了它。 No effect... 没有效果...

I am more than desperate to get this to work since I lost 6 days so far trying to get these Flutter packages to run under Android... :( 我非常想让它正常工作,因为到目前为止我已经丢失了6天,试图让这些Flutter程序包在Android下运行... :(

Any help highly appreciated. 任何帮助,高度赞赏。

Here is my flutter doctor -v output: 这是我的flutter doctor -v输出:

flutter doctor -v
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale
    en-CH)
    • Flutter version 1.5.4-hotfix.2 at /Users/user/Documents/flutter
    • Framework revision 7a4c33425d (4 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)


[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/user/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.34.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.0.2

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API
      28) (emulator)

• No issues found!

Here is an example of getting one single package to work under Android - my trial is with file_downloader ( Link to package definition ): 这是使一个软件包在Android下运行的示例-我的试用是file_downloader链接到软件包定义 ):

Below you find the cryptic error log when I try with the file_downloader package: 当我尝试使用file_downloader软件包时,在下面可以找到神秘的错误日志:

Step 1 : create a completely new Flutter project with flutter create --org com.myorg -i swift -a kotlin testy 步骤1:使用flutter create --org com.myorg -i swift -a kotlin testy创建一个全新的Flutter项目flutter create --org com.myorg -i swift -a kotlin testy

Step 2 : fill in the package-dependencies inside the pubsep.yaml file (ie taken from the package-example). 第2步:pubsep.yaml文件中填写包依赖关系(即从package-example中获取)。 Here are the dependencies for this package example: 这是此程序包示例的依赖项:

dependencies:
  flutter:
    sdk: flutter
  path_provider: ^0.4.0
  permission_handler: ^3.0.0
  flutter_downloader: ^1.1.7
  cupertino_icons: ^0.1.2

Step 3 : Keep the main.dart as the default "hello world" app (ie what is there after flutter create...) 第3步:将main.dart保留为默认的“ hello world”应用程序(即在创建flutter之后有什么...)

Therefore we only changed a few pubspec.yaml dependencies in comparison with a fresh new Flutter create app. 因此,与全新的Flutter create应用程序相比,我们仅更改了一些pubspec.yaml依赖项。 And the dependecies is what the package-provider suggests in his/her example ! 包提供者在他/她的示例中所暗示的就是依赖!

The "hello world" App works fine under Android & iOS. “ hello world”应用程序可以在Android和iOS上正常运行。 However, adding a few pubspec.yaml dependencies makes the Android crash (iOS works fine)... 但是,添加一些pubspec.yaml依赖关系会使Android崩溃(iOS可以正常运行)...

Here is the error log when Android is launched: 这是启动Android时的错误日志:

* Error running Gradle:
ProcessException: Process "/Users/user/Flutter_applications/01_MyOwn_Flutter_apps/testy/android/gradlew" exited abnormally:
Starting a Gradle Daemon, 5 stopped Daemons could not be reused, use --status for details


FAILURE: Build failed with an exception.

* Where:
Script '/Users/user/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 200

* What went wrong:
A problem occurred configuring project ':flutter_downloader'.
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':flutter_downloader' of type org.gradle.api.Project.
   > Could not find method debugProvided() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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 7s
  Command: /Users/user/Flutter_applications/01_MyOwn_Flutter_apps/testy/android/gradlew app:properties

Exited (sigterm)

Other packages deliver slightly different errors. 其他软件包提供的错误略有不同。 But it is always something with a gradle-issue or an android-incompatibility. 但这总是带有gradle-issue或android-incompatibility的东西。 What Android version do I need to install ? 我需要安装哪个Android版本? Isn't the newest stable one the best option ?? 最新的稳定器不是最佳选择吗? How do I find out which package-versions fit which Android-version ? 如何找出适合哪个Android版本的包版本? How can I match the two ??? 我该如何匹配两者??? (and still keep all my other packages running). (并仍然保持我所有其他软件包的运行状态)。

After my odyssey, I wonder, isn't Flutter a bit of a mess if it comes to Android dependencies ??? 在我的冒险旅行之后,我想知道,如果涉及到Android依赖项,Flutter不会有点混乱吗?

Any suggestion on how to deal with these kind of problems are highly appreciated. 任何有关如何处理此类问题的建议都将受到高度赞赏。 How do you proceed normally with Flutter packages and Android compatibility ??? 如何正常使用Flutter软件包和Android兼容性?


Or here another example with image_picker package ( coming from Flutter Team here ): 或者这里是另一个带有image_picker包的示例( 来自Flutter Team ):

Steps 1-3 are the same as above. 步骤1-3与上述相同。 All I do is creating a hello-world Flutter app and adding the dependencies as stated in the package-example: 我要做的就是创建一个hello-world Flutter应用程序,并按照package-example中的说明添加依赖项:

Here the image_picker dependencies: 这里是image_picker的依赖项:

dependencies:
  flutter:
    sdk: flutter
  video_player: 0.5.2
  image_picker: ^0.6.0+8
  cupertino_icons: ^0.1.2

And here the Android Error: 这是Android错误:

* Error running Gradle:
ProcessException: Process "/Users/user/Flutter_applications/01_MyOwn_Flutter_apps/testy/android/gradlew" exited abnormally:

FAILURE: Build failed with an exception.

* Where:
Script '/Users/user/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 200

* What went wrong:
A problem occurred configuring project ':image_picker'.
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':image_picker' of type org.gradle.api.Project.
   > Could not find method debugProvided() for arguments [file collection] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* 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 0s
  Command: /Users/user/Flutter_applications/01_MyOwn_Flutter_apps/testy/android/gradlew app:properties

Please review your Gradle project setup in the android/ folder.
Exited (sigterm)

I FINAAALLY FOUND A SOLUTION: 我终于找到了一个解决方案:

The next three steps show how to get two out of the four remaining dependencies up-n-running. 接下来的三个步骤显示了如何从n个正在运行的其余四个依赖中获取两个。

At the bottom, there is more Android Studio steps to go through (mixed with some prayers and manual steps) to finally get all four buggers up-n-running !!! 在底部,还有更多要执行的Android Studio步骤(混合了一些祈祷和手动步骤),最终使所有四个bug专家处于“ n-running”状态!

Here the flutter cleanup-steps that were needed: (no idea when, why and where it went corrupt in the first place !): 这是需要的抖动清除步骤:(首先不知道它何时,为什么以及在哪里损坏!):

Step 1 : Inside my flutter SDK install folder, I typed into a terminal: 步骤1:在flutter SDK安装文件夹中,输入一个终端:

git clean -xfd

git stash save --keep-index

git stash drop

git pull

flutter doctor

Step 2 : Inside my flutter app folder, I did also type in the terminal: 步骤2:在我的flutter应用文件夹中,我也输入了终端:

flutter packages pub cache repair

Step 3 : Inside Visual-Studio-Code, I also did a Flutter deinstall and Dart deinstall. 第3步:在Visual Studio代码内部,我还做了Flutter卸载和Dart卸载。 And re-installed the two. 并重新安装两个。 I restarted Visual-Studio-Code. 我重新启动了Visual Studio代码。

Having completed these three steps, I get two out of 4 dependencies back alive and my Android "hello world" app at least compiles (except for the last two buggers). 完成这三个步骤后,我又恢复了4个依赖关系中的2个,并且我的Android“ hello world”应用程序至少可以编译(最后两个错误除外)。 The two buggers still not working under Android are commented-out in the following pubspec.yaml dependency list : 以下pubspec.yaml依赖项列表中已注释掉在Android下仍无法使用的两个pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.2+1
  sqflite: ^1.1.5
  intl: ^0.15.8
  tuple: ^1.0.2
  material_design_icons_flutter: ^3.2.3695
  launch_review: ^2.0.0
  fit_image: ^0.1.2
  datetime_picker_formfield: ^0.1.8
  flutter_screenutil: ^0.5.2
  path_provider: ^1.1.0
  image_picker: ^0.6.0+8
  url_launcher: ^5.0.2
  # permission_handler: ^3.1.0
  # flutter_downloader: ^1.1.7
  large_file_copy: ^0.0.1
  flutter_localizations:
    sdk: flutter
  cupertino_icons: ^0.1.2

For the two dependencies (ie permission_handler and flutter_downloader ), I now get a new error when trying to build for Android: 对于这两个依赖项(即permission_handlerflutter_downloader ),现在尝试为Android构建时出现一个新错误:

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* 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 3s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
*******************************************************************************************
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

Now I am back to the need for AndroidX migration, it seems. 现在看来,我回到了AndroidX迁移的需求。 But I really fear of doing that since it corrupts all the other nicely working packages. 但是我真的很害怕这样做,因为它会破坏所有其他运行良好的程序包。

What do you suggest to do here as for the error message ?? 对于错误消息,您建议在这里做什么? How do I get the last two packages to work as well (next to all the other packages) ??? 如何使最后两个软件包也能正常工作(所有其他软件包旁边)?


Here is a solution to the last two buggers: 这是最后两个错误的解决方案:

Step A : Open Android Studio 步骤A:打开Android Studio

This can best be done inside VSCode by right-clicking the /android folder inside your Flutter project and selecting Open in Android Studio 最好在VSCode中完成此操作,方法是右键单击Flutter项目中的/ android文件夹,然后选择Open in Android Studio

在此处输入图片说明

Step B : Press the Make Project hammer inside Android Studio to cause some Android Studio checkups to run... 步骤B:在Android Studio中按Make Project锤,以使某些Android Studio检查运行。

在此处输入图片说明

Step C : Wait and pray (so that Android Studio makes the magic cleansing) 步骤C:等待并祈祷(以便Android Studio进行魔术清洗)

It turns out that Android Studio does not really grasp all mistakes as for the package compatibilities. 事实证明,Android Studio并不能真正解决所有软件包兼容性方面的错误。 Therefore, I went through all Gradles and checked manually for... 因此,我浏览了所有Gradles并手动检查了...

a) newest build.gradle version (ie hovering over any grey'isch gradle line by the mouse will show the newest version and you can change manually accordingly) a)最新的build.gradle版本(即,将鼠标悬停在任何grey'isch gradle行上将显示最新版本,您可以相应地手动更改)

b) newest Kotlin version (to find out which Kotlin version is the newest one, please go to the SDK-manager inside Android Studio and select Kotlin. This will reveal the newest version. Make sure to integrate this version in every gradle accordingly) b)最新的Kotlin版本(要找出哪个Kotlin版本是最新版本,请转到Android Studio中的SDK-manager并选择Kotlin。这将显示最新版本。请确保将此版本集成到每个gradle中)

Here is an illustration where and what to change: 这是更改位置和更改的示例:

在此处输入图片说明

And here an illustration on where to change for the newest Kotlin version : 以下是最新Kotlin版本的更改说明:

在此处输入图片说明

WITH THE ABOVE STEPS 1-3 AND STEPS AC, I ACHIEVED GETTING ALL THE DEPENCENCY PACKAGES RUNNING UNDER ANDROID. 通过上面的步骤1-3和步骤AC,我实现了在ANDROID下运行的所有防护包。

I hope that the Flutter Team will be able to make this process somewhat more transparent in the future - and I am sure they will. 我希望Flutter小组将来能够使此过程更加透明-我相信他们会做到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 插件在android phonegap中不起作用 - plugins not working in android phonegap 在Android Studio中取消选中哪些插件以及要检查哪些插件以进行抖动开发 - Which plugins to uncheck and which plugins to check in android studio for flutter development phonegap 1.7.0插件android无法正常工作 - phonegap 1.7.0 plugins android not working Flutter 插件不起作用(在通道 flutter.plugins.io/Y 上找不到方法 X 的实现) - Flutter plugins not working (No implementation found for method X on channel flutter.plugins.io/Y) Flutter Android:一个或多个插件需要更高的Android NDK版本 - Flutter Android: One or more plugins require a higher Android NDK version Java插件可在Android Studio Project中使用,但不能在Unity中使用 - java Plugins working in Android Studio Project, but not in Unity Capacitor v3 插件不适用于 android 版本 - Capacitor v3 plugins not working on android build cordova.plugins.locationManager.enableBluetooth()在android中不起作用 - cordova.plugins.locationManager.enableBluetooth() Not working in android 由于插件未自动附加到活动,Flutter Image Picker 无法正常工作 - Flutter Image Picker not working due to plugins not automatically attaching to activity flutter 嵌入 - 升级 Pre 1.12 Android 项目中断插件 - flutter embedding - Upgrading Pre 1.12 Android Projects Breaks Plugins
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM