[英]Test case success with Unit test but fails with Instrumented Test with NoSuchMethodError
我有一個 java maven 庫,我想在我的 Android 應用程序中使用它(這是庫)當我嘗試啟動像ZoldWts api = new RestfulZoldWts("key");
我得到 NoSuchMethodError。
java.lang.NoSuchMethodError: 在類 Lorg/apache/http/client/protocol/RequestDefaultHeaders 中沒有直接方法 (Ljava/util/Collection;)V; 或其超類('org.apache.http.client.protocol.RequestDefaultHeaders' 的聲明出現在 /system/framework/org.apache.http.legacy.boot.jar 中)
我如何將圖書館添加到我的成績中? compile 'com.amihaiemil.web:zold-java-client:0.0.1'
但是,我收到以下錯誤
發現多個文件與操作系統無關的路徑“META-INF/DEPENDENCIES”
我通過將其添加到我的 gradle 中解決了這個問題
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
為了確保庫沒有損壞,我編寫了一個單元測試並成功運行。 不幸的是,儀器測試沒有。 我嘗試通過useProguard false
禁用 proguard 沒有用。 我還嘗試將以下內容添加到我的 proguard 規則中
-保持類org/apache/http/client/protocol/.* { *; }
還是沒用。
我的gradle文件:
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
compileSdkVersion 28
defaultConfig {
applicationId "com.zold.ammar.zold_android"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// Zold Java
compile 'com.amihaiemil.web:zold-java-client:0.0.1'
}
我的測試代碼(完全相同的代碼在單元測試中有效,但在插樁測試中無效)
@Test
public void zoldinittest() {
ZoldWts api = new RestfulZoldWts("key");
assertNotNull(api);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.