Two ways of signing and packaging Android Studio

There are two ways of signing packaging:

Note: Signing the app we developed by ourselves represents my own copyright. If you want to upgrade in the future, you must use the same signature. The signature represents its own identity (ie keystore), and multiple apps can use the same signature.

If you don't know what the signature means, please Baidu yourself. The method of signing in eclipse is: select the project, select "export-android-export android application" in the mail,

1. Method 1: Signing through Android Studio:

Select the app module and select "Build-Generate signed apk" in the menu bar:

 

The following interface pops up:

5a3058ac-cba2-44d1-84cf-b77b246bb4d1

In the above picture, if you are using the signature for the first time, click the red box to create a new signature; if you have a signed file before, just select the blue box to import. Then I will first select the red box part:

70ae6ac4-ed0b-4938-b3f5-229dba3fea29

3b69eb78-a2bc-408b-b49f-272b46b32a31

3ef16884-13b8-453f-bad5-b9dba1a667f7

f757b8aa-277b-45f0-9afd-403adc82082c

 

In the above figure, after clicking "finish", you can see the bottom display of Android Studio: Gradle is executing a task such as assembleRelease, as shown in the following figure:

bf6076fd-480d-48b4-bb1a-e2bfee785e5e

After generating the signed apk, a prompt will pop up:

8b42d822-e3a2-4c66-aea4-6b2b4e83fef3

77cd9b25-b0f0-4f0b-85ec-c00b4e13b61b

 

2. Method 2: Signing through the command line:

(1) Load Key Store:

Let's delete the apk file signed by the first method above. Next, the second method is used to sign, that is, the command line method.

Open the Project Structure graphical interface:

03458b6c-92b8-42be-ab1d-e2c3097570eb

d6d07e96-330b-40c6-bc22-32fc37391144

In the above picture, select the app module, then switch to the singning tab, then click Add, then generate the release signature information , and then click "OK". Then do the following:

c638147d-7741-4c63-9d3a-0066ac959219

In the above figure, switch to the Build Types tab, select the Signing config as "release", and configure the release signature information just generated.

After the operation is completed, we can see that the build.gradle file of the app module has the following code in the red box:

f59c1858-e26a-41a4-96b5-f7e32eb6c8acThen execute "build-clean Project" in the menu bar:

a7af4c5b-23c2-4997-8d6f-47940c1a0f1c

(2) Generate the apk of the releasease version:

Then enter the following command in the command line Terminal: (AS has integrated the command line Terminal into the software)

gradlew assembleRelease

 

If the operation is successful, the effect is as follows:

74e21bb0-7afc-4bc6-9103-a4748f2003bf

The generated signed apk is in the following location:

b8f81109-cf7f-4649-a4da-a4bb91a3c96a

(3) Command line Terminal input command to generate apk, and also provide simple visual operation: 

  After the configuration is complete, how do we generate the APK and open the AS toolbarGradle/app/tasks/build

View Generate APK

Double click: assembleDebug ——-> Test APK

Double click: assembleRelease ——-> Official APK

So currently we use both methods to generate APK.

 

3. Why use the gradlew command instead of the gradle command:

There is a gradle folder in the HelloWorld project directory, and a gradle-wrapper.properties file in the gradle/wrapper directory, open it:

c5bb106f-081e-40d8-816e-ea04a4814977

The above figure represents the version information of gradle that the HelloWorld project depends on. The red line in the above figure indicates that if there is no gradle in our project, the software will download gradle according to this url, and finally know why it is so slow when opening AS for the first time, right?

If we execute the gradlew command, it actually executes the gradle wrapper above, and then finds the gradle 2.2.1 we have downloaded. If there are many projects now, but the gradle version of each project is different, I have to configure each version of gradle into the environment variable, and executing the gradlew command will avoid this trouble.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326077492&siteId=291194637