6

我正在尝试通过 ant 构建简单的 android 项目。这是我的蚂蚁脚本

<?xml version="1.0" encoding="UTF-8"?>
    <project name="HelloWorld" default="help">

    <!-- Input directories -->
    <property name="source.dir" value="src" />
    <property name="source.absolute.dir" location="${source.dir}" />
    <property name="gen.dir" value="gen" />
    <property name="gen.absolute.dir" location="${gen.dir}" />
    <property name="resource.dir" value="res" />
    <property name="resource.absolute.dir" location="${resource.dir}" />
    <property name="asset.dir" value="assets" />
    <property name="asset.absolute.dir" location="${asset.dir}" />

    <!-- Directory for the third party java libraries -->
    <property name="external.libs.dir" value="libs" />
    <property name="external.libs.absolute.dir" location="${external.libs.dir}" />

    <!-- Output directories -->
    <property name="out.dir" value="ant"/>
    <property name="out.absolute.dir" location="${out.dir}/bin"/>
    <property name="out.classes.absolute.dir" value="${out.absolute.dir}/classes"/>

    <property name="sdk.dir" value="../../AndroidSDK"/>
    <property name="sdk.absolute.dir" location="${sdk.dir}"/>

    <property name="android.jar" value="${sdk.absolute.dir}/platforms/android-8"/>

    <!-- The final package file to generate -->
    <property name="out.debug.unaligned.package"
                  location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
    <property name="out.debug.package"
                  location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
    <property name="out.unsigned.package"
                  location="${out.absolute.dir}/${ant.project.name}-unsigned.apk" />
    <property name="out.unaligned.package"
                  location="${out.absolute.dir}/${ant.project.name}-unaligned.apk" />
    <property name="out.release.package"
                  location="${out.absolute.dir}/${ant.project.name}-release.apk" />

    <!-- Verbosity -->
    <property name="verbose" value="true" />

    <condition property="v.option" value="-v" else="">
        <istrue value="${verbose}" />
    </condition>

    <!-- tools location -->
    <property name="android.tools.dir" location="${sdk.absolute.dir}/tools" />
    <property name="android.platform.tools.dir" location="${sdk.absolute.dir}/platform-tools" />
    <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
    <condition property="bat" value=".bat" else=""><os family="windows" /></condition>
    <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
    <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
    <property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
    <property name="aapt" location="${android.platform.tools.dir}/aapt${exe}" />
    <property name="dx" location="${android.platform.tools.dir}/dx${bat}" />

    <!-- Generates the R.java file for this project's resources. -->
    <target name="resource-src" depends="dirs">
        <echo>Generating R.java, Manifest.java from the resources...</echo>
        <exec executable="${aapt}" failonerror="true">
            <arg value="package" />
            <arg line="${v.option}" />
            <arg value="-m" />
            <arg value="-J" />
            <arg path="${gen.absolute.dir}" />
            <arg value="-M" />
            <arg path="AndroidManifest.xml" />
            <arg value="-S" />
            <arg path="${resource.absolute.dir}" />
            <arg value="-I" />
            <arg path="${android.jar}" />
        </exec>
    </target>

    <!-- Generates java classes from .aidl files. -->
    <target name="aidl" depends="dirs">
        <echo>Compiling aidl files into Java classes...</echo>
        <apply executable="${aidl}" failonerror="true">
            <arg value="-p${android.aidl}" />
            <arg value="-I${source.absolute.dir}" />
            <arg value="-o${gen.absolute.dir}" />
            <fileset dir="${source.absolute.dir}">
                <include name="**/*.aidl" />
            </fileset>
        </apply>
    </target>

    <target name="compile" depends="resource-src, aidl" description="Compiles project's .java files into .class files">
        <javac destdir="${classes.absolute.dir}" >
            <src path="${source.absolute.dir}" />
            <src path="${gen.absolute.dir}" />

            <classpath>
                <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
            </classpath>
        </javac>
    </target>

    <target name="clean" description="Removes output files created by other targets.">
        <delete dir="${out.absolute.dir}" verbose="${verbose}" />
        <delete dir="${gen.absolute.dir}" verbose="${verbose}" />
    </target>

    <!-- Creates the output directories if they don't exist yet. -->
    <target name="dirs">
        <echo>Creating output directories if needed...</echo>
        <mkdir dir="${resource.absolute.dir}" />
        <mkdir dir="${external.libs.absolute.dir}" />
        <mkdir dir="${gen.absolute.dir}" />
        <mkdir dir="${out.absolute.dir}" />
        <mkdir dir="${out.classes.absolute.dir}" />
    </target>

</project>

此脚本在代码块上失败 <target name="resource-src" depends="dirs">,我收到这样的消息: Configurations:D:\Development\Eclipse_workspace\HelloWorld\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that match the given name ' android:Theme.Light' D:\Development\Eclipse_workspace\HelloWorld\res\values-v11\styles.xml:7:错误:检索项目的父项时出错:找不到与给定名称“android:Theme.Holo”匹配的资源。光'。D:\Development\Eclipse_workspace\HelloWorld\res\values-v14\styles.xml:8:错误:检索项的父项时出错:未找到与给定名称“android:Theme.Holo.Light.DarkActionBar”匹配的资源。

如果我使用 eclipse 构建应用程序 - 没关系,应用程序构建得很好。

那么,有什么问题呢?我该如何解决?

4

2 回答 2

8

你这样做很难。android 具有为您的项目创建 ant 构建脚本的工具。只需从您的项目文件夹中运行它,

android update project --path .

android命令在 中<sdk folder>/tools)。

这将创建一个build.xml和其他几个附带的属性文件。android有关该命令的详细用法,请参阅从命令行管理项目的文档

于 2013-01-24T18:58:07.757 回答
0

假设您已经安装了 Ant。转到 Android SDK\tools 文件夹并执行以下命令

android update project --target android-18 --path "path to the project" 它将生成 build.xml 文件。

于 2014-03-07T10:12:02.280 回答