0
点赞
收藏
分享

微信扫一扫

制作自己的android升级包(update.zip)


1.创建一个update目录,该目录包含自己想要升级或替换的内容
例如:
update/
update/system
update/system/app
update/system/app/doodle_jump.apk
update/META-INF
update/META-INF/com
update/META-INF/com/google
update/META-INF/com/google/android
update/META-INF/com/google/android/update-script

该目录包含doodle_jump游戏,升级后该apk将出现在手机的/system/app/目录下。
META-INF目录下包含升级脚本,update-script脚本的内容如下:
show_progress 0.500000 0
copy_dir PACKAGE:system SYSTEM:
show_progress 0.100000 0
大家可以根据自己的升级内容添加相应的命令。

2.创建压缩包
在update/目录下运行:
$ zip -qry ../update.unsigned.zip ./
将在update/的父目录下产生update.unsigned.zip 压缩包

3.签名
$ java -Xmx512m -jar signapk.jar -w key.x509.pem key.pk8 update.unsigned.zip update.zip
生成签过名的update.zip包,其中
signapk.jar,key.x509.pem,key.pk8与具体手机系统相关

4.将签过名的update.zip包放入手机sdcard根目录,
重启系统进入recovery模式,选择
apply update.zip,成功后重启手机

ok,现在手机上已经有doodle_jump游戏了,并且它无法被删除~


-- original english --

When publishing an application or a custom rom  you need to sign the .apk or .zip files with a ​​ certificate​​​ using a private key. The ​​ Android​​​ system uses the certificate to identify the author of an application and establish trust relationship between applications. The classic way of doing this was to use ​​ keytool​​​ then sign it with  ​​ jarsigner​​. In this tutorial i’ll explain an alternative method which is relatively easy to use for most people  using a tool called SignApk.jar.

SignApk.jar is a tool included with the Android platform source bundle, you can download it from​​ here​​​. To use SignApk.jar you have to create a private key with it’s corresponding certificate/public key. To create private/public key pair, you can use ​​Openssl​​​. Openssl is relatively easy to use under unix/linux system. For Windows user, you can download Windows version of Openssl ​​ here​​.

How to create private/public key pair using openssl (windows version)

  • Download openssl package from link given above
  • Extract it anywhere on your drive (eg. C:\openssl)
  • Within openssl directory type (use cmd tool): - openssl genrsa -out key.pem 1024
    - openssl req -new -key key.pem -out request.pem
    - openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
    - openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt


制作自己的android升级包(update.zip)_system

  • Download SignApk.rar from link given above
  • Extract it  anywhere on your drive (eg. c:\SignApk)
  • If you don’t have java installed, ​​ download ​​and install it.
  • Copy certificate.pem and key.pk8 into your extracted SignApk directory
  • Within SignApk directory type:
  • java -jar signapk.jar certificate.pem key.pk8 your-app.apk  your-signed-app.apk

    OR

    java -jar signapk.jar certificate.pem key.pk8 your-update.zip your-signed-update.zip

Note:

If you don’t want to create your own public/private key pair, you can use test key included in SignApk.rar.

======================================= Import =========================================

There are several ways to install applications or  library files to an ​​ Android​​ ​​ Phone​​. You can use Market application to find and install or ​​ adb​​ command line tool to install or push the files to Android file system. These are all easy to implement for  single  file but if you have several applications or library files to install at once, it might be better to use update zip file. The update zip file is Android advanced system to install applications or lib files to Android file system using recovery tool. This method is commonly used by rom or theme developers to distribute their package.

Creating an update zip file is quite easy, all you have to do is put the files in corresponding directory in Android file system and an update-script file to copy the files. For example, to install Calculator.apk into system/app and copy libsec-ril.so file into system/lib

  • Create an empty folder (eg. C:\myupdate)
  • Create C:\myupdate\system\app folder for Calculator.apk and  C:\myupdate\system\lib folder for libsec-ril.so
  • Create C:\myupdate\META-INF\com\google\android folder for update-script
  • Create the update-script file with the following syntax:

show_progress 0.1 0

copy_dir PACKAGE:system SYSTEM:

