1

Everytime I try to build my app bundle it shows me this error.

Could not get unknown property 'keystoreProperties' for project ':app' of type org.gradle.api.Project.

I have tried multiple solutions but none of them works

ref1 : https://github.com/flutter/flutter/issues/28132

ref2 : Flutter Android Studio Error: couldn't get unknown property 'keystoreProperty'

ref3 : https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#generated-project-files-outdated

this is my 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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
    // compileSdkVersion flutter.compileSdkVersion
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    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.bot_write"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "androidx.multidex:multidex:2.0.1"
}

this is my key.properties file

keyAlias=upload
keyPassword=password
storeFile=d:/keystores/notesapp/upload-keystore.jks
storePassword=storepass

I have tried other stack overflow answers but none of them works. some solutions I have tried

  1. changing folder from d: to c:
  2. changing forward slash for path
storeFile=d:\keystores\botwrite\upload-keystore.jks
storeFile=c:\Users\upload-keystore.jks
storeFile=d:/keystores/notesapp/upload-keystore.jks
  1. running flutter packages pub cache repair
  2. running flutter clean and flutter pub get
  3. running flutter build appbundle

my android folder enter image description here

2 Answers2

1

You can generate the apk by opening the project in android studio :

enter image description here

Rahul Variya
  • 1,257
  • 1
  • 6
  • 15
  • Thank you this is a good workaround. But it didn't solve actual problem. If anyone else have this same problem do this (reset your previous setup : i.e. key.properties file and all other related files) 1. If you are using vscode right click on android folder > click "open in android studio" 2. next Click > Build > Generate Signed Bundle / apks 3. next follow these steps : https://developer.android.com/studio/publish/app-signing?authuser=2#sign-apk – AbdulHaseeeb Jan 24 '23 at 07:42
0

Your build.gradle file seems to be missing line:

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key. Properties')
if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

Regards, Claudio