如何使Maven的antrun任务从AIDL文件生成源?

时间:2013-07-23 06:15:56

标签: android maven ant aidl maven-antrun-plugin

我正在尝试将Ant任务转换为Maven的antrun插件任务。

Ant任务就是这样:

<aidl executable="${aidl}"
    framework="${project.target.framework.aidl}"
    libraryBinAidlFolderPathRefid="project.library.bin.aidl.folder.path"
    genFolder="${gen.absolute.dir}"
    aidlOutFolder="${out.aidl.absolute.dir}">
    <source path="${source.absolute.dir}"/>
</aidl>

此代码来自android sdk build.xml文件。

知道在Maven antrun插件中应该怎么样?

2 个答案:

答案 0 :(得分:1)

我正在发布我现在这样做的方式,以防有人正在寻找相同的解决方案。

请注意,代码不干净且无法移植。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-aidl</id>
      <phase>generate-sources</phase>
      <configuration>
        <target name="convert-aidl-files">
          <property name="aidl" location="${env.ANDROID_HOME}/build-tools/android-4.2.2/aidl${exe}"/>
          <property name="framework.aidl" location="${env.ANDROID_HOME}/platforms/android-17/framework.aidl"/>
          <apply executable="${aidl}" parallel="false">
            <arg value="-I${src.dir}"/>
            <arg value="-p${framework.aidl}"/>
            <arg value="-o${gen.dir}"/>
            <srcfile/>
            <fileset dir="${src.dir}">
              <include name="**\*.aidl"/>
            </fileset>
          </apply>
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>
  • maven-antrun-plugin是maven插件,用于执行ant任务。
  • 属性aidl指向Android SDK构建工具中的aidl.exe。 脚本的这一部分使用的是硬编码值。更好的方法是动态发现位置,但不幸的是我还没有找到方法。
  • 属性framework.aidl指向Android SDK中的framework.aidl文件。 脚本的这一部分使用的是硬编码值。更好的方法是动态发现位置,但不幸的是我还没有找到方法。
  • apply ant任务用于执行带有fileset作为输入参数的aidl.exe。
  • srcfile用于提及apply任务的输入文件。 srcfile为空,但我使用下面的fileset仅过滤了扩展名为* .aidl的文件。

答案 1 :(得分:1)

使用android-maven-plugin然后使用

更方便
mvn clean android:generate-sources
相关问题