0

我有一个 android 项目,我想使用命令行构建和安装并运行测试。

以下是我的构建 shell 脚本:

android update project --path ./main/libraryProject
android update project --path ./main/Project --library ../libraryProject
android update project --path ./main/Test --library ../libraryProject
android update test-project -m $(pwd)/main/Project -p ./main/Test
cd main/Project
ant debug install
cd ../Test
ant debug install test

该项目可以构建和安装,但在构建测试项目时遇到以下错误:

    [javac] An annotation processor threw an uncaught exception.
    [javac] Consult the following stack trace for details.
    [javac] java.lang.NoClassDefFoundError: android/app/Activity
    [javac]     at java.lang.ClassLoader.defineClass1(Native Method)
    [javac]     at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    [javac]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    [javac]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    [javac]     at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    [javac]     at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    [javac]     at java.security.AccessController.doPrivileged(Native Method)
    [javac]     at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    [javac]     at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    [javac]     at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    [javac]     at java.lang.Class.forName0(Native Method)
    [javac]     at java.lang.Class.forName(Class.java:264)
    [javac]     at com.google.android.testing.mocking.UsesMocksProcessor.findClassesToMock(UsesMocksProcessor.java:144)
    [javac]     at com.google.android.testing.mocking.UsesMocksProcessor.process(UsesMocksProcessor.java:108)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:735)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:664)
    [javac]     at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:809)
    [javac]     at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1060)
    [javac]     at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:795)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:380)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:306)
    [javac]     at com.sun.tools.javac.main.Main.compile(Main.java:297)
    [javac]     at com.sun.tools.javac.Main.compile(Main.java:82)
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:616)
    [javac]     at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
    [javac]     at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1153)
    [javac]     at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:930)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:616)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    [javac]     at com.android.ant.IfElseTask.execute(IfElseTask.java:120)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:616)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:616)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
    [javac]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    [javac]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac]     at java.lang.reflect.Method.invoke(Method.java:616)
    [javac]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [javac]     at org.apache.tools.ant.Target.execute(Target.java:392)
    [javac]     at org.apache.tools.ant.Target.performTasks(Target.java:413)
    [javac]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    [javac]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    [javac]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [javac]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    [javac]     at org.apache.tools.ant.Main.runBuild(Main.java:811)
    [javac]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
    [javac]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
    [javac]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
    [javac] Caused by: java.lang.ClassNotFoundException: android.app.Activity
    [javac]     at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    [javac]     at java.security.AccessController.doPrivileged(Native Method)
    [javac]     at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    [javac]     at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    [javac]     at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    [javac]     ... 68 more

有没有人知道我该怎么办?我使用 AndroidMock 会发生这种情况吗?

4

1 回答 1

0

您需要将 android jar 添加到类路径中才能编译代码。您可以通过设置来做到这一点:

<property name="jar.libs.dir" value="${libs.dir}" />

然后你可以在编译后删除它:

<target name="-post-compile">
    <delete file="libs/android.jar"> </delete>
</target>
于 2012-08-15T23:30:57.737 回答