This is the 25th article of the [Android Tutorial Series]. If you find it useful, please pay attention to the column.
Android Studio version: Arctic Fox 2020.3.1 Pathc 3, here I created a new Android project, and the rest can be done by following the steps.
Article directory
One: Generate keystore signature file
Step 1 Click in turn Build - Generate Signed Bundle/Apk...(生成签名)
Step 2 Select the APK option, click the button Next to go to the next
step Step 3 Select a new key store (key store)
Step 4 Create a new key store according to the following prompts
The suffix name here is designated as jks, just to make it easy to see that this is signed by Android Studio, you can also specify the suffix name as keystore.
If you click ok and it prompts an error, 警告:PKCS12 密钥库不支持其他存储和密钥命令,正在忽略用户指定的-keypass值。
it may be that the password of your key store and the password of the alias are inconsistent.
Then the following jks file will be generated in the path you specify.
When you create a new key store, it will automatically return to the following interface, and automatically fill in the password of your new key store, as well as its alias and alias password, as shown in the figure below. The
last step , click the Finish button and wait for Android Studio to automatically build Application signature.
The prompt as shown in the figure below is that the construction of the application signature is successful.
Two: Obtain the configuration information of the keystore signature file
Execute the following command in the terminal
keytool -list -v -keystore 你的 keystore 文件的绝对路径
After entering the keystore password, you can see the configuration information of the keystore signature file on the terminal. As shown in the figure below
, the value of SHA1 needs to be used when we apply for a third-party SDK (such as WeChat payment). Other configuration information The parameters have Chinese interpretation, and everyone can see it at a glance.
Three: Configure/add the signature information of build.gradle
So far, we have only generated the keystore, if you want to add it to the project, you need to configure it in the project's build.gradle
file .
Click one by File - Project Structure - Module - app - Signing Configs
one, as shown in the figure below.
After clicking the button ok, Android Studio will automatically add the signature information to the build.gradle
module , as shown in the figure below.
Currently it is the signature in debug mode. If you want to add the signature in release mode, you need File - Project Structure - Module - app - Signing Configs
to click Add in button,
The newly added configuration name is set to release, and then enter the keystore path, alias, password and other information. After configuration, as shown in the figure below
, the newly added release signature and the previous debug signature information are different except for the name. Everything else is the same, so you can also copy the debug signature directly, and then change the signature name. Here is just the process of adding signature information.
Four: Verify whether the signature is successful
In the first step, after generating the signature, we also app - release
generated a release version of the apk package in the folder, as shown
in the following figure. Use the command in the terminal
keytool -printcert -jarfile 安装包路径.apk
As shown in the picture below Has
your problem been solved? Welcome to leave a message in the comment area.
Give someone a rose, and there is a lingering fragrance in your hand. If you think the article is good, I hope you can give a one-click three-link, thank you.
Technology is accumulated little by little, and God cannot be achieved in a day. Staying still is going backwards, so make a little bit of progress every day.
concluding remarks
Finally, a motto is attached: "I am eager to learn, but humble as a fool", and I hope to encourage each other.