Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dexcache == null error #12

Open
sek opened this issue Mar 25, 2015 · 15 comments
Open

dexcache == null error #12

sek opened this issue Mar 25, 2015 · 15 comments

Comments

@sek
Copy link

sek commented Mar 25, 2015

This issue from the old google code project: https://code.google.com/p/dexmaker/issues/detail?id=2 is still valid as of the released 1.2 version

Java.lang.IllegalArgumentException: dexcache == null (and no default could be found; consider setting the 'dexmaker.dexcache' system property)
at com.google.dexmaker.DexMaker.generateAndLoad(DexMaker.java:359)
at com.google.dexmaker.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:252)
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:51)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:41)
...

However, I verified that it has been fixed in the current github repository (last commit March 12th 2015 - ca74669):

  • git clone https://github.com/crittercism/dexmaker.git
  • cd dexmaker
  • mvn install -Dmaven.test.skip=true
  • cp -R ~/.m2/repository/com/google/dexmaker $ANDROID_HOME/extras/android/m2repository/com/google
  • and then update project dependency to 1.3-SNAPSHOT

It would be nice to have a 1.3 release so that we can take the workaround lines out of the test setUp() methods:
System.setProperty("dexmaker.dexcache", getContext().getCacheDir().getPath());

Thanks!

@agampe
Copy link
Contributor

agampe commented Apr 20, 2015

Are you sure? I can't see any changes in the code path that would suggest it should not fail anymore.

I've added a pull request that updates the AppDataDirGuesser. It was out-of-date for any Android version 4.3+. With that it should be fine.

@ened
Copy link
Contributor

ened commented Jul 27, 2015

@sek please try 1.4.

@sek
Copy link
Author

sek commented Aug 4, 2015

I'm getting new errors in 1.3 and 1.4 =/

I pushed a simple demo project to github for reference: https://github.com/sek/MockitoOnAndroidDemo

To clone and run tests:

git clone https://github.com/sek/MockitoOnAndroidDemo
cd MockitoOnAndroidDemo
./gradlew connectedAndroidTest --stacktrace

It should also open smoothly in Android Studio 1.3 for editing.
The version of dexmaker can be modified on line 27 of app/build.grade

With dexmakerVersion == 1.2

All tests pass. Note that if this problem is fixed, DexmakerIssue12Test.testMockAndroidObject() should fail with "expected an Exception" message.

With dexmakerVersion == 1.3

com.stankurdziel.mockitodemo.DexmakerIssue12Test > testMockAndroidObject[Nexus_5_API_21_x86(AVD) - 5.0.1] FAILED
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/dexmaker/dx/rop/type/Type;
at com.google.dexmaker.TypeId.(TypeId.java:36)

com.stankurdziel.mockitodemo.DexmakerIssue12Test > testMockAndroidObjectWorkAround[Nexus_5_API_21_x86(AVD) - 5.0.1] FAILED
java.lang.NoClassDefFoundError: com.google.dexmaker.stock.ProxyBuilder
at com.google.dexmaker.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:55)
...

With dexmakerVersion == 1.4

com.stankurdziel.mockitodemo.DexmakerIssue12Test > testMockAndroidObject[Nexus_5_API_21_x86(AVD) - 5.0.1] FAILED
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/dx/rop/type/Type;
at com.android.dx.TypeId.(TypeId.java:36)

com.stankurdziel.mockitodemo.DexmakerIssue12Test > testMockAndroidObjectWorkAround[Nexus_5_API_21_x86(AVD) - 5.0.1] FAILED
java.lang.NoClassDefFoundError: com.android.dx.stock.ProxyBuilder
at com.android.dx.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:56)
...

@ened
Copy link
Contributor

ened commented Aug 4, 2015

Will look into it tonight.

@mjohenneken
Copy link

Are there updates on this issue? We simply don't get mockito working on Android Devices (API21). We're trying to mock Classes. We tried it with 1.4, no Chance..

@sek
Copy link
Author

sek commented Aug 13, 2015

Hi @mjohenneken ,
I'm still successfully using 1.2 with the workaround demonstrated here: https://github.com/sek/MockitoOnAndroidDemo/blob/master/app/src/androidTest/java/com/stankurdziel/mockitodemo/NormalUsageOfMockito.java

I think we are on API22 now, but pretty sure it worked fine on API21 also - just an inconvenience to have to have that line in your setUp() for every test mocking android classes.

-Stan

@vaughandroid
Copy link

@sek Could you try the build referenced in my pull request? #21

@mjohenneken
Copy link

I figured out that those dependencies make me able to write tests with Mockito, JUnit4 and Espresso on the Android Device. I had to add dexmaker-dx as dependency.

compile 'com.android.support:support-annotations:22.2.0'

androidTestCompile 'com.android.support.test:runner:0.3'

androidTestCompile 'com.android.support.test:rules:0.3'

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'

androidTestCompile 'org.mockito:mockito-core:1.10.19'

androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4'

androidTestCompile 'com.crittercism.dexmaker:dexmaker-dx:1.4'

androidTestCompile 'com.crittercism.dexmaker:dexmaker-mockito:1.4'

@vaughandroid
Copy link

@mjohenneken Thanks! Adding the dexmaker-dx dependency worked for me. 👍

@MatFl
Copy link

MatFl commented Apr 28, 2016

This is still a issue when trying to run local (non-android) tests in an android library module. It is working for application modules.

In the local tests the DexmakerMockMaker should not be used at all.

My current workaround is to provide a custom Mockito PluginSwitch which causes Mockito to use the default MockMaker.

@AnthonyUccello
Copy link

Hey guys I found a workaround for this that works:

https://comadeblog.wordpress.com/2013/11/12/dexcachenull-for-mockito-on-robolectric/comment-page-1/

Basically use 1.9 version of Mockito:

compile 'org.mockito:mockito-core:1.9.0'

@RyanNewsom
Copy link

@AnthonyUccello that worked for me. Can you guys fix this please however so we can use the latest 2.0 version?

@wongkwokfai
Copy link

@MatFl or anyone,
Could you exactly describe your implementation of Mockito PluginSwitch?

Many thanks!

@MatFl
Copy link

MatFl commented Feb 10, 2017

Newer versions of mockito (I think since mockito 2.6) support android out of the box. You can remove all the dexmaker dependencies and add the mockito-android instead. Check out the android-boilerplate project for an example: https://github.com/ribot/android-boilerplate/blob/master/app/build.gradle

@wongkwokfai
Copy link

@MatFi
Thanks for your quick reply.
FYI I manage to disable Dexmaker using PluginSwitch and mockito version 1.10.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants