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:
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:
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:
After generating the signed apk, a prompt will pop up:
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:
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:
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:
Then execute "build-clean Project" in the menu bar:
(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:
The generated signed apk is in the following location:
(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
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:
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.