重新打包 APK 文件以包含自定义资产 - 使用什么构建工具? [英] Repackage APK file to contain custom assets - what build tool to use?

查看:27
本文介绍了重新打包 APK 文件以包含自定义资产 - 使用什么构建工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:这是一篇旧帖子,下面对损坏的 aapt 版本的引用将过时.

<小时>

根据之前的反馈,我将自定义文本字段存储在我应用的资产目录中.

我将使用资产文件中的默认用户详细信息编写应用程序,并且客户希望为每个用户重建应用程序,包括资产文件中该用户的详细信息.

(我知道这个方法有一些严重的缺点,但客户仍然热衷于以这种方式来做 - 见 将登录详细信息嵌入到 APK 文件中,每个用户都不同(或其他选项?))

这个问题与我在解压 APK 文件并更新自定义资产文件后重建 APK 文件时遇到的问题有关.我确信我遗漏了一些小东西,但是,我在这些方法上找到的文档和帖子对新手来说并没有足够的帮助.

  1. aapt - Android sdk 工具:不幸的是,android 文档 [下面的链接 2] 上使用 aapt"的 android 文档非常有限.控制台命令 -help 显示更多信息.当尝试使用它向 test.apk 添加文件时,它最终会删除原始文件,并创建一个仅包含我尝试添加的文件的新文件 test.apk.zip.我一直无法找到正确的命令行组合来获取解压后的 apk 并重新打包——这将是我的一等奖.

  2. apkbuilder - Android sdk 工具:首先,该工具已被弃用,这是它的一个缺点.我也无法让它与解压缩文件夹中的内容一起使用.我想我错过了 apkbuilder 前的步骤,因为 apkbuilder 要求提供资源 zip 存档,而我有一个资源文件夹.

  3. ant - 构建工具:其他类似的帖子说使用 ant 构建,而不是使用 android 工具.我很难让蚂蚁工作.让 Ant 与 Android 一起工作的一个特定链接 [下面的链接 3] 看起来很有希望,但看起来它是针对不同的 android sdk(我的由 android 生成的 build.xml 看起来与他的不同).不幸的是,我对 ant 知之甚少,并且无法成为足以解决我当前问题的专家.
    下面是 NickT 的解决方案的进一步说明 - 运行 ant 脚本给了我错误
    无法使用类加载器 AntClassLoader[] 找到 taskdef 类 com.android.ant.SetupTask.
    我在网上找到了一些关于这个错误的参考,已经确认 local.properties 有一个 sdk.dir 设置指向我的 android sdk 安装文件夹 (sdk.dir=/Applications/android-sdk-mac_86).

  4. ?????:可能还有一些我没有列出/发现的其他选项,我有兴趣了解一下.

我意识到深入研究通常被我的想法掩盖的齿轮会导致困难.但是我知道很多 SO 用户可以做很多这样的事情,我希望我能引起他们中的一些人的兴趣.感谢您的帮助.

(Mac Snow Leopard 10.6 64 位上的 Eclipse 3.6)

PS,我还不能发布 1 个以上的超链接,所以我添加了这些地址以显示我的问题的更多信息.

(1): stackoverflow.com/questions/4783160/embed-login-details-in-apk-file-different-for-each-user-or-other-options

(2): developer.android.com/guide/developing/tools/aapt.html

(3):www.disgruntledrats.com/?p=27

解决方案

用我们最终选择的方法回答我自己的问题,并记录在案":

我无法让 Ant 为我正常工作(我缺乏理解).

我最终使用了 aapt 工具.它按照 Android sdk 文档工作,使用起来确实非常简单:

aapt add -v Test.apk "assets/readme.txt"

这将添加一个 readme.txt 文件(我们将它存储在当前运行文件夹的子文件夹中,称为资产.如果你想将新文件存储在其他地方,aapt 确实提供了一个命令行开关来指定)

但是,有一些警告:

  1. 我无法让它处理签名的 APK 文件.
  2. 某些版本的 aapt 无法正常工作!他们无法识别子文件夹...

解决1:

  1. 将 eclipse 中的 APK 导出为未签名的 APK.
  2. 使用 keytool 生成密钥(请参阅 Android 开发文档).
  3. 使用 aapt.
  4. 使用 jarsigner 对 APK 进行签名.

