2012-05-25 96 views
0

我有一個android項目,我想建立和安裝並運行與命令行測試。安卓android測試項目與AndroidMock

以下是我的構建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?

回答

0

您需要將android jar添加到要編譯的代碼的類路徑中。你可以通過設置這樣的:

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

,然後你可以將其刪除後編譯:

<target name="-post-compile"> 
    <delete file="libs/android.jar"> </delete> 
</target>