gpt4 book ai didi

android-espresso - java.lang.NoSuchFieldError : No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier

转载 作者:行者123 更新时间:2023-12-04 13:42:01 68 4
gpt4 key购买 nike

安卓工作室 3.3

我想用线模在我的 Espresso 测试。

构建.gradle:

buildscript {
ext.KOTLIN_VERSION = '1.3.21'
ext.ESPRESSO_VERSION = '3.2.0-alpha02'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

应用程序/build.gradle:
  buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.27.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
// Need to autocreate tasks crashlyticsUploadDistributionXXX
apply plugin: 'io.fabric'

repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}

def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(rootProject.file("app/keystore.properties")))

android {
dataBinding {
enabled = true
}

compileSdkVersion 28
defaultConfig {
applicationId "com.myproject.android"
minSdkVersion 18
targetSdkVersion 28
versionCode 6
versionName "0.0.8"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

multiDexEnabled true
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
//androidTest.assets.srcDirs += 'src/androidTest/assets'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true; }

implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha03'
implementation 'com.android.support:design:28.0.0'
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.yuyh.json:jsonviewer:1.0.6'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"

implementation project(':common')

androidTestImplementation "androidx.test.espresso:espresso-core:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-intents:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$ESPRESSO_VERSION"

androidTestImplementation 'androidx.test:rules:1.1.2-alpha02'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'

androidTestImplementation("com.github.tomakehurst:wiremock:2.18.0")

testImplementation 'junit:junit:4.12'
}

这里是 Espresso 的测试:
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions.*
import androidx.test.platform.app.InstrumentationRegistry
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import com.github.tomakehurst.wiremock.junit.WireMockRule

@RunWith(AndroidJUnit4::class)
class AddTraderActivityTest {
val context = InstrumentationRegistry.getInstrumentation().getContext()
val targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext()

@get:Rule
var addTraderIntentTestRule: IntentsTestRule<AddTraderActivity> = IntentsTestRule(AddTraderActivity::class.java)

@get:Rule
var wireMockRule = WireMockRule(wireMockConfig().port(8081))

@Test
fun toolbar_title() {
onView(withId(R.id.toolbaTitleTextView))
.check(matches(withText(R.string.traders)))
}

但我在这一行出现错误:
var wireMockRule = WireMockRule(wireMockConfig().port(8081))

java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar:classes2.dex)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:146)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:958)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:76)
at com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.<init>(ProxyResponseRenderer.java:58)
at com.github.tomakehurst.wiremock.core.WireMockApp.buildStubRequestHandler(WireMockApp.java:131)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:73)
at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:43)
at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:39)
at java.lang.reflect.Constructor.newInstance(Native Method)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:389)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)

最佳答案

我意识到这比你的问题来得晚,但我想发布我在遇到同样问题时发现的内容,以防其他人遇到它。

为了避免这个特定的问题,我不得不将 Gradle 中的依赖引用更改为 Wiremock 的独立变体

从:
androidTestImplementation("com.github.tomakehurst:wiremock:2.18.0")
到:
androidTestImplementation("com.github.tomakehurst:wiremock-standalone:2.18.0")
为了保持一致性,我保留了原始海报的 2.18.0 版本,但是,我在使用 2.26.0 版本时遇到了这个问题。

我不确定为什么独立版本的依赖项解决了这个问题,但我怀疑它与导致某种潜在冲突的另一个依赖项有关。

关于android-espresso - java.lang.NoSuchFieldError : No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55774353/

68 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com