Android 本地单元测试通过,但编辑器窗口“无法解析符号”

问题描述 投票:0回答:0

Android Studio 的编辑器抱怨它无法解析单元测试中的符号,尽管

main/
test/
中的目录结构匹配正确。

尽管如此,测试还是会通过...

我已经使缓存失效并重新启动,并在

~/.gradle
中清除了我的 Gradle 缓存,但我只希望前者会对编辑器窗口产生任何影响,因为 - 就像我说的 - 测试 does 通过.

这个问题只有在我删除文件夹结构中不需要的层时才会出现:

agent2/app/src

成为

agent2/src

并且没有对任何

app
文件夹的引用

(显然这是对真实项目的简化)

文件结构

top-level-project
  agent2/
    src/
      main/
        com/
          level1/
            Class1.java
            level2/
              Class2.java
      test/
        com/
          level1/
            Class1Test.java

agent2 build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 30
    buildToolsVersion "29.0.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 30
        versionCode 1
        versionName productVersionName
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
            unitTests.returnDefaultValues = true
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-common:2.2.0'

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.json:json:20190722'
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'
    testImplementation 'org.powermock:powermock-core:2.0.7'
    testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
    testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
}

configurations {
    all*.exclude group: 'commons-logging', module: 'commons-logging'
    all*.exclude group: 'com.android.support', module: 'support-annotations'
}

顶级设置.gradle

rootProject.name = "top-level-proj"
include "agent2"

顶层build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id "com.jfrog.artifactory" version "4.24.14"
    id "maven-publish"
}

apply from: 'publish.gradle'

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
java android gradle
© www.soinside.com 2019 - 2024. All rights reserved.