网上好多自动化打包,都是争对同一个工程打不通渠道的包,而目前我要做的就像讯飞语音那样,需要根据你注册的信息去生成更改了包名的example工程,只是我们提供的只是apk包不需要源代码,公司大牛通过写shell脚本,去轮询工程从而替换所有的packagename。现本人分享一段google后的样本,只通过修改sdk下相应build.xml 文件的配置,从而达到同一工程打不通packagename的apk.

只需在-package-resources命令中添加manifestpackage="${package.manifest.name}",这样包名变更改为package.manifest.name的实际值了。如下


```java

<target name="-package-resources" depends="-crunch">

<!-- only package resources if *not* a library project -->

<do-only-if-not-library elseText="Library project: do not package resources..." >

<aapt executable="${aapt}"

command="package"

versioncode="${version.code}"

versionname="${version.name}"

debug="${build.is.packaging.debug}"

manifest="${out.manifest.abs.file}"

assets="${asset.absolute.dir}"

androidjar="${project.target.android.jar}"

apkfolder="${out.absolute.dir}"

nocrunch="${build.packaging.nocrunch}"

resourcefilename="${resource.package.file.name}"

resourcefilter="${aapt.resource.filter}"

libraryResFolderPathRefid="project.library.res.folder.path"

libraryPackagesRefid="project.library.packages"

libraryRFileRefid="project.library.bin.r.file.path"

previousBuildType="${build.last.target}"

buildType="${build.target}"

ignoreAssets="${aapt.ignore.assets}"

manifestpackage="${package.manifest.name}">

<res path="${out.res.absolute.dir}" />

<res path="${resource.absolute.dir}" />

<!-- <nocompress /> forces no compression on any files in assets or res/raw -->

<!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->

</aapt>

</do-only-if-not-library>

</target>

```

可以通过cmd执行android update .命令,在工程下生成build.xml文件,便可看到具体引用的sdk下打包用的build.xml文件,通过复制文件进行修改,并修改相应的引用即可。这些就不在赘述了。

传送门http://my.eoe.cn/109830/archive/15436.html