[英]Unable to get Flutter Add to App working with plugins
I have a Flutter module and I'm trying to add it to my native Android app.我有一个 Flutter 模块,我正在尝试将它添加到我的本机 Android 应用程序中。 I have tried both the AAR approach and the source code approach.我已经尝试过 AAR 方法和源代码方法。
When I try building the AAR, I run the flutter build aar
command.当我尝试构建 AAR 时,我运行flutter build aar
命令。 I get a long output, but this seems to be the error message:我得到一个很长的 output,但这似乎是错误消息:
Plugin project :moor_ffi not found. Please update settings.gradle.
Plugin project :connectivity_macos not found. Please update settings.gradle.
Plugin project :url_launcher_web not found. Please update settings.gradle.
However, this does actually build the debug aar, but not the release.但是,这实际上构建了调试 aar,而不是发布版本。
When I try building my app with the source code, I get this error:当我尝试使用源代码构建我的应用程序时,出现以下错误:
> Configure project :flutter
Plugin project :moor_ffi not found. Please update settings.gradle.
Plugin project :connectivity_macos not found. Please update settings.gradle.
Plugin project :url_launcher_web not found. Please update settings.gradle.
FAILURE: Build failed with an exception.
* Where:
Script '/Users/me/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 738
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.
> Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.
> Could not get unknown property 'android' for project ':app' of type org.gradle.api.Project.
I managed to get passed that error message by updating my settings.gradle to this:我设法通过将我的 settings.gradle 更新为以下内容来传递该错误消息:
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
by reading this issue https://github.com/flutter/flutter/issues/55077 .通过阅读这个问题https://github.com/flutter/flutter/issues/55077 。 This time I get errors saying that it can't find the Flutter classes.这次我收到错误消息说找不到 Flutter 类。 I tried adding the flutter.jar to my project, but that didn't make a difference.我尝试将 flutter.jar 添加到我的项目中,但这并没有什么不同。
Any help would be appreciated.任何帮助,将不胜感激。 I've been working on this all day and am about out of ideas.我整天都在做这件事,几乎没有主意了。
Here is my flutter doctor output:这是我的 flutter 医生 output:
[✓] Flutter (Channel beta, 1.18.0-11.1.pre, on Mac OS X 10.15.4 19E287, locale en-US)
• Flutter version 1.18.0-11.1.pre at /Users/me/flutter
• Framework revision 2738a1148b (2 weeks ago), 2020-05-13 15:24:36 -0700
• Engine revision ef9215ceb2
• Dart version 2.9.0 (build 2.9.0-8.2.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/me/Library/Android/sdk
• Platform android-29, build-tools 29.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_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.5, Build version 11E608c
• CocoaPods version 1.8.4
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.8052
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.45.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.2
UPDATE更新
The only way I managed to get this to work was to downgrade to an older version of Flutter. I was able to get it working on the beta channel, v1.14.6.我设法让它工作的唯一方法是降级到旧版本 Flutter。我能够让它在 beta 通道 v1.14.6 上工作。 This definitely doesn't fix anything, but at least I could make a release build.这绝对不能解决任何问题,但至少我可以制作一个发布版本。
Please try adding this to your flutter app -> android -> settings.gradle请尝试将此添加到您的 flutter 应用 -> android -> settings.gradle
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
Replace all the file app -> android -> settings.gradle with this:将所有文件 app -> android -> settings.gradle 替换为:
include ':app'
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
}
plugins.each { name, path ->
def pluginDirectory =
flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.