【问题标题】:How to link against a external jar in Ant?如何链接到 Ant 中的外部 jar?
【发布时间】:2014-05-28 09:29:33
【问题描述】:

我有一个使用外部 jar 的库。 (Unity的东西)我怎样才能链接到它,以便ant jar命令成功?我对蚂蚁很陌生,所以我有点迷茫......

我尝试添加一个新属性:

<property name="unity.androidplayer.jarfile" value="/Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidDevelopmentPlayer/bin/"/>
    <path id="classpath">
        <fileset dir="${unity.androidplayer.jarfile}" includes="**/*.jar"/>
    </path>

然后添加一个“编译”目标

<target name="compile"
        description="Compiles project's .java files into .class files">
  <javac encoding="ascii" debug="true">
    <src path="${source.dir}" />
    <classpath>
      <pathelement location="${sdk.dir}\platforms\${target}\android.jar"/>
      <pathelement location="${unity.androidplayer.jarfile}"/>
    </classpath>
  </javac>
</target>

但更糟糕的是,我得到更多错误:(

我还在 jar 目标中尝试了&lt;zipgroupfileset dir="${unity.androidplayer.jarfile}" includes="*.jar" excludes="*.config"/&gt;,但没有任何改变。

我认为我没有将${unity.androidplayer.jarfile} 添加到正确的位置。

最初我的 build.xml 看起来像这样,现在我将符号库添加到 libs/ 中,我认为这不是最佳解决方案。

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

<property file="local.properties" />
<property file="ant.properties" />
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

<loadproperties srcFile="project.properties" />

<fail
        message="sdk.dir is missing. Make sure blah blah..."
        unless="sdk.dir"
/>

<!-- Jar target to make it a library -->
<target name="jar" depends="debug">
  <jar
      destfile="bin/MySuperLibrary.jar"
      basedir="bin/classes"
      includes="net/mycompany/myapp/*"
      />
</target>

<import file="custom_rules.xml" optional="true" />

<import file="${sdk.dir}/tools/ant/build.xml" />

非常感谢任何帮助

更新

这是我得到的结果:

$ ant jar
Buildfile: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 22.6.2
 [checkenv] Installed at /Users/guillermo.enriquez/Downloads/adt-bundle-mac-x86_64-20140321/sdk

-setup:
     [echo] Project Name: MyFirstApp
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.3
     [echo] Resolving Build Target for MyFirstApp...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/res
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/rsObj
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/rsLibs
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/gen
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/classes
    [mkdir] Created dir: /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for MyFirstApp...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...
   [subant] No sub-builds to iterate on

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 4 source files to /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/bin/classes
    [javac] /Users/guillermo.enriquez/Documents/github/mycompany/myapp/Android/src/com/mycompany/myapp/MySource.java:22: package com.unity3d.player does not exist
    [javac] import com.unity3d.player.UnityPlayer;
    [javac]                          ^

【问题讨论】:

  • 你能分享你的ant jar 命令输出吗?
  • @PCoder 我刚刚添加了我的结果。我要的库好像没找到

标签: android ant jar unity3d


【解决方案1】:

日志表明问题与javac 无法在指定的类路径中找到库有关。我会尝试在我的构建文件中使用类似的东西。

  <path id="android">
    <fileset dir="${sdk.dir}\platforms\${target}">
      <include name="*.jar"/>
    </fileset>
  </path>

  <path id="unity">
    <fileset dir="${unity.androidplayer.jarfile}">
      <include name="*.jar"/>
    </fileset>
  </path>

...

  <javac encoding="ascii" debug="true">
    <src path="${source.dir}" />
    <classpath>
        <path refid="android"/>
        <path refid="unity"/>
    </classpath>
  </javac>

【讨论】:

  • 你是对的,没有找到图书馆。这样做会导致我犯另一个错误。 ...mple/myfirstapp/MainActivity.java:16: package R does not exist [javac] setContentView(R.layout.main);
  • 这曾经在使用这个外部库之前工作过,所以我相信这与包含的 jar 有关?
  • 是的,这个错误可能是由于 android jar 的路径错误。
  • 无论如何,您始终可以使用 echo 命令测试您的路径是否合适。 &lt;property name="androidpath" value="${sdk.dir}\platforms\${target}"/&gt; 然后回显&lt;echo message="&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; ${androidpath}"/&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-17
  • 2013-11-07
  • 2010-09-14
  • 2017-09-02
  • 2012-08-18
  • 1970-01-01
相关资源
最近更新 更多