show_progress 0.1 10


  • Line 1&5 : show progress bar Line 3: copy system folder from update package to Android’s /system

    Note: you should add one extra  line at the end of the file (Line 6)

  • Compress the entire contents of C:\myupdate folder to zip (not the myupdate folder itself)
  • Sign the myupdate.zip file
  • java -jar signapk.jar certificate.pem key.pk8 myupdate.zip update.zip

    Note: you can find tutorial on how to sign the update.zip file ​​ here​​

  • Copy the update.zipupdate-script syntax reference (definitions from recovery.c android source code):
  • copy_dir
  • Syntax: copy_dir <src-dir> <dst-dir> [<timestamp>]
    Copy the contents of <src-dir> to  <dst-dir>. The original contents of <dst-dir> are preserved unless something in <src-dir> overwrote them.
    Ex: copy_dir PACKAGE:system SYSTEM:

  • format
  • Syntax: format <root>
    Format a partiti0n
    Ex: format SYSTEM:, will format entire /system

  • delete
  • Syntax: delete <file1> [... <fileN>]
    Delete  file.
    EX: delete SYSTEM:app/Calculator.apk, will delete Calculator.apk from system/app

  • delete_recursive
  • Syntax: delete_recursive <file-or-dir1> [... <file-or-dirN>]
    Delete a file or directory with all of it’s contents recursively
    Ex: delete_recursive DATA:dalvik-cache, will delete /data/dalvik-cache

  • run_program
  • Syntax: run_program <program-file> [<args> ...]
    Run an external program included in the update package.
    Ex: run_program PACKAGE:install_busybox.sh, will run install_busybox.sh

  • set_perm
  • Syntax: set_perm <uid> <gid> <mode> <path> [... <pathN>]
    Set ownership and permission of single file or entire directory trees, like ‘chmod’, ‘chown’, and ‘chgrp’ all in one
    Ex: set_perm 0 2000 0550 SYSTEM:etc/init.goldfish.sh

  • set_perm_recursive
  • Syntax: set_perm_recursive <uid> <gid> <dir-mode> <file-moe> <path> [... <pathN>]
    Set ownership and permission of a directory with all of it’s contents recursively

    Ex: set_perm_recursive 0 0 0755 0644 SYSTEM:app

  • show_progress
  • Syntax: show_progress <fraction> <duration>
    Use of the on-screen progress meter for the next operation, automatically advancing the meter over <duration> seconds (or more rapidly if the actual rate of progress can be determined).
    Ex: show_progress 0.1 0

  • symlink
  • Syntax: symlink <link-target> <link-path>

    Create a symlink (like ‘ln-s’). The <link-path> is in root:path format, but <link-target> is
    for the target filesystem (and may be relative)

Definition of roots and partitions (from root.c android source code)

ROOT: (Linux block device) /mountpoint/ fs, size Description. BOOT: (/dev/mtdblock[?]) / (RAM) Raw Kernel, ramdisk and boot config. DATA: (/dev/mtdblock5) /data/ yaffs2, 91904kb User, system config, app config, and apps (without a2sd) CACHE: (/dev/mtdblock4) /cache/ yaffs2, 30720kb OTA cache, Recovery/update config and temp MISC: (/dev/mtdblock[?]) N/A Raw [TODO: Get info on MISC:] PACKAGE: (Relative to package file) N/A Pseudo-filesystem for update package. RECOVERY: (/dev/mtdblock[?]) / (RAM) Raw, [?]kb The recovery and update environment's kernel and ramdisk. Similar to BOOT:. SDCARD: (/dev/mmcblk0(p1)) /sdcard/ fat32, 32MB-32GB The microSD card. Update zip is usually here. SYSTEM: (/dev/mtdblock3) /system/ yaffs2, 92160kb The OS partition, static and read-only. TMP: /tmp/ in RAM Standard Linux temporary directory.

ROOT:     (Linux block device) /mountpoint/ fs, size
Description.

BOOT: (/dev/mtdblock[?]) / (RAM) Raw
Kernel, ramdisk and boot config.
DATA: (/dev/mtdblock5) /data/ yaffs2, 91904kb
User, system config, app config, and apps (without a2sd)
CACHE: (/dev/mtdblock4) /cache/ yaffs2, 30720kb
OTA cache, Recovery/update config and temp
MISC: (/dev/mtdblock[?]) N/A Raw
[TODO: Get info on MISC:]
PACKAGE: (Relative to package file) N/A
Pseudo-filesystem for update package.
RECOVERY: (/dev/mtdblock[?]) / (RAM) Raw, [?]kb
The recovery and update environment's kernel and ramdisk.
Similar to BOOT:.
SDCARD: (/dev/mmcblk0(p1)) /sdcard/ fat32, 32MB-32GB
The microSD card. Update zip is usually here.
SYSTEM: (/dev/mtdblock3) /system/ yaffs2, 92160kb
The OS partition, static and read-only.
TMP: /tmp/ in RAM
Standard Linux temporary directory.


举报

相关推荐

0 条评论