dexmaker icon indicating copy to clipboard operation
dexmaker copied to clipboard

dexcache == null error

Open sek opened this issue 9 years ago • 15 comments

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!

sek avatar Mar 25 '15 00:03 sek

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.

agampe avatar Apr 20 '15 23:04 agampe

@sek please try 1.4.

ened avatar Jul 27 '15 06:07 ened

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) ...

sek avatar Aug 04 '15 07:08 sek

Will look into it tonight.

ened avatar Aug 04 '15 08:08 ened

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..

mjohenneken avatar Aug 13 '15 16:08 mjohenneken

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 avatar Aug 13 '15 17:08 sek

@sek Could you try the build referenced in my pull request? https://github.com/crittercism/dexmaker/pull/21

vaughandroid avatar Aug 27 '15 16:08 vaughandroid

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 avatar Aug 28 '15 09:08 mjohenneken

@mjohenneken Thanks! Adding the dexmaker-dx dependency worked for me. :+1:

vaughandroid avatar Sep 10 '15 08:09 vaughandroid

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.

MatFl avatar Apr 28 '16 08:04 MatFl

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 avatar May 13 '16 17:05 AnthonyUccello

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

RyanNewsom avatar Jun 22 '16 23:06 RyanNewsom

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

Many thanks!

wongkwokfai avatar Feb 09 '17 14:02 wongkwokfai

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

MatFl avatar Feb 10 '17 09:02 MatFl

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

wongkwokfai avatar Feb 10 '17 10:02 wongkwokfai