如何使用系统签名签署Android应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3635101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:06:14  来源:igfitidea点击:

How to sign Android app with system signature?

android

提问by Michalis

I've downloaded and compiled Android 2.1 version with signed-google_ion-ota-14721.zipimage for my HTC phone. The compile completed successfully and so the system image flash. How can I sign my own Android application with the system signature?

我已经signed-google_ion-ota-14721.zip为我的 HTC 手机下载并编译了带有图像的Android 2.1 版本。编译成功完成,系统映像闪烁。如何使用系统签名签署我自己的 Android 应用程序?

Can someone describe the whole process for signing a user application with system signature as I am completely new to the signing process.

有人可以描述使用系统签名对用户应用程序进行签名的整个过程,因为我对签名过程完全陌生。

回答by Michalis

Finally I managed to discover a way to sign my application with the platform signature. You need to use keys located in <root-of-android-source-tree>/build/target/product/security/and add android:sharedUserId="android.uid.system"in your AndroidManifest.xml file.

最后,我设法找到了一种使用平台签名对我的应用程序进行签名的方法。您需要使用位于<root-of-android-source-tree>/build/target/product/security/并添加android:sharedUserId="android.uid.system"到您的 AndroidManifest.xml 文件中的密钥。

Details from this google groups thread:

来自这个谷歌群组线程的详细信息:

On top of signing Android 1.6 for Dream with certificates generated by myself, I've also managed to sign my app with the platform certificate and run it with the system sharedUserId. These are the steps I took:

  • Build and flash to your Dream your own Android using https://web.archive.org/web/20081211205758/http://source.android.com:80/documentation/building-for-dream. Use the mkkey.sh script on https://web.archive.org/web/20091213215940/http://pdk.android.com/online-pdk/guide/release_keys.htmlto create new certificates, including x509 certificates before you do 'make'.
  • In the AndroidManifest.xmlof your application: under the <manifest>element, add the attribute android:sharedUserId="android.uid.system".
  • Export an unsigned version of your Android application using Eclipse: right-click on the project >> Android Tools >> Export Unsigned Application Package.
  • Use <root-of-android-source-tree>/out/host/<your-host>/framework/signapk.jarto sign your app using platform.x509.pemand platform.pk8in <root-of-android-source-tree>/build/target/product/securitygenerated earlier:

    java -jar signapk.jar platform.x509.pem platform.pk8 YourApp-unsigned.apk YourApp-signed.apk.
    
  • Install the app to your device:

    adb install YourApp-signed.apk
    
  • Run your app
  • Use adb shell psto confirm that your app is running as system.

除了使用我自己生成的证书为 Dream 签署 Android 1.6 之外,我还设法使用平台证书签署了我的应用程序,并使用系统 sharedUserId 运行它。这些是我采取的步骤:

  • 使用https://web.archive.org/web/20081211205758/http://source.android.com:80/documentation/building-for-dream构建您自己的 Android 并将其烧录到您的梦想中。使用https://web.archive.org/web/20091213215940/http://pdk.android.com/online-pdk/guide/release_keys.html上的 mkkey.sh 脚本 创建新证书,包括在您之前的 x509 证书做吧'。
  • AndroidManifest.xml您的应用程序中:在<manifest>元素下,添加属性android:sharedUserId="android.uid.system"
  • 使用 Eclipse 导出 Android 应用程序的未签名版本:右键单击项目 >> Android 工具 >> 导出未签名应用程序包。
  • 用于<root-of-android-source-tree>/out/host/<your-host>/framework/signapk.jar使用 之前生成的platform.x509.pemplatform.pk8在您的应用程序中签名<root-of-android-source-tree>/build/target/product/security

    java -jar signapk.jar platform.x509.pem platform.pk8 YourApp-unsigned.apk YourApp-signed.apk.
    
  • 将应用程序安装到您的设备:

    adb install YourApp-signed.apk
    
  • 运行你的应用
  • 使用adb shell ps要确认您的应用程序正在运行的系统。

回答by user2478124

The procedure works fine I have tried it. So long as you don't forget to run zipalign after signing as the signing processes leaves the APK unaligned and it will NOT install. You will need to install the aligned APK.

该程序运行良好,我已经尝试过了。只要您不要忘记在签名后运行 zipalign,因为签名过程会使 APK 未对齐并且不会安装。您将需要安装对齐的 APK。

zipalign -fv 4 YourApplication-signed.apk YourApplication-aligned.apk