Romanch haque
Romanch haque

Reputation: 104

flutter . When I'm trying run this commend "flutter build appbundle" I get this error

I am trying to build a app with flutter . When I'm trying run this commend "flutter build appbundle" I get this error :

FAILURE: Build failed with an exception.

  • Where: Build file 'F:\azabaza_app\myapp\android\app\build.gradle' line: 28

  • What went wrong: A problem occurred evaluating project ':app'.

Could not get unknown property 'compileSdkVersion' for extension 'flutter' of type FlutterExtension.

  • 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 828ms Running Gradle task 'bundleRelease'...
1,536ms Gradle task bundleRelease failed with exit code 1

My android/app/build.gradle file:

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
    compileSdkVersion flutter.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "io.flutter.examples.flutter_view"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

}
flutter {
    source '../..'
}
dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
}

Upvotes: 0

Views: 3566

Answers (2)

Anna
Anna

Reputation: 47

From your android/app/build.gradle file, you need to change 3 variables from your build.gradle file into to integers: compileSdkVersion which is now set to flutter.compileSdkVersion, minSdkVersion now set to flutter.minSdkVersion, and targetSdkVersion now set to flutter.targetSdkVersion. They need to be replaced with latest stable versions.

android {

    compileSdkVersion 31

    compileOptions {
       ...
    }

   ... ...

    defaultConfig {
        ...
        minSdkVersion 28
        targetSdkVersion 30
       ...
    }
}

The compileSdkVersion should be newest stable version. eg now is 31. The targetSdkVersion can be less or equal to compileSdkVersion, thus 30 is OK, and 31 is even better. If you don't set the targetSdkVersion, it will use the minSdkVersion.

After you make your changes, run flutter clean to remove your last previous build. Then rebuild again flutter build appbundle -v or flutter build appbundle to reflect your new changes.

Upvotes: 3

You are currently setting android the compile version to a variable that doesn't exist compileSdkVersion flutter.compileSdkVersion. The compile version is usually a hard coded number ex: compileSdkVersion 30

Upvotes: 0

Related Questions