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工具可以通过命令行更改项目的包名吗?我不想使用Eclipse的Android工具——>重命名应用程序包。
1 个解决方案
#1
10
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].
如果您想一次性更改源代码,可以使用Android命令行工具Android update project Documentation在[developer docs][1]中。
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.
如果您想在每次构建期间动态地执行它,您将需要一个自定义ant构建脚本将参数传递给aapt,不幸的是,您不能使用默认的aapt任务,因为它不支持设置选项——renam -manifest-package。
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" />
您需要将以下目标添加到默认构建中。xml文件android命令行创建;在
<!-- 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>
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.
name将包含包的名称。您可以将其设置在属性文件中或作为命令行选项-Dpackage.manifest.name=value中,您还可以将其扩展为基于属性重命名输出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?
这个问题涵盖了从清单中获取版本信息以添加到apk输出名称:如何在使用ant构建Android apk时在文件名中包含版本字符串?
You will want to look at the build.xml file that is imported to get an idea of what you will need to override.
您将希望查看构建。导入的xml文件,了解需要重写的内容。
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.
您可以继续向本地构建添加规则重写。xml文件,但是由于需要进行定制,所以我想直接复制构建。来自android工具的xml文件并对其进行修改,而不是将其用作导入。这意味着更多的工作确保它仍然适用于android工具链的每一个更新。
#1
10
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].
如果您想一次性更改源代码,可以使用Android命令行工具Android update project Documentation在[developer docs][1]中。
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.
如果您想在每次构建期间动态地执行它,您将需要一个自定义ant构建脚本将参数传递给aapt,不幸的是,您不能使用默认的aapt任务,因为它不支持设置选项——renam -manifest-package。
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" />
您需要将以下目标添加到默认构建中。xml文件android命令行创建;在
<!-- 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>
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.
name将包含包的名称。您可以将其设置在属性文件中或作为命令行选项-Dpackage.manifest.name=value中,您还可以将其扩展为基于属性重命名输出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?
这个问题涵盖了从清单中获取版本信息以添加到apk输出名称:如何在使用ant构建Android apk时在文件名中包含版本字符串?
You will want to look at the build.xml file that is imported to get an idea of what you will need to override.
您将希望查看构建。导入的xml文件,了解需要重写的内容。
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.
您可以继续向本地构建添加规则重写。xml文件,但是由于需要进行定制,所以我想直接复制构建。来自android工具的xml文件并对其进行修改,而不是将其用作导入。这意味着更多的工作确保它仍然适用于android工具链的每一个更新。