我已经安装了Android SDK平台28和Android 28的Sources。我的项目可以正确构建。但是,当我查看SDK源代码(例如Activity.java)时,Android Studio会向我显示烦人的错误(无法解析符号)。我尝试重新安装Android SDK平台28和适用于Android 28的源,并使缓存/重新启动Android Studio无效,但是它们都没有帮助。我比较了android.jar的结构和SDK中的sources目录,发现有
源目录中的类比android.jar多。我猜想源代码和android.jar文件不匹配,但我不知道如何解决。我尝试在新的Ubuntu虚拟机上安装Android Studio和SDK,Android Studio向我显示了相同的错误。
下面是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
}
答案 0 :(得分:0)
尝试以下方法之一:
1)您可以执行File-> Invalidate Caches / Restart
,然后选择Invalidate and Restart
选项来解决此问题。
2)选择工具-> android-> SDK manager
并下载所有SDK build tools
,SDK platform
和Google API's
3)清理项目并重建
4)备份您的项目。删除所有.iml
文件和.idea
文件夹重新启动Android Studio并重新导入您的项目。
5)compileSdkVersion 29
和targetSdkVersion 29