How to fix ERROR: No signature of method: build_754ga1wplg93aizkkd14wn52w.android()

Viewed 1924

Gradle sync failed: No signature of method: build_754ga1wplg93aizkkd14wn52w.android() is applicable for argument types: (build_754ga1wplg93aizkkd14wn52w$_run_closure2) values: [build_754ga1wplg93aizkkd14wn52w$_run_closure2@4657e4e8]

The build gradle is:

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 FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

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

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

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


android {
    defaultConfig {
        minSdkVersion(15)
        targetSdkversion(29)
        multiDexEnabled = true
    }
    compileSdkVersion 30

    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 "com.example.flutter_blog"
        minSdkVersion 16
        compileSdkversion 30
        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
        }
    }
    buildToolsVersion '30.0.3'
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.1.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation("androidx.multidex:multidex:2.0.1")
    implementation 'com.google.android.material:material:1.4.0-rc01'
}

Android Studio 4.2.1 Build #AI-202.7660.26.42.7351085, built on May 10, 2021 Runtime version: 11.0.8+10-b944.6842174 amd64 VM: OpenJDK 64-Bit Server VM by N/A Windows 10 10.0 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 12 Registry: external.system.auto.import.disabled=true Non-Bundled Plugins: Dart, org.jetbrains.kotlin, io.flutter

1 Answers

This error usually occurs when you write unnecessary details in your :app build gradle.

You added two defaultconfig in android{ ... }. You have to delete the first defaultConfig.

This is how your android{ ... } looks now:

android {
    defaultConfig {
        minSdkVersion(15)
        targetSdkversion(29)
        multiDexEnabled = true
    }
    compileSdkVersion 30

    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 "com.example.flutter_blog"
        minSdkVersion 16
        compileSdkversion 30
        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
        }
    }
    buildToolsVersion '30.0.3'
}

versus how it should look:

android {
    
    compileSdkVersion 30

    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 "com.example.flutter_blog"
        minSdkVersion 16
        compileSdkversion 30
        multiDexEnabled true // Since you wanted to use multiDex this is where you put it
        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
        }
    }
    buildToolsVersion '30.0.3'
}

And also in dependencies{} change implementation("androidx.multidex:multidex:2.0.1") to implementation "androidx.multidex:multidex:2.0.1" This should solve your problem.

For anyone else having this issue thoroughly check your :app build gradle for unnecessary indentations and wrong name conventions.

Related