dexmaker
dexmaker copied to clipboard
dexcache == null error
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!
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.
@sek please try 1.4.
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.
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.
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) ...
Will look into it tonight.
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..
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
@sek Could you try the build referenced in my pull request? https://github.com/crittercism/dexmaker/pull/21
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'
@mjohenneken Thanks! Adding the dexmaker-dx
dependency worked for me. :+1:
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.
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'
@AnthonyUccello that worked for me. Can you guys fix this please however so we can use the latest 2.0 version?
@MatFl or anyone, Could you exactly describe your implementation of Mockito PluginSwitch?
Many thanks!
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
@MatFi Thanks for your quick reply. FYI I manage to disable Dexmaker using PluginSwitch and mockito version 1.10.19