Building with ANT - ClassNotFound on Android classes

958 views
Skip to first unread message

Jason

unread,
Apr 26, 2011, 6:58:23 PM4/26/11
to Android Mock Discussion
Hi guys,

So I have AndroidMock working in Eclipse (junit test with mock objects
and expectations etc), now I'm trying to get the Android build system
to work.

I have previously been using the "run-tests" ANT task provided in the
Android SDK successfully (along with code coverage etc), however with
the inclusion of AndroidMock I am now seeing ClassNotFound
exceptions. Now this would make sense to me if the classes not being
found where my own, but actually it's Android SDK classes...

[javac] Note: Adding Class to Mocking List:
android.widget.ViewFlipper
[javac] error: Could not find android.widget.ViewFlipper
[javac] error: java.lang.ClassNotFoundException:
android.widget.ViewFlipper

So AndroidMock IS running on compile, and is finding all the classes
that need to be mocked out, but whenever it encounters an Android
class (either directly or via a compile-time dependency) it barfs with
a ClassNotFound.

I am not doing any magic with the classpath used by the javac task in
the Android ANT build, however by default it will include all the JARs
in the libs folder of the test project (which it is, and must be
because the annotations ARE being processed by AndroidMock). Without
any annotations present my ANT build runs fine. It seems that somehow
AndroidMock is not picking up the full classpath.

Could it be that this is because the path to the SDK is actually
specified in the "bootclasspathref" attribute of the ANT javac task?
(and not the standard classpath attribute)

Also.. where do I put the android_framework_mocks.jar? Should this
also be in the libs/ folder of the test project?

Thanks!

Stephen Woodward

unread,
Apr 27, 2011, 4:15:56 PM4/27/11
to androi...@googlegroups.com

Hi Jason,

This sounds familiar but I haven't looked at ant debugging in quite awhile. Putting the sdk jar in the classpath will likely work if I remember correctly but it might also cause the sdk classes to end up in your apk. It's worth an experiment anyhow.

Could you send me your ant file, and a verbose output of an attempted run with it?  That should have some useful information.

Thanks,

Steve

Jason

unread,
Apr 27, 2011, 6:53:40 PM4/27/11
to Android Mock Discussion
Hi Stephen,

This is proving to be a really confusing problem. When the Android
build script runs it's "compile" target (which is called if you call
the 'run-tests' target) it fires up the annotation processor as
expected, but the processor fails with ClassNotFound exceptions. As
you would probably know AndroidMock is then printing out the classpath
and the really weird thing is that (excluding android.jar) the other
classes that the annotation processor can't find (i.e. classes in my
main Android project) ARE listed in the classpath printed.

Now.. I have it working in eclipse so I have been working through what
the differences may be. The only difference I can see that is
meaningful is the configuration of the "annotation factory path" (as
per the PDF explanation for AndroidMock). As far as I can tell this
corresponds to the "-processorpath" command line parameter of javac.

Although the doco for -processorpath states "...searches for any
annotation processors that are available. The search path can be
specified with the -processorpath option" (http://download.oracle.com/
javase/6/docs/technotes/tools/solaris/javac.html) I wondered if
somehow the annotation processor was using this path as it's
classpath, rather than the classpath of the javac command itself.

