Android的 - 构建不同的处理器架构单独的APK [英] Android - build separate APKs for different processor architectures

查看:184
本文介绍了Android的 - 构建不同的处理器架构单独的APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法来建立单独的APK文件的Andr​​oid不同的处理器架构,与老ANT或新的摇篮建设进程?我这样做的方法是建立一肥APK与所有支持本机库收录,然后分割成单独的APK,因为我解释这里。然而,似乎应该有这样做的更直接的方法...

Is there an easy way to build separate APK files for Android for different processor architectures, with the old ANT or the new Gradle build process? My way of doing this is to build one "fat" APK with all supported native libraries included, and then splitting them into separate APK as I explained here. However, it seem that there should be a more direct method of doing this...

推荐答案

我决定重新发布我的的答案从其他地方在这里,所以这一切是在一个页面上以便于访问。如果这是对SO策略,请告诉我,从这里删除该帖子。

I decided to re-post my answer from elsewhere here, so that all of this is on one page for easy access. If this is against SO policies, please tell me and delete this post from here.

下面是我对如何创建单独的APK文件,为每个支持的处理器体系结构的想法:

Here is my idea on how to create separate APK files for each supported processor architecture:

  1. 建一肥APK与你使用任何工具,包含您的支持,例如,所有本地code库armeabi,armeabi-V7A,x86和MIPS。我把它叫做原始APK文件。

  1. Build one "fat" APK with any tools you use, containing all native code libraries you support, e.g. armeabi, armeabi-v7a, x86 and mips. I'll call it the 'original' APK file.

解压缩到原来的APK到一个空文件夹,与任何压缩/解压缩工具,最好用命令行工具,这样你就可以用一个shell脚本或批处理文件后自动执行它。其实,我的样本批处理脚本下面贴表演,我只是用命令行压缩/解压缩工具来直接操作的APK,而不是完全解压缩他们,但效果是一样的。

Unzip your original APK into an empty folder, with any zip/unzip utility, best use command line tools, so that you could automate it with a shell script or batch file later. Actually, as my sample batch script posted below shows, I just use command line zip/unzip tools to manipulate APKs directly, instead of unzipping them fully, but the effect is the same.

在原来的地方APK是pssed(或在原来的apk文件/ .ZIP)uncom $ P $,删除META-INF子文件夹中的文件夹(这包含了签名,我们需要重新-sign的APK所有的修改之后,所以原来的META-INF必须被删除)。

