【问题标题】:Cannot resolve symbol upon support library version change支持库版本更改时无法解析符号
【发布时间】:2016-01-25 18:35:33
【问题描述】:

我希望有人能对这个问题有所了解。我正在尝试从以下位置更改支持库版本:

compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'

compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:support-v13:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

通常看起来像一个简单的小升级已经让我整天忙活。基本上在更新 gradle.build 文件时,我同步 -> 清理,并且在 IDE 上出现了一堆无法解析符号错误,用于支持库中的类。

更有趣的是,如果我尝试通过 adb 在手机上运行代码,尽管 AS 显示为“无法解析符号”,但它在我的手机上运行良好。

在我尝试过的事情中:

  1. 清理/重建
  2. 使缓存无效/重新启动
  3. 删除所有 .iml 文件和 .idea 文件夹
  4. 重新安装 Android Studio,重新导入项目
  5. 正在重新启动

深入研究构建目录,它们在某种意义上是相似的

build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.0\jars\classes.jar

build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.1.1\jars\classes.jar

分别生成。不同的是,在AS中,对于之前的版本,“classes.jar”在AS中可以是opened,而在新版本中,它们在AS中是cannot be opened

我觉得我已经用尽了所有可用的选项,所以如果有人能阐明如何解决这个问题,我将不胜感激。

我的完整 gradle.build 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.XXX"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.1.1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(path: ':XXX', configuration: 'android-endpoints')
    testCompile 'junit:junit:4.12'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.balysv:material-ripple:1.0.2'
    compile 'net.sf.flexjson:flexjson:3.3'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.google.android.gms:play-services-ads:8.1.0'
    compile 'com.google.android.gms:play-services-identity:8.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile 'com.android.support:support-annotations:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:support-v13:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
}

【问题讨论】:

  • 可能是个愚蠢的问题,但是您的 sdk 管理器中的 Android 支持存储库是最新的吗?
  • 哈哈,你赢了我几秒钟!
  • 是的。 imgur.com/0xum2uo
  • 我在 build.gradle 中从 23.1.0 升级到 23.1.1 后遇到了同样的问题
  • 我也是。但真正让我感到沮丧的是谷歌删除课程的速度有多快。向后兼容性会发生什么?

标签: android android-studio android-support-library


【解决方案1】:

我终于解决了:

首先,我更新了gradle插件。

dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
}

然后只需构建->清理项目,一切都会再次运行。

【讨论】:

    【解决方案2】:

    我想我已经解决了这个问题。转到项目中的主模块,它的名称通常为 app

    然后转到 > Open Module Settings > 在 Properties 中将 Build Tools Version 更改为 23.0.1 .

    然后确保打开 build.gradle 文件,并将 compileSDKVersion 和 buildToolsVersion 分别更改为 23 和 23.0.1。

    android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    
    defaultConfig {
        applicationId "id.web.twoh"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
      }
    }
    

    您还应确保项目中的所有模块都具有以 23 开头的 compileSdkVersion 和 buildToolsVersion,因为您将使用第 23 版的支持库。

    【讨论】:

    • 谢谢,但从我最初的 gradle 文件中可以看出,我使用的构建工具版本已经是 23.0.2
    • 您的项目是否只包含一个模块?如果您的项目中有多个模块,则应同时检查其他模块
    【解决方案3】:

    我知道已经晚了,但我遇到了类似的问题。原来这个问题是由数据绑定库引起的。我在生成的绑定类中的无效引用中引用的代码中有错误。我的布局文件定义了一个 id 为 webview 的 webview,但在代码中我将它引用为 webView。在纠正错误并清理并进行完全重建后,Android Studio 开始识别所有包并查看支持库。

    【讨论】:

      【解决方案4】:

      完全遇到了同样的问题,为了解决它,我刚刚将 BuildDebug Configuration 微调器更改为 MainActivity

      【讨论】:

      • “BuildDebug 配置”对您意味着什么
      • 查看屏幕截图!跟着红色箭头走!
      【解决方案5】:

      我通过在工具栏中将运行/调试配置微调器更改为 MainActivity(而不是 app[androidDepedencies])解决了我的问题...

      【讨论】:

      • 你能详细说明一下吗?我不明白你的意思。
      猜你喜欢
      • 2015-08-28
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-18
      • 2018-11-11
      • 1970-01-01
      相关资源
      最近更新 更多