The only reason for this assumption is that the eclipse setup
guidelines suggest that the Factory Path (which eclipse says is "Plug-
ins and JARs that contain annotation processors") should include ALL
the dependent libraries.

That is, the Factory Path needs to include the path to android.jar,
but technically this is not a location the compiler should look for an
annotation processor (at least not AndroidMock).

So anyway.. I created an override for the "compile" target shipped
with the Android SDK (in ant) and added a "-processorpath" option to
match the path configured as the Factory Path in eclipse.

Hasn't worked so far, but I think I have some unrelated issues I need
to resolve.

You should be able to reproduce the problem by simply creating a
android project with a test project, then creating a simple test which
uses a mock of an Android SDK class (eg ImageView), then calling the
run-tests target of the build.xml in the test project.

If this works for you, then I have clearly screwed something up.. but
my guess is it will fail.

I'll post back if my processorpath option works out.

Cheers,

Jason

On Apr 27, 1:15 pm, Stephen Woodward <sd.woodwar...@gmail.com> wrote:
> Hi Jason,
>
> This sounds familiar but I haven't looked at ant debugging in quite awhile.
> Putting the sdk jar in the classpath will likely work if I remember
> correctly but it might also cause the sdk classes to end up in your apk.
> It's worth an experiment anyhow.
>
> Could you send me your ant file, and a verbose output of an attempted run
> with it?  That should have some useful information.
>
> Thanks,
>
> Steve
>

Jason

unread,
Apr 27, 2011, 7:15:26 PM4/27/11
to Android Mock Discussion
ok.. update.

setting processorpath with the same path as the Factory Path in
eclipse didn't work, I got this error:

[javac] error: Exception thrown while constructing Processor object:
java.lang.NoClassDefFoundError: javassist/ClassPath


hmmm... so, I tried manually adding the same factory path as is in
eclipse to the classpath of the javac ANT task (called from the
"compile" target in the Android main_rules.xml ANT file).

Good news and bad news...

All the errors relating to MY classes went way, but I still can't
generate mocks for Android sdk classes. Here's the output:

[javac] Note: Mocking class android.widget.ImageView
[javac] error: Could not find android.widget.ImageView
[javac] error: java.lang.ClassNotFoundException:
v231.genmocks.android.widget.ImageViewDelegateSubclass
[javac] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[javac] at java.security.AccessController.doPrivileged(Native
Method)
[javac] at java.net.URLClassLoader.findClass(URLClassLoader.java:
190)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[javac] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[javac] at java.lang.Class.forName0(Native Method)
[javac] at java.lang.Class.forName(Class.java:169)
[javac] at
com.google.android.testing.mocking.AndroidFrameworkMockGenerator.getPrebuiltClassesFor(AndroidFrameworkMockGenerator.java:
80)
[javac] at
com.google.android.testing.mocking.AndroidFrameworkMockGenerator.getMocksForClass(AndroidFrameworkMockGenerator.java:
59)
[javac] at
com.google.android.testing.mocking.UsesMocksProcessor.getClassMocks(UsesMocksProcessor.java:
180)
[javac] at
com.google.android.testing.mocking.UsesMocksProcessor.getMocksFor(UsesMocksProcessor.java:
100)
[javac] at
com.google.android.testing.mocking.UsesMocksProcessor.process(UsesMocksProcessor.java:
75)
[javac] at
com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:
625)
[javac] at
com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:
554)
[javac] at
com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:
699)
[javac] at
com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:
981)
[javac] at
com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:279)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:270)
[javac] at com.sun.tools.javac.Main.compile(Main.java:69)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
[javac] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
[javac] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[javac] at
org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:
56)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:
1097)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:
906)
[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:
25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[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:
25)
[javac] at java.lang.reflect.Method.invoke(Method.java:597)
[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:390)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:
411)
[javac] at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1397)
[javac] at
org.apache.tools.ant.Project.executeTarget(Project.java:1366)
[javac] at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
41)
[javac] at
org.apache.tools.ant.Project.executeTargets(Project.java:1249)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:801)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:218)
[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] Note: Known Classpath:
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
bin/classes/
[javac] Note: file:/usr/local/newco/android/checkout/newco-android/
bin/classes/
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/AndroidMockGenerator-nodeps.jar
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/AndroidMockRuntime.jar
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/android_framework_mocks.jar
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/easymock.jar
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/javassist-newco.jar
[javac] Note: file:/Users/myuser/dev/workspace/newco-android-test/
libs/polidea_test_runner_1.1.jar
[javac] Note: file:/usr/local/newco/android/checkout/newco-android/
libs/commons-codec-1.4.jar
[javac] Note: file:/usr/local/newco/android/checkout/newco-android/
libs/FlurryAgent.jar
[javac] Note: file:/usr/local/newco/android/checkout/newco-android/
libs/ormlite-android-4.18.jar
[javac] Note: file:/usr/local/newco/android/checkout/newco-android/
libs/ormlite-core-4.18.jar
[javac] Note: file:/usr/local/android/platforms/android-8/
android.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
launcher.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
antlr.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-bcel.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-bsf.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-log4j.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-oro.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-regexp.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-resolver.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
apache-xalan2.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
commons-logging.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
commons-net.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
jai.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
javamail.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
jdepend.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
jmf.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
jsch.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
junit.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
netrexx.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
nodeps.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
swing.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/ant-
testutil.jar
[javac] Note: file:/Users/myuser/dev/java/apache-ant-1.8.1/lib/
ant.jar

