Home > other >  Could not find method flutter()
Could not find method flutter()

Time:03-04

I am trying to open my app in android emulator on macos but I'm getting following error

* Where:
Build file '/Users/home/app_sources/my_app/android/app/build.gradle' line: 63

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method flutter() for arguments [build_enl1wb3rxbgojqnsmrkb1pqib$_run_closure3@4a124cf3] on project ':app' of type org.gradle.api.Project.

Also if I try to Open Android module in Android Studio

ONE

When it opens there is no configuration

two

When I try to add configuration there is no module to select

three

I've been facing this issue for past 3 days and trust me I've tried every topic on this website, every article on this matter nothing worked, so please don't suggest google search because I've done that a lot!

Note:

  1. Using Sync Project with Gradle Files return same error as above
  2. Using Invalidate Caches doesn't help either.
  3. Comment include ':app' in settings.gradle and sync, again uncomment and sync doesn't help either.

Any idea?

UPDATE

settings.gradle

include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

android/build.gradle

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs  = 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "xxx.xxx.xxx.xxx"
        minSdkVersion 19
        targetSdkVersion 32
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

CodePudding user response:

You need to update the build.gradle from

def localPropertiesFile = rootProject.file('local.properties')

to

def localPropertiesFile = new rootProject.file('local.properties')

Will solve u r problem.

CodePudding user response:

Solved

I've removed Flutter SDK and Dart SDK from my system and re-install them then error gone away.

PS: I have no idea why this happened or why clean install solved the problem (specially that my installed version was the same version as this clean install) but it did the trick, that's all I know.

  • Related