你好,我刚在我正在开发的一个应用程序上迁移到Androidx。但是在我迁移之后,androidTest模块不能引用被测试的类。例如,我想测试com.work.appname.webservice包中的webservice模块,所以我需要在androidTest中导入类。但是当我迁移之后,测试类找不到要测试的类,那就是com.work.appname.webservice。无法解析符号'webservice‘无法解析符号Webservice
分级文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: "kotlin-allopen"
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'org.jetbrains.kotlin.android.extensions'
androidExtensions {
experimental = true
}
version = project.VERSION_NAME
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
mavenCentral()
mavenLocal()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
url "https://oss.sonatype.org/content/repositories/ksoap2-android-releases/"
}
maven {
url "https://maven.google.com"
}
flatDir {
dirs 'libs'
}
google()
}
android {
compileSdkVersion 32
buildToolsVersion "30.0.3"
packagingOptions {
exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
exclude 'build-data.properties'
return void
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 32
versionCode Integer.parseInt(project.VERSION_CODE)
versionName project.VERSION_NAME
testInstrumentationRunner "com.xxxxx.testutil.MultiDexAndroidJUnitRunner"
multiDexEnabled true
applicationId "com.xxxxx.expenses"
manifestPlaceholders = [
'appAuthRedirectScheme': project.CALLBACK_SCHEMA
]
buildConfigField "String", "CALLBACK_SCHEMA", '"' + project.CALLBACK_SCHEMA + '"'
}
buildTypes {
release {
zipAlignEnabled true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug{
minifyEnabled false
testCoverageEnabled = Boolean.parseBoolean(project.ENABLED_COVERAGE)
}
}
flavorDimensions("productFlavors")
productFlavors {
expenses {
applicationId "com.xxxxx.expenses"
}
expensesCitrix {
applicationId "com.xxxxx.expenses.citrix"
}
}
lintOptions {
abortOnError false
}
dexOptions {
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
jacoco {
toolVersion = "0.8.8"
reportsDir = file("$buildDir/customJacocoReportDir")
}
dependencies {
implementation 'com.xxxxx:common:4.4.4'
implementation 'com.google.code.gson:gson:2.8.2'
implementation(name: 'google-maps-sdk-m4b', ext: 'aar')
implementation 'commons-codec:commons-codec:1.15'
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
implementation 'junit:junit:4.13.2'
testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test.ext:junit:1.1.3'
testImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.annotation:annotation:1.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:core:1.5.0-alpha02'
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.10.0'
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0') {
exclude group: 'com.google.code.findbugs'
}
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
exclude group: 'com.google.code.findbugs'
}
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0', {
exclude group: 'com.google.code.findbugs'
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
allOpen {
annotation("com.xxxxx.expenses.util.OpenClass")
}
当我导入时,它似乎只找到androidTest中的类。有人知道解决办法吗?谢谢
发布于 2022-09-05 08:58:47
从build.gradle来看,一切看起来都很好。我检查过了,这是导入库的一个问题。如果使用Android从菜单迁移到AndroidX,重构>迁移到AndroidX,则需要运行单元测试并查看构建错误。有时从该菜单迁移到Android的自动化不能正常工作。
例如:它应该是import androidx.fragment.app.Fragment
而不是import androidx.core.app.Fragment
。您可以转到错误行并突出显示错误,然后看到Import class
按钮,只需单击
发布于 2022-11-14 07:45:22
我升级了我的build.gradle,然后测试类能够解析应用程序类。你必须更新你的分级版本。我的运行版本是7.3.1,没有测试错误。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
}
}
https://stackoverflow.com/questions/73551914
复制相似问题