Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not get unknown property 'flutter' for extension 'android'

I got this issue suddenly as i didn't update or change any code or package

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/amitbahadur/.pub-cache/hosted/pub.dev/geolocator_android-4.6.2/android/build.gradle' line: 29

* What went wrong:
A problem occurred evaluating project ':geolocator_android'.
> Could not get unknown property 'flutter' for extension 'android' of type com.android.build.gradle.LibraryExtension.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':geolocator_android'.
> Failed to notify project evaluation listener.
   > Cannot invoke method substring() on null object
   > com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Error: Gradle task assembleDebug failed with exit code 1

i tried downgrading and upgrading the geolocator package and also update the flutter but still not working

like image 823
Amit Bahadur Avatar asked Oct 25 '25 14:10

Amit Bahadur


2 Answers

If you are using Flutter 3.24.4 or familiar, let downgrade to 4.6.1 or override it.

dependency_overrides:
  geolocator_android: 4.6.1
like image 133
Kiều Phong Avatar answered Oct 27 '25 04:10

Kiều Phong


I was upgrading a very old project from flutter 3.0.2 to a newer version and decided to upgrade to the latest version possible (3.29.0 at this time).

What worked for me was removing this from the build.gradle:

   flutter {
       source '../..'
   }

and then going directly to the dependency (Geolocator 5.0.1+1 in my case) folder android/build.gradle and directly giving it version numbers:

android {
    if (project.android.hasProperty("namespace")) {
        namespace("com.baseflow.geolocator")
    }
    compileSdkVersion 34

    // compileSdk flutter.compileSdkVersion

    defaultConfig {
        // minSdkVersion flutter.minSdkVersion
        minSdkVersion 26
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

What the error says is that it isn't recognizing "flutter" and that's because of the flutter.xversion type of code. It will probably be fixed in the dependency itself in the future, but that's what worked for me.

like image 31
Angel Aquino Avatar answered Oct 27 '25 02:10

Angel Aquino