0

在此处的文档中

https://developer.android.com/tools/projects/projects-cmdline.html

它说

'android update'

可用于从现有代码创建新项目。然而,该示例并未说明如何做到这一点。给定一个现有的项目文件夹(基本上包含一个模板 android 项目),我如何从 cmd 行创建一个具有自己文件夹的新项目?

4

1 回答 1

0

Lennert,我真的认为'android 更新'很差。我想复制一个现有项目,但重命名包名称,但我无法做到这一点,然后我使用脚本 ant 做到了。

<project name="betorcs" basedir="." >

    <property environment="env" />

    <!-- project directories -->
    <property name="project.dir" value="${basedir}/.." />
    <property name="project.src" value="${project.dir}/src/main/java" />
    <property name="project.res" value="${project.dir}/res" />


    <!-- load configuration file -->
    <loadproperties srcFile="${checklist.file}" />

    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="libs/xmltask.jar"/>


    <!-- altera o nome do packageName -->
    <target name="-change-package">
        <echo> Name the application package name on manifest.</echo>
        <xmltask encoding="UTF-8" source="${project.dir}/AndroidManifest.xml" dest="${project.dir}/AndroidManifest.xml">
            <copy path="/manifest/@package" property="packageName" />
            <replace path="/manifest/@package" withText="${project.package}" />
        </xmltask>

        <echo> Refactory reference from '${packageName}' to '${project.package}'</echo>
        <replace dir="${project.src}" value="${project.package}.R">
            <include name="**/*.java" />
            <replacefilter
                        token="${packageName}.R"
                        value="${project.package}.R" />
        </replace>

        <replace dir="${project.src}" value="${project.package}.BuildConfig">
            <include name="**/*.java" />
            <replacefilter
            token="${packageName}.BuildConfig"
            value="${project.package}.BuildConfig" />
        </replace>

        <echo> Rename resources from '${packageName}' to '${project.package}'</echo>
        <replace dir="${project.res}" value="http://schemas.android.com/apk/res/${project.package}">
            <include name="**/*.xml" />
            <replacefilter
                        token="http://schemas.android.com/apk/res/${packageName}"
                        value="http://schemas.android.com/apk/res/${project.package}" />
        </replace>
    </target>




</project>


    Action "update project":
      Updates an Android project (must already have an AndroidManifest.xml).
    Options:
      -l --library    : Directory of an Android library to add, relative to this
                        project's directory.
      -p --path       : The project's directory. [required]
      -n --name       : Project name.
      -t --target     : Target ID to set for the project.
      -s --subprojects: Also updates any projects in sub-folders, such as test
                        projects.

    Action "create project":
      Creates a new Android project.
    Options:
      -n --name    : Project name.
      -t --target  : Target ID of the new project. [required]
      -p --path    : The new project's directory. [required]
      -k --package : Android package name for the application. [required]
      -a --activity: Name of the default Activity that is created. [required]

于 2013-09-26T14:24:50.663 回答