The inexplicable thing is this:

[javac] Note: file:/usr/local/android/platforms/android-8/android.jar

I MANUALLY added that path to the classpath of the javac task, and
it's clearly in the classloader when the annotation processor runs (I
have double-checked that it is the correct path too)

and yet it can't find android.widget.ImageView, which is in
android.jar.

Weird...

I'm thinking I might go back to basics and just create a simple
android project, with a test project, using AndroidMock and see what
happens when I execute run-tests...

If you have done the same and have any insight I'd really appreciate
it.

Cheers,

Jason.

Jason

unread,
Apr 27, 2011, 8:37:45 PM4/27/11
to Android Mock Discussion
Just had a thought... it may be a whole lot easier to just not use
annotations at all.

If the AndroidMockGenerator could be wrapped in an ANT task, then I
could just manually nominate the classes that need to be mocked.

It's much less elegant I know, but may mean less digging around in the
Android build scripts...

Just a thought.
> > the differences may be.  The only difference I can...
>
> read more »

Jason

unread,
Apr 29, 2011, 3:03:02 PM4/29/11
to Android Mock Discussion
OK.. some new info...

First.. the ANT task is a bad idea. well.. not "bad" as such, just
problematic. Getting ANT to recognize the classpath for classes
generated DURING the build is difficult and requires a little too much
tinkering with the Android build scripts for my liking.

So.. back to annotation processing.

It "seems" (although this sounds kinda strange) that the
"bootclasspath" of the javac task does not become part of the
classpath given to annotation processors. As a consequence the
Android SDK jar (android.jar) is NOT in the classpath when the
AndroidMock annotation processor executes.

So far I have overcome this by overriding the "compile" task (from
main_rules.xml) and adding the "android.target.classpath" to the
classpath of the javac task. Although there may be a more elegant way
to just override the "jar.libs.ref" in the -pre-compile task to avoid
having to directly override the compile task.

Regardless, this leads to a new problem:

When the final test APK is build, I get this exception:

[apply] UNEXPECTED TOP-LEVEL EXCEPTION:
[apply] java.lang.IllegalArgumentException: already added: Lv15/
genmocks/android/widget/ImageViewDelegateInterface;
[apply] at
com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:
123)
[apply] at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
[apply] at
com.android.dx.command.dexer.Main.processClass(Main.java:372)
[apply] at
com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
[apply] at com.android.dx.command.dexer.Main.access$400(Main.java:
59)
[apply] at com.android.dx.command.dexer.Main
$1.processFileBytes(Main.java:294)
[apply] at
com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:
244)
[apply] at
com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:
130)
[apply] at
com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:
108)
[apply] at com.android.dx.command.dexer.Main.processOne(Main.java:
313)
[apply] at
com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
[apply] at com.android.dx.command.dexer.Main.run(Main.java:185)
[apply] at com.android.dx.command.dexer.Main.main(Main.java:166)
[apply] at com.android.dx.command.Main.main(Main.java:90)
[apply] 1 error; aborting

Now... the mock for ImageView is being created correctly, and as far
as I can tell there IS only one of them, but somehow the DEX compiler
is encountering a duplicate. I have no idea where this is coming
from.

Any thoughts on what might be happening here?

Thanks,

Jason.
> > it's...
>
> read more »

Jason

unread,
Apr 29, 2011, 3:09:26 PM4/29/11
to Android Mock Discussion
Strike that last post.. I realized the problem.

The android_framework_mocks.jar already contains a mock of the
ImageView class. My test was nominating this as a mocked object (via
annotation) so AndroidMock was generating this mock. Then because I
had android_framework_mocks.jar in the libs folder of my test project,
DEX was trying to include it twice.

I don't think I need the android_framework_mocks.jar when running
directly in ANT.

I'll post back with full solution once I'm sure it's working.

Cheers,

Jason.
> > > libs/android_framework_mocks.jar...
>
> read more »

Jason

