Reputation: 850
I am trying to generate appbundle
using flutter build appbundle --release
, when i run the command it throws following errors.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:signReleaseBundle'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Failed to read key upload from store "/android/app/key.jks": Invalid keystore format
For signing the app, I followed the Flutter Official Documentation for Android
my app/build.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
}
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.batuwacab"
minSdkVersion 20
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
}
}
}
...
I have stored key.jks
in android/app
and used this command to generate key.jks
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
Thanks in Advance.
Upvotes: 1
Views: 3337
Reputation: 204
As per official Flutter guide,
The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12.
So, I would guess that during building the compiler is expecting JKS type file while you by default have created PKCS12 type file as you omitted -storetype tag while generating it. So simply remove ".jks" from storefile = "/android/app/key.jks" in your key.properties as well as from the file extension of the keystore file key.jks.
Further, you could provide .p12 or .pfx as file extension for PKCS12 type keystore, but I have tested for file without extension and the build was successful.
Also, not related to this question, but related to PKCS12 keystore: My build was failing with "given-final-block-not-properly-padded" error. Problem was in key.properties file I had different passwords for storePassword and keyPassword.
While generating PKCS12 type keystore file, keytool asks for only storePassword and it seems same password is applied to keyPassword as well. So in key.properties when I used same passwords for both, then the build was successful.
Upvotes: 1
Reputation: 688
I think your problem could be the -storetype option, it is missing in your keytool command line. Here follow mine that is working.
keytool -genkey -v -keystore upload-keystore.jks
-storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload
I think in same point this line changed, and you are using the old one.
Upvotes: 5