No signature of method: .android() is applicable for argument types. Exception in build.gradle (app)

Viewed 66735
  • Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'

Caused by: groovy.lang.MissingMethodException: No signature of method: build_h12dou32x8mktsbcdinr8fpc.android() is applicable for argument types: (build_h12dou32x8mktsbcdinr8fpc$_run_closure1) values: [build_h12dou32x8mktsbcdinr8fpc$_run_closure1@1630dea1]

30 Answers

I had the same issue when migrating to the AGP 7.0 when moving from aaptOptions to androidResources.

For me it was enough to replace

androidResources {
   noCompress '...'
}

with

aaptOptions {
   noCompress '...'
}

Best way to deal with this is going in the android { ... } block and start commenting out different methods/blocks until the configuration moves past the .android() error and you'll know which block is causing it. In my case it was a deprecated method in the buildTypes { ... } block.

I recently had similar trouble. I had to rerun the project with a "build.gradle" file from another project that didn't have any issues. Then I narrowed the issue down to useProguard true. The issue disappeared after I commented out useProguard true as shown below:

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        //useProguard true  <-- remove this line
        proguardFiles getDefaultProguardFile('proguard-android.txt')
    }
    debug {
        signingConfig signingConfigs.debug
    }
}

I had the same issue when migrating to the 'com.android.tools.build:gradle:7.0.0'

I removed the code:

javaCompileOptions {
            annotationProcessorOptions {
                arguments = [fragmentArgsLogWarnings: 'false']
                includeCompileClasspath true
            }
        }

here is desc about how to add it again for kapt https://github.com/sockeqwe/fragmentargs#annotation-processor-options

I fixed this error by removing 'useProguard' from app/build.gradle like so:

buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            shrinkResources true

            // useProguard true <-- removed this
            proguardFiles(
                    getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
            )
        }
    }
    

I hope that helps someone!

In my case, there was an unwanted character(a semicolon) in build.gradle(app)

I deleted that and rebuiled the project

problem solved.

I was using - (in build.gradle) "versionCode" as RN-2 (* as i was developing in React Native) then i tried "versionCode" as 3.1 but that also was throwing error then i used - versionCode 4

and this time the BUILD was SUCCESSFUL

my learning -> versionCode should be integer*

The error can have many origins. One most frequent is due to syntax typo inside build.gradle file and there's no easy way to spot it.

My suggestion. Copy the code from a working build.grade file on another project and replace the part that is throwing the error.

kotlinOptions lambda caused error in my case.

android {
...
    kotlinOptions {
        jvmTarget = "11"
    }
...
}

When I removed it - everything start to work back again.

There's no unique answer for this, except that it's a syntax typo inside build.gradle file.

My solution was to comment all elements in android {} section, sync & build and then uncomment. It worked.

I had the same issue when I removed the id 'org.jetbrains.kotlin.android.extensions' plugin from build.gradle(:app).

It was fixed by also removing

    android {
        ...
        androidExtensions {
            experimental = true
        }
        ...
    }

remove

"useProguard true"

