Android 中Odex文件生成与合并, 移植apk【转载+修正】

发现lewa的通讯录很牛逼,就想移植到机子上,搜索到odex和apk合并的文章,红色字体为本博主心得,分享下:

来自:http://blog.csdn.net/happyhell/article/details/6084058


一、APK生成odex文件方法:

  编译开源GIT上的build/tools/dexpreopt/dexopt-wrapper这个,使用dexopt-wrapper即可,操作步骤

  将dexopt-wrapper放到/data/local目录中,使用adb shell执行linux命令行,使用cd命令进入/data/local目录,

  cd /data/local

  ./dexopt-wrapper devdiv.apk devdiv.odex

 

二、合并odex和 少dex的apk 为完整的apk文件

   1. 下载 http://smali.googlecode.com/files/smali-1.2.5.jar 和 http://smali.googlecode.com/files/baksmali-1.2.5.jar 

实际上我喜欢用最新的,菜鸟有福了:http://code.google.com/p/smali/downloads/list

   2 .  通过odex生成class文件

          java -jar baksmali-1.2.2.jar -x devdiv.odex

         执行完上面这行命令后,会生成一个out 文件夹里面是devdiv.odex的class文件。出现问题,根据提示可以从rom的 /system/framework core.odex, ext.odex, framework.odex, android.policy.odex, services.odex这5个文件也放在同一目录(也可以放在别的目录,通过设置BOOTCLASSPATH指定,默认就是当前目录)。

把system/framework的文件全部复制即可,省的看的眼睛痛;另外,devdiv.odex改成你的odex文件名即可。

这时,蛋疼的事情来了:

UNEXPECTED TOP-LEVEL EXCEPTION:
org.jf.dexlib.Util.ExceptionWithContext: regCount does not match the number of a
rguments of the method
        at org.jf.dexlib.Util.ExceptionWithContext.withContext(ExceptionWithCont
ext.java:54)
        at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(Instructio
nIterator.java:92)
        at org.jf.dexlib.CodeItem.readItem(CodeItem.java:154)
        at org.jf.dexlib.Item.readFrom(Item.java:76)
        at org.jf.dexlib.OffsettedSection.readItems(OffsettedSection.java:48)
        at org.jf.dexlib.Section.readFrom(Section.java:143)
        at org.jf.dexlib.DexFile.<init>(DexFile.java:431)
        at org.jf.baksmali.main.main(main.java:265)
Caused by: java.lang.RuntimeException: regCount does not match the number of arg
uments of the method
        at org.jf.dexlib.Code.Format.Instruction3rc.checkItem(Instruction3rc.jav
a:129)
        at org.jf.dexlib.Code.Format.Instruction3rc.<init>(Instruction3rc.java:7
9)
        at org.jf.dexlib.Code.Format.Instruction3rc.<init>(Instruction3rc.java:4
4)
        at org.jf.dexlib.Code.Format.Instruction3rc$Factory.makeInstruction(Inst
ruction3rc.java:145)
        at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(Instructio
nIterator.java:84)
        ... 6 more
Error occured at code address 0
code_item @0x325a8

不要慌,我已经解决了,哈哈,看招:

java -jar baksmali-1.3.2.jar -a 13  -x pim.odex

恩,加个--api-level就ok了,具体原因上google讨论里面找!


  3. 通过class生成classes.dex 文件。

        java -Xmx512M -jar smali-1.3.2.jar out -o classes.dex

  4. 将classes.dex放到apk文件

        因为apk是zip的mime编码类型,使用winzip或winrar直接拖入到apk改名为zip的压缩包中即可。

  5. 不要忘记了签名,使用jdk中的arsigner和keytool打包重新签名即可。



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值