[The 25th part of the Android tutorial series] How to use Android Studio to generate a keystore signature file

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.

One: Generate keystore signature file

Step 1 Click in turn Build - Generate Signed Bundle/Apk...(生成签名)
insert image description here
Step 2 Select the APK option, click the button Next to go to the next
insert image description here
step Step 3 Select a new key store (key store)
insert image description here
Step 4 Create a new key store according to the following prompts
insert image description here

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值。
insert image description here
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.
insert image description here
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
insert image description here
last step , click the Finish button and wait for Android Studio to automatically build Application signature.
insert image description here
The prompt as shown in the figure below is that the construction of the application signature is successful.
insert image description here

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
insert image description here
, 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.gradlefile .

Click one by File - Project Structure - Module - app - Signing Configsone, as shown in the figure below.
insert image description here
After clicking the button ok, Android Studio will automatically add the signature information to the build.gradlemodule , as shown in the figure below.
insert image description here
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 Configsto 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
insert image description here
, 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 - releasegenerated a release version of the apk package in the folder, as shown
insert image description here
in the following figure. Use the command in the terminal

keytool -printcert -jarfile 安装包路径.apk

As shown in the picture below Has
insert image description here
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.


concluding remarks

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.

Finally, a motto is attached: "I am eager to learn, but humble as a fool", and I hope to encourage each other.

Guess you like

Origin blog.csdn.net/qq_42351033/article/details/122279278
Recommended