Reputation: 10930
I'm trying to deploy my Flutter app to Android. According to the Flutter documentation, we have to sign our apps. The first step is to create an upload keystore
. There are two ways to do this.
The first method uses Android Studio. The instructions say:
In the menu bar, click Build > Generate Signed Bundle/APK.
Here's a screenshot of Build
in Bumblebee 2021.1.1:
Where is Generate Signed Bundle/APK
?
I clicked Build > Flutter > Build App Bundle
. This ran for a while and finished without error messages.
The second method uses the CLI. You enter this (on a Mac or Linux):
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
That prompted me for a keystore password
. What is that and where do I get one?
I'm supposed to see an upload-keystore.jks
file in my home directory. Does this mean in my project's home directory or my user's home directory? I don't see that file.
Next, I'm told to
Create a file named [project]/android/key.properties that contains a reference to your keystore:
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>
What password from what previous step? And where is the key store file located?
I apologize if this is all obvious to Android users. I've always used iPhones. I bought my first Android phone yesterday and this is completely baffling to me.
Upvotes: 12
Views: 29731
Reputation: 141
1- run this command:
keytool -genkeypair -v -keystore key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
2-Create a file named key.properties
in the android directory of your project
3-Add the following lines and replace the placeholders with the values from the keystore you generated:
storePassword=toio123
keyPassword=toio123
keyAlias=key
storeFile=../app/key.jks
4-Open android/app/build.gradle and add the signing config:
android {
...
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
...
}
}
...
}
5- android/app/build.gradle above android
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
...
6- finally Run the following command:
flutter build appbundle --release
Upvotes: 14
Reputation: 31
(If anyone facing this issue currently) You need to open your project's android folder in android studio, then only you will be able to see the Generate Signed Bundle/APK option.
Upvotes: 3
Reputation: 10930
Thank you @ישו אוהב אותך. The mistake is that when you run
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
it prompts you: Enter keystore password:
It should say Create new keystore password
or Enter new keystore password
.
I made up a unique new password swordfish
and entered it. I was prompted for my name and address and then told:
Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /Users/TDK/upload-keystore.jks -destkeystore /Users/TDK/upload-keystore.jks -deststoretype pkcs12".
So apparently there's a second item that needs to be updated in the documentation.
I ran the new command and now I see a file upload-keystore.jks
in my user home directory (not in my project home directory).
I'll post a ticket with Flutter the make these two updates.
Upvotes: 11