FAILURE: Build failed with an exception.
-
Where:
Build file ‘/Users/1726mohitraj/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle’ line: 31 -
What went wrong:
A problem occurred evaluating project ‘:audioplayers_android’.
No signature of method: build_91u1y9cmlwptitkd488tz946b.android() is applicable for argument types: (build_91u1y9cmlwptitkd488tz946b$_run_closure2) values: [build_91u1y9cmlwptitkd488tz946b$_run_closure2@745e6edd]
code in ‘/Users/1726mohitraj/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle’ :
group 'xyz.luan.audioplayers'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.7.10'
ext.coroutines_version = '1.6.4'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1"
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'de.mannodermaus.android-junit5'
android {
compileSdk 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lint {
disable 'InvalidPackage'
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
dependencies {
implementation "androidx.core:core-ktx:1.9.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testImplementation 'org.assertj:assertj-core:3.23.1'
}
repositories {
mavenCentral()
}
I tried to comment out each line in android{…} and run the project but then also it doesn’t work. I also tried to Invalidate caches and restart the project but still didn’t get any output.
2
Answers
Remove following code from android Tag in Build.gradle file which is located at /Users/1726mohitraj/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle
After that save gradle file and re run your project. If doesn’t work then try to comment in android Tag line by line and save and re run project until it works. This way you will be able resolve your issue.
This issue appears because the project you are working on has an old version of Android Gradle Plugin (AGP). Lots of Flutter plugins started to update their Android part to support recent releases of AGP. Namely, since Android Gradle Plugin 8 it is required to declare a
namespace
property inbuild.gradle
file of the project: https://medium.com/androiddevelopers/5-ways-to-prepare-your-app-build-for-android-studio-flamingo-release-da34616bb946 (couldn’t link exact step mentioning this).This
namespace
property appeared only in Android Gradle Plugin 4.2. Here is an explanation in a Github issue about the samem problem you have: https://github.com/flutter/flutter/issues/125621#issuecomment-1525995461Based on that the solution to your issue is to go in
android
->build.gradle
and update Android Gradle Plugin version. I would recommend to go with something like7.4.2
as it is the last version before 8.x.x and versions 8.x.x are not fully supported by packages likeintegration_test
yet (as of May 2023).Here is how the line with AGP version looks like: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/android/build.gradle#L11
Note, if you had AGP pre 4.2 it is highly likely that to update to 7.x you would also need to update your Gradle wrapper version. Here is where you can find the line to modify Gradle wrapper version: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/battery_plus/battery_plus/android/gradle/wrapper/gradle-wrapper.properties#L3
Some Flutter plugins decided to go a way of not adding a workaround to support pre 4.2 versions of AGP and it includes Plus Plugins, where I was the person who decided that with a new major release we could encourage people to update their Android native part of the project to benefit from all the improvements Google and Gradle teams are working on.