我想在使用Android Eclipse ADT插件的同时自定义构建过程

安装ADT插件后,以下构建器对于 Android项目处于活动状态:

> Android资源管理器
> Android预编译器
> Java Builder
> Android Package Builder

查看输出目录,将创建以下工件:

> resources.ap_(只是一个资源没有代码的APK / ZIP)
> gen / R.java(自动生成的资源列表)
> .class文件,带有java字节码
> classes.dex
> ${project-name} .apk

对于我的项目,我自动生成了几个代码工件,并且通常需要更严格地控​​制构建过程.首先,我认为资源管理器负责创建resources.ap_,预编译器创建了R.java,java builder显而易见,然后Android Package Builder创建了classes.dex,然后组合了classes.dex和resources.ap_创建APK文件.

我禁用了前两个步骤,并创建了一个自定义预构建器,它构建了一个resources.ap_副本,认为这是等效的.没有这样的运气.

不幸的是,最终的Android Package Builder似乎直接从res /中啜饮了资源而忽略了我的resources.ap_.实际上,除了生成R.java之外,前两个构建步骤似乎没有做太多.

这是它真正成问题的地方.如果我禁用最后的构建步骤并放下我自己的APK文件(具有完全相同的名称),我会收到以下错误

[2011-02-27 20:25:28 - android-premium] ------------------------------
[2011-02-27 20:25:28 - android-premium] Android Launch!
[2011-02-27 20:25:28 - android-premium] adb is running normally.
[2011-02-27 20:25:28 - android-premium] Could not find android-premium.apk!

所以我陷入困境:使用Android Package Builder(没有可辨别的配置),我必须提供单独的./res/文件.没有它,我无法让项目在设备上启动(而不是从Eclipse).

在这个领域,任何人都有更好的想法/经验吗?

解决方法

关于Ant脚本,以下是我用于构建Android应用程序的Ant步骤的一体化模板(这可能对尝试将Eclipse构建转换为Ant的其他人有用,因为它比不透明版本更简单,更透明用android工具自动生成):
<property name="workspace.dir" value="/workspace" />
<property name="project.dir" location="." />
<property name="android-platform.name" value="android-1.5" />


<!-- Framework Paths -->
<property name="android-sdk.dir" value="${workspace.dir}/EpicFramework/android-sdk"/>
<property name="android-tools.dir" value="${android-sdk.dir}/tools" />
<property name="android-platform.dir" value="${android-sdk.dir}/platforms/${android-platform.name}" />
<property name="android-platform-tools.dir" value="${android-platform.dir}/tools"/>
<property name="android-platform-jar" value="${android-platform.dir}/android.jar"/>
<property name="android-framework-src.dir" value="${workspace.dir}/EpicFramework/EpicAndroid"/>

<!-- Tool Binaries -->
<property name="adb" value="${android-tools.dir}/adb"/>
<property name="apkbuilder" value="${android-tools.dir}/apkbuilder"/>
<property name="aapt" value="${android-platform-tools.dir}/aapt"/>
<property name="dx" value="${android-platform-tools.dir}/dx"/>

<!-- Project Paths -->
<property name="src.dir"   value="${project.dir}/src" />
<property name="gen.dir"   value="${project.dir}/gen" />
<property name="res.dir"   value="${project.dir}/res" />
<property name="lib.dir"   value="${project.dir}/lib" />
<property name="build.dir" value="${project.dir}/bin" />
<property name="build.classes.dir" value="${build.dir}/classes" />

<property name="resources.file" value="${build.dir}/resources.ap_"/>
<property name="dex.file" value="${build.dir}/classes.dex" />
<property name="debug-apk.file" value="${build.dir}/${ant.project.name}-debug.apk"/>


<target name="dirs">
    <echo>Creating output directories if needed...</echo>
    <mkdir dir="${res.dir}" />
    <mkdir dir="${gen.dir}" />
    <mkdir dir="${lib.dir}" />
    <mkdir dir="${build.dir}" />
    <mkdir dir="${build.classes.dir}" />
</target>

<target name="android-resource-src" depends="dirs">
    <echo>Generating R.java from the resources...</echo>
    <exec executable="${aapt}" failonerror="true">
        <arg value="package" />
        <arg value="-M" />
        <arg path="AndroidManifest.xml" />
        <arg value="-S" />
        <arg path="${res.dir}" />
        <arg value="-I" />
        <arg path="${android-platform-jar}" />
        <arg value="-m" />
        <arg value="-J" />
        <arg path="${gen.dir}" />
    </exec>
</target>

<target name="android-compile" depends="android-resource-src">
   <echo>Compiling java files into class files...</echo>
    <javac 
      encoding="ascii"
      target="1.5"
      debug="true"
      extdirs=""
      destdir="${build.classes.dir}"
      includeAntRuntime="false"
      bootclasspath="${android-platform-jar}">
        <src path="${android-framework-src.dir}" />
        <src path="${src.dir}" />
        <src path="${gen.dir}" />
        <classpath>
            <fileset dir="${lib.dir}" includes="*.jar"/>
        </classpath>
     </javac>
</target>

<target name="android-dex" depends="android-compile">
    <echo>Converting compiled files and 3rd party libraries into ${dex.file} ...</echo>
    <apply executable="${dx}" failonerror="true" parallel="true">
        <arg value="--dex" />
        <arg value="--output=${dex.file}" />
        <arg path="${build.classes.dir}" />
        <fileset dir="${lib.dir}" includes="*.jar"/>
    </apply>
</target>

<target name="android-package-resources">
    <echo>Packaging Android resources into ${resources.file} ...</echo>
    <exec executable="${aapt}" failonerror="true">
        <arg value="package" />
        <arg value="-M" />
        <arg path="AndroidManifest.xml" />
        <arg value="-S" />
        <arg path="./res" />
        <arg value="-I" />
        <arg path="${android-platform-jar}" />
        <arg value="-f" />
        <arg value="-F" />
        <arg value="${resources.file}" />
    </exec>
</target>

<target name="android-debug" depends="android-dex,android-package-resources">
    <echo>Packaging app and signing it with the debug key</echo>
    <exec executable="${apkbuilder}" failonerror="true">
        <arg value="${debug-apk.file}" />
        <arg value="-d" />
        <arg value="-z" />
        <arg value="${resources.file}/" />
        <arg value="-f" />
        <arg value="${dex.file}" />
    </exec>
</target>

<target name="android-release" depends="android-dex,android-package-resources">
    <echo>Packaging App without signing,so that it can be signed with the official publishing key ...</echo>
    <exec executable="${apkbuilder}" failonerror="true">
        <arg value="${release-apk.file}" />
        <arg value="-u" />
        <arg value="-d" />
        <arg value="-z" />
        <arg value="${resources.file}/" />
        <arg value="-f" />
        <arg value="${dex.file}" />
    </exec>
    <echo>All generated packages need to be signed with jarsigner before they are published.</echo>
</target>

<target name="android-install" depends="android-debug">
    <echo>Removing all com.epicapplications APK files from default emulator ...</echo>
    <exec executable="${adb}" inputstring="echo hi; rm -f /data/app/com.epicapplications.*; exit;
    ">
        <arg value="shell"/>
    </exec>
    <echo>Installing ${debug-apk.file} onto default emulator...</echo>
    <exec executable="${adb}" failonerror="true">
        <arg value="install" />
        <arg value="-r" />
        <arg path="${debug-apk.file}" />
    </exec>
</target>

我正在寻找的是能够使用这个Ant构建脚本的全部或片段,但仍然有Eclipse集成来启动和调试应用程序.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...