unread,
Apr 29, 2011, 6:27:42 PM4/29/11
to Android Mock Discussion
OK.. I'm back, with good news and bad news.

The good news is that I managed to get it working, the bad news is
that it's a house of cards, and they're all the Queen of Hack.

So... the original error I posted was actually a red herring. The
error message was what confused me:

"Could not find android.widget.ViewFlipper"

because the next line of the trace (which I'm just realizing I didn't
include in the original post!).. was:

...v21.genmocks.android.widget.ViewFlipperDelegateInterface

which actually means it couldn't find the delegate interface.. not
that it couldn't find the Android class.

Then I suddenly understood the meaning of
android_framework_mocks.jar... it includes pre-generated mocks of ALL
the android classes. The "problem" with this is that it's quite large
(~20MB) and the build churns away trying to DEX 20MB of java code. So
I thought I'd do the decent thing and exclude this file.. which of
course leads back to the original error.

I then realized this is because Android mock (by default) will not re-
generate [Android] framework mocks and needs an "-A" compiler argument
(-ARegenerateFrameworkMocks=true). Unfortunately the "compile" target
in the Android build.xml doesn't provide any way to add compiler
arguments without overriding the entire target, which is what I ended
up doing.

The next problem was the prefix on the generated mock. AndroidMock
uses an Android API version prefix on generated classes (eg
v21.genmocks), but for reasons I don't quite understand the
"SdkVersion" class fails to determine the SDK version during
compilation. Hence the framework mock generated does not have a
prefix, but at runtime it does and so looks for the prefixed
versions.. which of course doesn't exist.

To overcome this, the simplest solution was for me to modify the
AndroidMock class and recompile the JAR file, which is far from the
ideal solution I know, but preferable to spending more time trying to
work out why the "android.os.Build$VERSION" is not available to
SdkVersion at compile time.

Finally I also needed to override the "extensible.classpath" variable
which is passed into the javac task during the compile target. For
some reason unless I manually add the classes of both my main project
and my test project to this classpath, AndroidMock fails to locate
them. This could be my crufty setup though, so may not be necessary.

So the final solution looks like this:

1. Change the source code of AndroidMock to ALWAYS us the base package
name for generated mocks, and not the prefixed version. SVN Patch...

