IllegalAccessError:尝试使用ANT构建Android时访问类

时间:2012-11-29 13:30:23

标签: java android ant

我们正在使用 ANT 构建我们的Android应用程序。升级到最新的 SDK工具(Rev 21)平台工具(Rev 16)并设置 android:targetSdkVersion =“17”在manifest.xml中,我们的ant构建因 IllegalAccessError 而失败。

奇怪的是,双 ant发布成功了:

  • ant clean - >建立成功
  • ant release - >建立失败
  • ant release - > 建立成功

显然我们真正想做的事情并非如此:

  • ant clean release - >建立失败

我已经使用 android update project -p。重新生成build.xml,导致同样的问题。

请参阅下面的ANT输出:

release:

-pre-build:

-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...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...

BUILD FAILED
/home/me/android-sdks/tools/ant/build.xml:645: The following error occurred while executing this line:
/home/me/android-sdks/tools/ant/build.xml:683: java.lang.IllegalAccessError: tried to access class com.google.common.base.Platform from class com.google.common.base.CharMatcher
    at com.google.common.base.CharMatcher.precomputed(CharMatcher.java:684)
    at com.google.common.base.CharMatcher.<clinit>(CharMatcher.java:63)
    at com.google.common.base.Splitter.on(Splitter.java:129)
    at com.android.sdklib.internal.build.SymbolWriter.write(SymbolWriter.java:51)
    at com.android.ant.AaptExecTask.execute(AaptExecTask.java:711)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.Main.runBuild(Main.java:809)
    at org.apache.tools.ant.Main.startAnt(Main.java:217)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 2 seconds

非常感谢并欢迎来自中部白雪皑皑的中欧

2 个答案:

答案 0 :(得分:1)

也许这会在遇到这个错误时帮助某人:

我有同样的问题,原因是Ant的类路径中有重复的JAR。在我的例子中,checkstyle-5.6-all.jar被添加到包含上述类的ANT_HOME \ lib文件夹中,由于重复的类和它们之间的访问而导致一些错误。

在这种情况下,我建议为使用此库的Ant目标添加一个本地类路径变量,并使ANT_HOME \ lib保持尽可能干净。

答案 1 :(得分:0)

我遇到了同样的问题,经过几个小时的解决。 只需使用最新的ANT(但不是Jenkins附带的那款) 似乎apache-ant-1.8.4有一些问题。
但是在下载了最新的 apache-ant-1.9.1 之后,ant能够成功地用库项目构建项目

系统的配置,其中使用库项目构建工作ant:

>ANT: 1.9.1
>Android SDK - 22 rev
>java 1.6.0_38