Moh Say 21
Moh Say 21

Reputation: 171

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

I'm new to flutter and I'm trying to run my first project without any changes to the source code of the demo app. But I keep getting the following error:

Launching lib\main.dart on SM A115F in release mode...
Running Gradle task 'assembleRelease'...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\METRO\StudioProjects\helloworld\android\app\build.gradle' line: ??

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'keystoreProperties' for SigningConfig_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signing=null, enableV4Signing=null} of type com.android.build.gradle.internal.dsl.SigningConfig.

* 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 5s
Exception: Gradle task assembleRelease failed with exit code 1

I tried everything from upgrading gradle to generating keystore even if I'm just trying to run the project, this is my 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 FileNotFoundException("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"

android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.helloworld"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName.toString()
    }
signingConfigs{
    release {
        keyAlias keystoreProperties['key']
        keyPassword keystoreProperties['key password']
        storeFile keystoreProperties['C:\\Users\\METRO\\key.jks'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['store password']
    }
}
    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}
if (project.hasProperty("MyProject.signing")
        && new File(project.property("MyProject.signing")+".gradle").exists()){
    apply from: project.property("MyProject.signing")+".gradle"
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()){
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

And this is my keystore.properties file :

storePassword = store password
keyPassword = key password
keyAlias = key
storeFile = C:\\Users\\METRO\\key.jks

Note: android studio highlights warnings in front of storePassword,keyPassword,keyAlias as unused properties. Is this is the problem ? If it is, how to solve it ? PLEASE help.

Upvotes: 17

Views: 22835

Answers (5)

David oteng
David oteng

Reputation: 1

You need to type the full path

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



 signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties["storeFile"] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

And keep the content like this

keyAlias=xxx
keyPassword=xx
storeFile=xx.ks
storePassword=xx

Upvotes: 0

hgiahuyy
hgiahuyy

Reputation: 308

Folder /app/build.grade (add code below)

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

End edit continue

buildTypes {
    release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.release <-- 

    }
}

And add

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}

Upvotes: 1

Elmar
Elmar

Reputation: 4397

You probably missing this block inside project/android/app build.gradle file:

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

It should be just before Android block: enter image description here

Upvotes: 28

Abdul Majid
Abdul Majid

Reputation: 127

follow the steps and you will get rid of the problem:

Flutter signing the application

You probably have misconfigured the file and the credentials too.

Upvotes: 2

berkaykurkcu
berkaykurkcu

Reputation: 495

You seem to have misconfigured your app\build.gradle file and used double back slashes on your keystore.properties.

Add this at the end of your localProperties instead of the bottom of that file.

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

Change your

signingConfigs{
    release {
        keyAlias keystoreProperties['key']
        keyPassword keystoreProperties['Kha128256512$']
        storeFile keystoreProperties['C:\\Users\\METRO\\key.jks'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['Kha128256512$']
    }

to

signingConfigs {            
      release {
                    keyAlias keystoreProperties['keyAlias']
                    keyPassword keystoreProperties['keyPassword']
                    storeFile keystoreProperties['storeFile'] ? 
                    file(keystoreProperties['storeFile']) : null
                    storePassword keystoreProperties['storePassword']
       }

and run this on Terminal

keytool -genkey -v -keystore c:\Users\YOUR_PREFERRED_LOCATION\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

and make sure you set your location like this in your key.properties file

storeFile=c:/Users/YOUR LOCATION/upload-keystore.jks

Upvotes: 23

Related Questions