如何更改应用程序包的名称通过命令行的Andr​​oid应用 [英] How can I change the application package name for an Android app via command line

查看:106
本文介绍了如何更改应用程序包的名称通过命令行的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个Android的工具,将通过命令行更改项目的包名。我不想使用Eclipse的Andr​​oid工具 - >重新命名应用程序包

Is there an Android tool that will change a project's package name via command line. I don't want to use Eclipse's Android Tools -> Rename Application Package.

推荐答案

如果你想这样做,作为一次改变源,你可以使用Android的命令行工具 Android的更新项目的说明文件在[开发文档] [1]。

If you want to do it as a one time change to the source you can use the Android command line tool android update project Documentation is in the [developer docs][1].

如果要动态过程中每一个构建,您将需要一个自定义的Ant构建脚本来传递参数到 AAPT 做到这一点不幸的是,你不能使用默认的AAPT任务,因为它不支持设置选项--rename舱单包。

If you want to do it dynamically during every build you will need a custom ant build script to pass arguments into aapt Unfortunately you can not use the default aapt task because it doesn't support setting the option --rename-manifest-package.

您需要将以下目标添加到默认的build.xml 文件机器人命令行创建;之前它加入<导入文件=$ {sdk.dir} /tool​​s/ant/build.xml/>

You need to add the following target to the default build.xml file android command line creates; add it prior to <import file="${sdk.dir}/tools/ant/build.xml" />

<!-- Replaces the target in tools\ant\build.xml -->
<target name="-package-resources" depends="-crunch">
            <!-- this exec replicates the output of the aapt task in build.xml
                 -package-resources with the addition of a rename-manifest-package option. -->
            <exec executable="${aapt}" failonerror="true">
                <arg value="package" />
                <arg value="-f" />
                <arg value="--auto-add-overlay" />
                <arg value="-M" />
                <arg path="${basedir}/AndroidManifest.xml" />
                <arg value="-S" />
                <arg path="${resource.absolute.dir}" />
                <arg value="-S" />
                <arg path="${basedir}/${android.library.reference.1}/${resource.dir}" />
                <arg value="-A" />
                <arg path="${asset.absolute.dir}" />
                <arg value="-I" />
                <arg path="${android.jar}" />
                <arg value="-F" />
                <arg path="${out.absolute.dir}/${resource.package.file.name}" />
                <arg value="--rename-manifest-package" />
                <arg value="${package.manifest.name}" />
            </exec>
</target>

属性 package.manifest.name 将包含该程序包的名称。您可以设置在一个属性文件或命令行选项 -Dpackage.manifest.name =值 您还可以扩展此基础上的属性,以及重命名输出的apk。

The property package.manifest.name will contains the name of the package. You can set that in a properties file or as a command line option -Dpackage.manifest.name=value You can also extend this to rename the output apk based on a property as well.

这个问题涉及获取版本信息的清单添加到APK输出名称: <一href="http://stackoverflow.com/questions/5270368/how-to-include-version-string-in-the-filename-when-building-android-apk-with-ant">How建立的Andr​​oid APK蚂蚁时,包括版本字符串的文件名?

This question covers getting version info from the manifest to add to the apk output name: How to include version string in the filename when building Android apk with ant?

您将要看看那被导入得到什么,你需要重写一个想法build.xml文件。

You will want to look at the build.xml file that is imported to get an idea of what you will need to override.

您可以继续添加规则覆盖到当地的build.xml文件,但是由于定制你需要做的水平,我想直接从Android工具复制build.xml文件,并修改它,而不是使用它作为一个进口。这也意味着更多的工作,确保它在整个每次更新仍然工作到Android工具链。

You can keep adding rule overrides to the local build.xml file, but due to the level of customization you need to do, I'd think about directly copy the build.xml file from the android tools and modify it rather than using it as an import. This does mean more work making sure it still works across every update to the android tool chain.

这篇关于如何更改应用程序包的名称通过命令行的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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