Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter, sign with both debug keys and release keys on Android

I followed the instructions to build release for Android and it was successful. https://flutter.io/docs/deployment/android#configure-signing-in-gradle

However, this project is open source and without the keys.properties file it will fail to build. This means that contributors are unable to run the project.

How do I setup build.gradle to sign debug with debug keys when doing a --debug or --profile build and with release keys from keys.properties with a --release build?

like image 437
Luke Pighetti Avatar asked Dec 13 '18 17:12

Luke Pighetti


People also ask

What is the difference between debug mode and profile mode?

Use debug mode during development, when you want to use hot reload. Use profile mode when you want to analyze performance.


1 Answers

this will use release keys only if the key.properties file exists

signingConfigs {
    release {
        if (keystorePropertiesFile.exists()) {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
}

buildTypes {
    release {
        if (keystorePropertiesFile.exists()) {
            signingConfig signingConfigs.release
            println "Signing with key.properties"
        } else {
            signingConfig signingConfigs.debug
            println "Signing with debug keys"
        }
    }
}
like image 123
Luke Pighetti Avatar answered Nov 15 '22 09:11

Luke Pighetti