Unable to get Flutter Add to App working with plugins

3.5k Views Asked by At

I have a Flutter module and I'm trying to add it to my native Android app. I have tried both the AAR approach and the source code approach.

When I try building the AAR, I run the flutter build aar command. I get a long output, but this seems to be the error message:

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.

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:

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. This time I get errors saying that it can't find the Flutter classes. I tried adding the flutter.jar to my project, but that didn't make a difference.

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 (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. This definitely doesn't fix anything, but at least I could make a release build.

2

There are 2 best solutions below

0
On

Please try adding this to your flutter app -> 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
}

To know more check this.

0
On

Replace all the file app -> android -> settings.gradle with this :

    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
    }