升级支持库版本后出现无法解析符号错误

9
我希望有人能够解决这个问题。我正在尝试更改支持库的版本,从:

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中打开,而对于新版本,则无法在AS中打开

我感觉我已经尽力解决所有可用选项,所以如果有人能够解决这个问题,我会非常感激。

我的完整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支持库存储库是否是最新的? - RussHWolf
哈哈,你在几秒钟内赢了我! - CodeAlo
是的,它就是。http://imgur.com/0xum2uo - AndroidP
自从升级到23.1.1的build.gradle后,我遇到了与23.1.0相同的问题。 - Christian
我也是。但真正让我沮丧的是Google删除类的速度有多快。向后兼容性怎么办? - Ricardo
显示剩余4条评论
5个回答

2
我终于解决了问题:
首先,我更新了gradle插件。
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
}

然后只需构建->清理项目,一切就会重新运作。

1
我想我已经解决了这个问题,朋友们。进入你的项目中的主模块,通常它的名称为app
然后进入 > 打开模块设置 > 在属性中将构建工具版本更改为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'
    }
  }
}

你还需要确保项目中所有的模块都使用compileSdkVersion和buildToolsVersion版本号23,因为你将使用第23个版本的支持库。

谢谢,但是从我的初始Gradle文件中可以看出,我使用的构建工具版本已经是23.0.2了。 - AndroidP
你的项目只包含一个模块吗?如果你的项目中有多个模块,你也应该检查其他模块。 - Hafizh Herdi

0

我知道现在可能有点晚了,但我遇到了一个类似的问题。结果发现这个问题是由数据绑定库引起的。我的代码中有一个错误,它引用了一个无效的引用,在生成的绑定类中也出现了问题。我的布局文件定义了一个ID为webview的Webview,但在代码中我将其引用为webView。在纠正了这个错误并对Android Studio进行了清理和完整重建之后,它开始识别所有包并看到支持库了。


-2

我曾经遇到完全相同的问题,为了解决它,我只是将 BuildDebug 配置下拉菜单更改为 MainActivity

SPINNER


你是指什么是“BuildDebug配置”? - Ricardo
看屏幕截图!跟随红色箭头! - Christian

-3

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


1
你能详细解释一下吗?我不明白你的意思。 - AndroidP

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接