buildTypes {
        release {
            minifyEnabled true
            //useProguard true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

I got the solution. There was a library in project having,

plugins {
    id 'com.android.library'
}

in the build.gradle file of library. I added the same,

plugins {
    id 'com.android.library'
}

in build.gradle file of app. It was causing this error. I changed it back to,

plugins {
    id 'com.android.application'
}

This solved my issue.

In my case I've commented buildTools

android {
    compileSdk 32
//    buildTools "32.1.0 rc1"
...
}

In my case I was working with productFlavors, setting up a boolean property. I forgot to surround the boolean value with apostrophes.

So I changed this

productFlavors {
    normal {
        flavorDimension "access"
        buildConfigField 'boolean', 'IS_ADMIN', false
    } 

    admin {
        flavorDimension "access"
        buildConfigField 'boolean', 'IS_ADMIN', true
    }
}

to this

productFlavors {
    normal {
        flavorDimension "access"
        buildConfigField 'boolean', 'IS_ADMIN', 'false'
    } 

    admin {
        flavorDimension "access"
        buildConfigField 'boolean', 'IS_ADMIN', 'true'
    }
}

I had this error No signature of method: build_eux4i9fuz78eb5ojbn76y01n5.android() is applicable for argument types

It was fixed by changing

buildFeatures {
    dataBinding true
}

to

dataBinding {
    enabled = true
}

I believe the error is the cause of version conflicts between kotlin plugin version and gradle version.

I just created a new project and added dependencies, and this error occurred.

In my case the problem was namespace 'com.appName.packageName.app' line in build.gradle file. Deleting this helped me.

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs.kotlin'
}

android {
    namespace 'com.mathtask.app' // Delete this line
    compileSdk 32

    defaultConfig {
        applicationId "com.mathtask.app"
        minSdk 27
        targetSdk 32
        versionCode 1
        versionName "1.0"
...

An absolutely Ludicrous error being issued by Android Studio

Mind you this has been compiling absolutely fine in previous versions of AS and Gradle until I upgraded a couple of days ago.

I had accidentally in one of my modules typed a Capital letter (many months ago mind you) as follows ;

DefaultConfig {
    minSdkVersion 25
    targetSdkVersion 30
}

After so many hours of searching and trying various things I just happened to spot it.

defaultConfig {
    minSdkVersion 25
    targetSdkVersion 30
}

The above resolved the issue.

DefaultConfig -> defaultConfig

I fix this error by changing version code to less than 6. using 7 onwards will exist this error.

In my case I defined flavorDimensions using kotlin style instead of groovy

flavorDimensions += listOf("api", "mode")

Fixed it this way

flavorDimensions += ["api", "mode"]

In my case i could fix it commenting the : MultiDexEnable value on android.defaultConfig

For me, I changed build:gradle.7.1.2 to 4.1.0 and work very good

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

to

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

I do that:

buildTypes {
    release {

        /**
         * Enables code shrinking, obfuscation, and optimization for only
         * your project's release build type.
         * */
        minifyEnabled true

        /**
         * Enables resource shrinking, which is performed by the
         * Android Gradle plugin.
         * */
        shrinkResources true

        /**
         * Includes the default ProGuard rules files that are packaged with
         * the Android Gradle plugin. To learn more, go to the section about
         * R8 configuration files.
         * */
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        /**
         * Enables code shrinking, obfuscation, and optimization for only
         * your project's release build type.
         * */
        minifyEnabled true

        /**
         * Enables resource shrinking, which is performed by the
         * Android Gradle plugin.
         * */
        shrinkResources true

        /**
         * Includes the default ProGuard rules files that are packaged with
         * the Android Gradle plugin. To learn more, go to the section about
         * R8 configuration files.
         * */
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

    }
}

This error is a bit misleading. A simple typo can cause this error

enter image description here

I just had the spelling of "multidexEnabled" wrong.

For me, when I was downgrading the GradleVersion and some dependencie, I had to remove this line from build.gradle (:app)

android {
...
    namespace 'com.yourpackagename' <-- delete this line
...
}

It usually happens during upgrading process of very old project and when some gradle file parts edited manually and there is a mismatch. It is very time consuming and sometimes very painful to find what is the exact problem as generated errors may not even correctly indicate the issue.

One complex solution is to create new project with exact same package name and then copy-paste working-logic part into that project. This is easier solution as when we create new project all gradle, sdk, dependecies automatically created.

It happened with my Flutter project upgrade and managed to solve the issue only this way.

I'm facing this problem because of jackOptions.I solve this to remove bellow code from android:

jackOptions {
            enabled true
        }

in my case, it was storeFile value. following work fine for me.

storeFile keystoreProperties['storeFileUpload'] ? file(keystoreProperties['storeFileUpload']) : null

In my case I had to remove this:

  proguardFile getDefaultDexGuardFile('dexguard-debug.pro')
Related