Android 与proguard一起运行Robolectric
这些是测试依赖项:Android 与proguard一起运行Robolectric,android,proguard,robolectric,robolectric-gradle-plugin,Android,Proguard,Robolectric,Robolectric Gradle Plugin,这些是测试依赖项: // tests androidTestCompile 'org.mockito:mockito-all:1.10.8' androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1' androidTestCompile 'junit:junit:4.12' androidTestCompile ('org.robolectric:robolectric:2.4') { exclude mod
// tests
androidTestCompile 'org.mockito:mockito-all:1.10.8'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1'
androidTestCompile 'junit:junit:4.12'
androidTestCompile ('org.robolectric:robolectric:2.4') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
我的debug
构建类型启用了minifyEnabled true
,这样我就不会达到DEX方法的限制。完整建筑的定义如下:
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 15
targetSdkVersion 22
versionName VERSION_NAME
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile 'proguard-rules.pro'
}
signingConfigs {
debug {
storeFile file('keystore/debug.keystore')
}
}
productFlavors {
develop {
versionCode versionBuild()
signingConfig signingConfigs.debug
proguardFile 'proguard-rules-debug.pro'
}
}
buildTypes {
debug {
minifyEnabled true
}
}
有一个默认的proguard rules.pro
文件,还有一个额外的proguard rules debug.pro
文件用于味道
:proguardDevelopDebug
gradle任务根据我的选项成功通过。但是,:ProguardDevelopedebugandroidTest
失败,出现以下错误:
这很奇怪,因为我在文件中添加了以下内容:
-dontobfuscate
# ------------------- TEST DEPENDENCIES -------------------
-dontwarn org.hamcrest.**
-dontwarn com.squareup.**
-dontwarn com.google.android.**
-keep class com.google.android.** {
*;
}
-keep class com.google.common.** {
*;
}
-keep class org.hamcrest.** {
*;
}
# Apache Maven
-keep class org.apache.maven.** { *; }
-dontwarn org.apache.maven.**
# Junit
-keep class org.junit.** { *; }
-dontwarn org.junit.**
# Mockito
-keep class org.mockito.** { *; }
-dontwarn org.mockito.**
# Robolectric
-keep class org.robolectric.** { *; }
-dontwarn org.robolectric.**
你知道为什么这两个不能一起工作吗?你不需要proguard来为robolectric服务。它在JVM上运行,而dex根本没有发生。您是否有64k调试方法的问题?您使用什么依赖关系?预检调试并没有真正的帮助operation@EugenMartynov是的,如上所述,我达到了65k的极限。依赖项列表很长,在某些依赖项中使用
exclude
并不能真正帮助避免使用proguardAs for me proguard在调试中使用proguard是修复65k问题的最后一个选项。如果您使用play服务,那么您可以使用服务的确切部分()。您还可以使用debuggable=true
为Robolectric测试创建另一个构建配置,并为其切换proguard