Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to sign applications in Android

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to sign applications in Android". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to sign applications in Android" together.

Android requires all programs to be digitally signed before installation, and if no digital signature is available, the system will not allow the program to be installed and run. Whether it's a simulator or a real phone. Therefore, before you can run the debugger on a device or simulator, you must set up a digital signature for your application.

All programs must be signed. Without signed programs, the system will not install.

Applications can be signed using self-signed certificates without authorization credentials. The system only tests the validity of the signed certificate at installation time, and if the application's signature expires after installation, the application can still be launched normally. Standard tools-Keytool and Jarsigner-generate keys to sign the application's.apk file.

Android SDK tools can sign apps while debugging. Both ADT plug-ins and Ant compilers provide two signature patterns-debug pattern and release pattern

In debug mode, the compiler uses Keytool, a generic program in JDK, to create secret locks and keys using known methods and passwords. Each time it compiles, the tool signs the application's.apk file with the debug key. Because the password is known, the tool

There is no need to prompt for a lock and key every time you compile.

When an application is debugged and ready for release, it can be compiled in release mode. In release mode, the compiler does not sign.apk files. You need to generate your own key and secret lock with Keytool, and then sign the.apk file with Jarsigner tool in JDK.

Signature Basic Settings

First set the JAVA_HOME environment variable to tell the SDK how to find Keytool, or you can add the JDK path of Keytool to the Windows system environment variable PATH.

To publish a release version, select your project from the Package panel, press the right mouse button, and select Android Tools, then Export Application Package. Or you can export an unsigned apk file by clicking on the "Exporting the unsigned .apk" link on the Manifest Editor, overview page. After saving the.apk file, sign the apk file with Jarsigner and your own key. If you don't have a key, you can use Keystore to create a key and a secret lock. If you already have a key, such as a public key, you can sign the.apk file.

You can also write the complete steps above as a bat file, so that when you need to sign, just run this bat. Here is a complete bat file example:

@Rem android signer//comment directive

@Rem echo Yes Display command format: echo [{on| off}] [message]

@echo **********************************************************

@Rem file exists command format: if exist path + file name command

@if exist d:sign/MyFirstApp.keystore goto sign

@echo Create signature file MyFirstApp.keystore

@Rem keytool command format: -genkey generate signature-alias alias-keyalg encryption algorithm-validity valid days-keystore production signature file name

keytool -genkey -alias MyFirstApp.keystore -keyalg RSA -validity 40000 -keystore MyFirstApp.keystore

@echo Start signing:

@Rem jarsigner command format: -verbose output details-keystore location-signedjar files to generate files to sign keystore files

jarsigner -verbose -keystore MyFirstApp.keystore -signedjar MyFirstApp_signed.apk MyFirstApp.apk MyFirstApp.keystore

@goto over

:sign

@echo Start signing:

jarsigner -verbose -keystore MyFirstApp.keystore -signedjar MyFirstApp_signed.apk MyFirstApp.apk MyFirstApp.keystore

:over

@echo ******************MyFirstApp.apk Signed ***********************

pause

The above is a complete bat file signed for the application. When running this bat file, you need to enter some necessary information according to the steps prompted on the screen. *** A signed file is generated: MyFirstApp_signed.apk.

After signing ***, compress this file again. Use zipalign in the tools folder under the Android SDK installation path to compress it. Take this file as an example. It can also be written as a bat file. The example is as follows:

D:\soft\android-sdk-windows\tools\zipalign -f -v 4 MyFirstApp_signed.apk MyFirstApp_zip.apk D:\soft\android-sdk-windows\tools\zipalign -c -v 4 MyFirstApp_zip.apk

pause

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report