Index: AndroidMock.java
===================================================================
--- AndroidMock.java (revision 14)
+++ AndroidMock.java (working copy)
@@ -2631,11 +2631,7 @@
Class<T> subclass;
String className = null;
try {
- if (isAndroidClass(clazz)) {
- className = FileUtils.getSubclassNameFor(clazz,
SdkVersion.getCurrentVersion());
- } else {
- className = FileUtils.getSubclassNameFor(clazz,
SdkVersion.UNKNOWN);
- }
+ className = FileUtils.getSubclassNameFor(clazz,
SdkVersion.UNKNOWN);
subclass = (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find class for " +
className
@@ -2780,11 +2776,7 @@
private static <T> Class<T> getInterfaceFor(Class<T> clazz) {
try {
String className;
- if (isAndroidClass(clazz)) {
- className = FileUtils.getInterfaceNameFor(clazz,
SdkVersion.getCurrentVersion());
- } else {
- className = FileUtils.getInterfaceNameFor(clazz,
SdkVersion.UNKNOWN);
- }
+ className = FileUtils.getInterfaceNameFor(clazz,
SdkVersion.UNKNOWN);
return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find mock for " +
clazz.getName()

2. Add the following to the build.xml of the TEST project:

<target name="-pre-compile" depends="override-extensible-classpath"/>
<target name="-set-coverage-classpath" depends="override-extensible-
classpath-instrumented"/>

<target name="override-extensible-classpath">
<path id="override.path">
<path refid="android.target.classpath"/>
<path refid="jar.libs.ref"/>
<pathelement location="${tested.project.absolute.dir}/bin/classes"/>
</path>

<property name="extensible.classpath" refId="override.path"/>
</target>

<target name="override-extensible-classpath-instrumented">
<path id="override.path">
<path refid="android.target.classpath"/>
<path refid="jar.libs.ref"/>
<pathelement location="${tested.project.absolute.dir}/bin/classes"/>
<pathelement location="${instrumentation.absolute.dir}/classes"/>
</path>
<property name="extensible.classpath" refId="override.path"/>
</target>

(The "instrumented" version(s) are only required if you're generating
EMMA coverage.. which I am)

3. Override the "compile" target, again ONLY in the TEST build.xml to
add the compiler argument:

<!-- Compiles this project's .java files into .class files. -->
<target name="compile" depends="-pre-build, -aidl, -renderscript, -
resource-src, -pre-compile"
description="Compiles project's .java files into .class
files">
<if condition="${manifest.hasCode}">
<then>
<!-- If android rules are used for a test project, its
classpath should include
tested project's location -->
<condition property="extensible.classpath"
value="${tested.project.absolute.dir}/bin/classes"
else=".">
<isset property="tested.project.absolute.dir" />
</condition>
<condition property="extensible.libs.classpath"
value="${tested.project.absolute.dir}/libs"
else="${jar.libs.dir}">
<isset property="tested.project.absolute.dir" />
</condition>
<javac encoding="${java.encoding}"
source="${java.source}" target="${java.target}"
debug="true" extdirs=""
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
verbose="${verbose}"
classpath="${extensible.classpath}"
classpathref="jar.libs.ref">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<src refid="project.libraries.src" />
<classpath>
<fileset dir="${extensible.libs.classpath}"
includes="*.jar" />
</classpath>

<compilerarg value="-ARegenerateFrameworkMocks=true"/>
</javac>
</then>
<else>
<echo>hasCode = false. Skipping...</echo>
</else>
</if>
</target>

4. Add the modified AndroidMockGeneratorRuntime.jar (with the altered
AndroidMock class) to the libs folder of the TEST project. I didn't
need AndroidMockGenerator.jar (?)


Now.. let me close by saying I know this is not the right solution..
but maybe the AndroidMock folks can use this info to modify/enhance
the library to be able to work with the default ANT build scripts
shipped with Android.

It's really close, and I think a few minor mods might get it there.

This is working for me "so far".. but I only have one fairly trivial
test using mocks so not sure if it's a "robust" solution or not.

Cheers,

Jason.
> > > >     [javac]     at...
>
> read more »

Stephen Woodward

unread,
Apr 30, 2011, 5:56:30 AM4/30/11
to androi...@googlegroups.com
Hi Jason,

I've added a new Wiki page to the Android Mock wiki: http://code.google.com/p/android-mock/wiki/AndroidMockMechanics

Hopefully that should help to explain some of what's going on.

I'm just on my way out the door and late, so I don't have time for a full response to this email, but I think the wiki page will help to clear things up.  The one quick thing worth mentioning is that the android-framework-mocks.jar was never intended to be part of the dex process.  AndroidMockGenerator.jar, during the compilation/annotation processing phase will select the required mock classes out of the framework jar file and include them as outputs of the compilation step.  If the files are missing from this jar file, then it's a sign that the given class is unmockable (i.e. cannot be subclassed).

If you'd like, please feel free to send me the log file and stdout of your compilation attempts with Android Mock, either on thread or to my personal account, and I'll have a look to see what's going on.

Thanks,

Steve

Daniel McCartney

unread,
May 4, 2011, 5:41:05 PM5/4/11
to androi...@googlegroups.com
I managed to get it working with Ant.  

I wrote how I modified the test project's build.xml to do it:

Matt

unread,
Sep 12, 2012, 12:17:33 PM9/12/12
to androi...@googlegroups.com
I know this is an old thread but I'm having this exact same problem - would you mind posting the solution?

Jason

unread,
Mar 20, 2013, 4:10:18 PM3/20/13
to androi...@googlegroups.com, mdel...@azavea.com
This is an old thread, and I don't think this project is even supported anymore.  Most (all) of the open issues have remains open since they were created and the issue in this thread is still unresolved.  I am trying to re-create my project structure because after so much tinkering with the Android build scripts (which have breaking changes on EVERY release) the whole thing is a mess.

It's a real shame, but even the simplest Android project when run using ANT will fail to mock any Android framework classes.  This has nothing to do with pre/post generated mocks and everything to do with the fact that the android.jar file is not in the classpath when javac is called.
Reply all
Reply to author
Forward
0 new messages