我想,同时还采用了Android的Eclipse ADT插件来定制生成过程我想、采用了、插件、过程

2023-09-05 00:05:19 作者:神经病院钻石会员。

随着ADT插件安装,下面的建设者们积极为Android项目:

With the ADT plug-in installed, the following builders are active for an Android project:

在Android的资源管理器 Android的pre编译器 在Java的生成器 在Android的程序包生成器

纵观输出目录,将创建下列构件:

Looking at the output directory, the following artifacts are created:

resources.ap_(只是一个APK / ZIP的资源和无code) 在根/ R.java(资源的自动生成列表) 与Java字节code .class文件 classes.dex $ {项目名称} .apk文件

有关我的项目,我自动生成多个code文物和一般需要更严格的控制整个构建过程中。起初,我想通了资源管理器是负责创建resources.ap_,在precompiler创建R.java,Java的建设者做了明显的,然后在Android程序包生成器创建classes.dex,然后组合classes.dex和resources.ap_创建APK文件。

For my project, I autogenerate several code artifacts and in general need tighter control of the build process. At first, I figured that the Resource Manager was responsible for creating resources.ap_, the precompiler created R.java, java builder did the obvious, and then the Android Package Builder created classes.dex, then combined classes.dex and resources.ap_ to create the APK file.

我禁用了前两个步骤,并创建一个自定义pre-生成器,它规定了resources.ap_的副本,认定这将是等效的。没有这样的运气。

I disabled the first two steps and created a custom pre-builder that laid down a copy of resources.ap_, figuring this would be equivalent. No such luck.

不幸的是,最终的Andr​​oid程序包生成器似乎直接从水库思乐普的资源/而忽略我的resources.ap_。事实上,前两个构建步骤似乎并没有做太多其他的不是生成R.java。

Unfortunately, the final Android Package Builder seems to slurp the resources directly from res/ and ignores my resources.ap_. In fact, the first two build steps don't seem to do much other than generate R.java.

这是它变得非常困难。如果我禁用最终生成步骤,躺在我自己的APK文件(使用的确切的同一个名字),我得到以下错误:

This is where it gets really problematic. If I disable the final build step and lay down my own APK file (with the exact same name), I get the following error:

[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程序包生成器(它没有可识别的配置),我必须提供个人./res/文件。没有它,我不能拿到项目启动装置(未从Eclipse中)上。

So I'm stuck: with the Android Package Builder (which has no discernable configuration), I have to supply individual ./res/ files. Without it, I can't get the project to launch on the device (not from Eclipse).

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

Anyone have any better ideas / experience in this space?

推荐答案

对于Ant脚本,下面是我的所有功能于一身的模板构建一个Android应用程序的蚂蚁步骤(这可能是有用的人尝试翻译在Eclipse构建以蚂蚁,因为它是更简单,比自动生成的Andr​​oid工具的不透明版)更加透明的:

Regarding Ant scripts, the following is my all-in-one template of the Ant steps for building an Android app (this might be useful to others trying to translate the Eclipse build to Ant as it is much simpler and more transparent than the opaque version autogenerated with the android tools):

<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集成的启动和调试应用程序。

What I am looking for is to be able to use all or fragments of this Ant build script, but still have the Eclipse integration for launching and debugging the app.

 
精彩推荐
图片推荐