У меня есть этот тест:
@RunWith(AndroidJUnit4.class)
public class TestDataDaoTest {
private ApplicationDatabase dataBase;
private TestDataDao testDataDao;
@Before
public void initDb() {
dataBase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(),
ApplicationDatabase.class)
// allowing main thread queries, just for testing
.allowMainThreadQueries()
.build();
testDataDao = dataBase.testDataDao();
}
@After
public void tearDown() {
dataBase.close();
}
@Test
public void someTest() {
}
}
когда я запускаю этот тест, я получаю исключение NoSuchMethodError
:
java.lang.NoSuchMethodError: No virtual method close()V in class Lcom/example/example/database/ApplicationDatabase; or its super classes (declaration of 'com.example.example.database.ApplicationDatabase' appears in /data/app/com.example.exampleModule-2/base.apk)
at com.example.example.database.dao.TestDataDaoTest.tearDown(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Unknown Source)
at org.junit.internal.runners.model.ReflectiveCallable.run(Unknown Source)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(Unknown Source)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(Unknown Source)
at org.junit.runners.ParentRunner.runLeaf(Unknown Source)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(Unknown Source)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(Unknown Source)
at org.junit.runners.ParentRunner$3.run(Unknown Source)
at org.junit.runners.ParentRunner$1.schedule(Unknown Source)
at org.junit.runners.ParentRunner.runChildren(Unknown Source)
at org.junit.runners.ParentRunner.access$000(Unknown Source)
at org.junit.runners.ParentRunner$2.evaluate(Unknown Source)
at org.junit.runners.ParentRunner.run(Unknown Source)
at android.support.test.runner.AndroidJUnit4.run(Unknown Source)
at org.junit.runners.Suite.runChild(Unknown Source)
at org.junit.runners.Suite.runChild(Unknown Source)
at org.junit.runners.ParentRunner$3.run(Unknown Source)
at org.junit.runners.ParentRunner$1.schedule(Unknown Source)
at org.junit.runners.ParentRunner.runChildren(Unknown Source)
at org.junit.runners.ParentRunner.access$000(Unknown Source)
at org.junit.runners.ParentRunner$2.evaluate(Unknown Source)
at org.junit.runners.ParentRunner.run(Unknown Source)
at org.junit.runner.JUnitCore.run(Unknown Source)
at org.junit.runner.JUnitCore.run(Unknown Source)
at android.support.test.internal.runner.TestExecutor.execute(Unknown Source)
at android.support.test.runner.AndroidJUnitRunner.onStart(Unknown Source)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1886)
Я думаю, что это связано с Proguard, так что это моя конфигурация Proguard:
Gradle:
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
testProguardFile 'proguard-test-rules.pro'
proguardFile 'proguard-project.txt'
}
}
proguard-test-rules.pro:
# Proguard rules that are applied to your test apk/code.
-ignorewarnings
-keepattributes *Annotation*
-dontnote junit.framework.**
-dontnote junit.runner.**
-dontwarn android.test.**
-dontwarn android.support.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter
-keepclassmembers class android.arch.** { *; }
-keep class android.arch.** { *; }
# Uncomment this if you use Mockito
#-dontwarn org.mockito.**
ProGuard-project.txt:
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn com.flurry.**
-dontwarn javax.**
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn org.joda.convert.**
-dontobfuscate
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keepattributes *Annotation*
-keepclassmembers class * {
@org.greenrobot.eventbus.Subscribe *;
}
удаление proguard & minify из отладочной сборки невозможно.
есть идеи?
спасибо!