解决2:

我真的无能为力.我尝试下载的每个 SDK 版本(在 Mac 上)都包含一个无法识别子文件夹的 aapt 工具.一位同事下载了一个有效的版本,但我们仍然无法弄清楚他下载的是哪个版本,所以我们保留了这个神奇"的副本并重命名了它,并将一直使用它,直到我们找到一个有效的新版本.

Update: This is an old post, and references below to broken aapt versions will be out of date.


Based on previous feedback, I am storing custom text fields in the assets directory of my app.

I will write the app, using default user details in an asset file, and the client would like to rebuild the app for each user, including that user's details in the asset file.

(I am aware this is method has some serious shortcomings, but the client is still keen to do it in this way - see Embed login details in APK file, different for each user (or other options?))

This question relates to troubles I am having with rebuilding the APK file, once I have unzipped it, and updated the custom asset file. I am quite convinced I am missing something small, however, the documentation and posts I have found on these methods are not helpful enough for a newcomer.

  1. aapt - Android sdk tool: Unfortunately the android docs on "Using aapt" on the android docs [link 2 below] are very limited. The console command -help shows a bit more info. When trying to use it to just add a file to the test.apk, it ends up deleting the original, and creating a new file test.apk.zip containing only the file I tried to add. I have not been able to find the correct command line combination to take an unzipped apk and repackage it - that would be my first prize.

  2. apkbuilder - Android sdk tool: Firstly this tool is deprecated, which is a negative point for it. I also can't get it to work with what I have in that unzipped folder. I think I'm missing a pre-apkbuilder step because apkbuilder asks for a resource zip archive, and I have a resource folder.

  3. ant - build tool: Other similar posts say to build with ant, rather than using the android tools. I am having trouble getting ant to work. One particular link to Getting Ant to Work with Android [link 3 below] looks promising but looks like it is for a different android sdk (my build.xml that is generated by android looks different to his). Unfortunately I know little about ant, and am having trouble becoming expert enough to solve my current issue.
    Further to NickT's solution below - running the ant script gives me the error
    taskdef class com.android.ant.SetupTask cannot be found using the classloader AntClassLoader[].
    I have found some references online to this error, have confirmed that local.properties has an sdk.dir setting that is pointing to my android sdk install folder (sdk.dir=/Applications/android-sdk-mac_86).

  4. ?????: There might be some other option that I have not listed / discovered, which I would be interested in hearing about.

I realize that delving into the gears that are normally covered up by my ide can lead to diffuculties. But I know that a lot of the SO users can do many of these things, and I hope I get the interest of some of them. Thanks for any help.

(Eclipse 3.6 on Mac Snow Leopard 10.6 64 bit)

PS, I am not able to post more than 1 hyperlink yet, so I have included these addresses to show more info to my question.

(1): stackoverflow.com/questions/4783160/embed-login-details-in-apk-file-different-for-each-user-or-other-options

(2): developer.android.com/guide/developing/tools/aapt.html

(3): www.disgruntledrats.com/?p=27

解决方案

To answer my own question with the method we finally chose, and "for the record":

I was unable to get Ant working correctly for me (my lack of understanding).

I ended up using the aapt tool. It works as per the Android sdk documentation and really is quite simple to use:

aapt add -v Test.apk "assets/readme.txt"

This will add a readme.txt file (we were storing it in a subfolder of the current running folder, called assets. If you want to store the new file somewhere else, aapt does offer a command line switch to specify that)

However, there are some caveats:

  1. I couldn't get it to work on signed APK files.
  2. some versions of aapt don't work properly! They don't recognise the subfolder...

To solve 1:

  1. Export the APK from eclipse as an unsigned APK.
  2. Use the keytool to generate a key (see Android dev docs).
  3. Use aapt.
  4. Sign the APK using jarsigner.

To solve 2:

I can't really help with this. Every version of the SDK (on Mac) I tried to download included an aapt tool that did not recognize the subfolders. A colleague downloaded a version that worked, but we could still not figure out which version it was that he downloaded, so we kept this "magic" copy and renamed it and will be using it until we find a new version that works.

这篇关于重新打包 APK 文件以包含自定义资产 - 使用什么构建工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