In the folder where original APK was uncompressed to (or in the original .apk/.zip), delete META-INF sub-folder (this contains the signatures, we'll need to re-sign the APK after all the modifications, so the original META-INF must be deleted).

更改为lib子文件夹,并删除子文件夹,你不希望在新的APK文件中的任何处理器架构。例如,只留下86子文件夹内的APK英特尔Atom处理器。

Change to lib sub-folder, and delete the sub-folders for any processor architectures you don't want in the new APK file. For example, leave only 'x86' sub-folder to make an APK for Intel Atom processors.

重要:每个APK了不同的架构,必须有不同的版本code'号在AndroidManifest.xml中,并且版本$ C $下如armeabi-V7A必须比一个用于armeabi略高(读谷歌的方向在这里创建多个APK:的 http://developer.android.com/google/play/publishing/multiple-apks.html )。不幸的是,清单文件是在APK内已编译的二进制形式。我们需要修改的版本code有一个特殊的工具。见下文。

Important: each APK for a different architecture, must have a different 'versionCode' number in AndroidManifest.xml, and the version code for e.g. armeabi-v7a must be slightly higher than the one for armeabi (read Google directions for creating multiple APKs here: http://developer.android.com/google/play/publishing/multiple-apks.html ). Unfortunately, the manifest file is in a compiled binary form inside the APK. We need a special tool for modifying the versionCode there. See below.

在清单被修改为新版本code和不必要的目录和文件删除,再压缩,签署和调整您的小APK(从Android SDK中使用的jarsigner和zipalign工具)。

Once the manifest is modified with a new version code, and unnecessary directories and files deleted, re-zip, sign and align your smaller APK (use jarsigner and zipalign tools from Android SDK).

重复此过程,你需要支持其他架构,略有不同的版本codeS(但相同的版本名称)创建更小的APK文件。

Repeat the process for all other architectures you need to support, creating smaller APK files with slightly different version codes (but the same version name).

唯一悬而未决的问题是修改版本code'二进制清单文件的方式。我无法找到一个解决方案很长一段时间,所以最后不得不坐下来和曲柄我自己的code做到这一点。为出发点,我带着APKExtractor由Prasanta保罗,的http:// code.google.com/p/apk-extractor/ ,用Java编写的。我是老学校,更舒适的使用C ++,所以我的小实用程序aminc用C ++编写,现在在GitHub上的:

The only outstanding issue is the way to modify ‘versionCode’ in binary manifest file. I could not find a solution for this for a long time, so finally had to sit down and crank my own code to do this. As the starting point, I took APKExtractor by Prasanta Paul, http://code.google.com/p/apk-extractor/, written in Java. I’m the old school and still more comfortable with C++, so my little utility program 'aminc' written in C++ is now on GitHub at:

https://github.com/gregko/aminc

我贴了整个的Visual Studio 2012的解决方案存在,但整个程序是可能可以在任何平台上编译一个.cpp文件。这里是我使用分裂我的胖的apk命名atVoice.apk到名为atVoice_armeabi.apk,atVoice_armeabi-v7a.apk,atVoice_x86.apk和atVoice_mips.apk 4小文件示例Windows批处理脚本文件。事实上,我将这些文件提交给谷歌播放(见我的应用程序在的https: //play.google.com/store/apps/details?id=com.hyperionics.avar )和所有完美的作品:

I posted the entire Visual Studio 2012 solution there, but the whole program is a single .cpp file which probably can be compiled on any platform. And here is a sample Windows batch script file I use to split my "fat" apk named atVoice.apk into 4 smaller files named atVoice_armeabi.apk, atVoice_armeabi-v7a.apk, atVoice_x86.apk and atVoice_mips.apk. I actually submit these files to Google Play (see my app at https://play.google.com/store/apps/details?id=com.hyperionics.avar) and all works perfectly:

@echo off
REM    My "fat" apk is named atVoice.apk. Change below to whatever or set from %1
set apkfile=atVoice
del *.apk

REM    My tools build atVoice-release.apk in bin project sub-dir. 
REM    Copy it herefor splitting.
copy ..\bin\%apkfile%-release.apk %apkfile%.apk

zip -d %apkfile%.apk META-INF/*

REM ------------------- armeabi ------------------------
unzip %apkfile%.apk AndroidManifest.xml
copy/y %apkfile%.apk %apkfile%.zip
zip -d %apkfile%.zip lib/armeabi-v7a/* lib/x86/* lib/mips/*
aminc AndroidManifest.xml 1
zip -f %apkfile%.zip
ren %apkfile%.zip %apkfile%_armeabi.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore d:\users\greg\.android\Hyperionics.keystore -storepass MyPass %apkfile%_armeabi.apk MyKeyName
zipalign 4 %apkfile%_armeabi.apk %apkfile%_armeabi-aligned.apk
del %apkfile%_armeabi.apk
ren %apkfile%_armeabi-aligned.apk %apkfile%_armeabi.apk

REM ------------------- armeabi-v7a ---------------------
copy/y %apkfile%.apk %apkfile%.zip
zip -d %apkfile%.zip lib/armeabi/* lib/x86/* lib/mips/*
aminc AndroidManifest.xml 1
zip -f %apkfile%.zip
ren %apkfile%.zip %apkfile%_armeabi-v7a.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore d:\users\greg\.android\Hyperionics.keystore -storepass MyPass %apkfile%_armeabi-v7a.apk MyKeyName
zipalign 4 %apkfile%_armeabi-v7a.apk %apkfile%_armeabi-v7a-aligned.apk
del %apkfile%_armeabi-v7a.apk
ren %apkfile%_armeabi-v7a-aligned.apk %apkfile%_armeabi-v7a.apk

REM ------------------- x86 ---------------------
copy/y %apkfile%.apk %apkfile%.zip
zip -d %apkfile%.zip lib/armeabi/* lib/armeabi-v7a/* lib/mips/*
aminc AndroidManifest.xml 9
zip -f %apkfile%.zip
ren %apkfile%.zip %apkfile%_x86.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore d:\users\greg\.android\Hyperionics.keystore -storepass MyPass %apkfile%_x86.apk MyKeyName
zipalign 4 %apkfile%_x86.apk %apkfile%_x86-aligned.apk
del %apkfile%_x86.apk
ren %apkfile%_x86-aligned.apk %apkfile%_x86.apk

REM ------------------- MIPS ---------------------
copy/y %apkfile%.apk %apkfile%.zip
zip -d %apkfile%.zip lib/armeabi/* lib/armeabi-v7a/* lib/x86/*
aminc AndroidManifest.xml 10
zip -f %apkfile%.zip
ren %apkfile%.zip %apkfile%_mips.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore d:\users\greg\.android\Hyperionics.keystore -storepass MyPass %apkfile%_mips.apk MyKeyName
zipalign 4 %apkfile%_mips.apk %apkfile%_mips-aligned.apk
del %apkfile%_mips.apk
ren %apkfile%_mips-aligned.apk %apkfile%_mips.apk


del AndroidManifest.xml
del %apkfile%.apk
:done

其他保障

我得到在谷歌的几个错误报告Play开发者控制台,指出一个本地方法不能被发现。最有可能这是由于安装了错误的APK,例如用户英特尔和MIPS APK一个ARM设备上。增加了额外的code到我的应用程序,核对Build.CPU_ABI版本code号码,则显示错误消息的情况下不匹配,要求用户从谷歌播放(或我自己的网站,在那里重新安装我在这样的情况下,发布胖APK)。

Additional safeguards

I get a few error reports at Google Play developer console, stating that a native method could not be found. Most probably this is caused by the user installing a wrong APK, e.g. Intel or MIPS APK on an ARM device. Added extra code to my app, checking the VersionCode number against Build.CPU_ABI, then displaying an error message in case of mismatch, asking the user to re-install from Google Play (or my own website, where I post a "fat" APK) in such case.

格雷格

这篇关于Android的 - 构建不同的处理器架构单独的APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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