我是
Android编程的初学者.我正在尝试使用Android Studio创建一个基本的Hello World应用程序.在按照创建Hello World程序的初始步骤后,我立即在Java文件中遇到以下错误.
"Cannot resolve Symbol FloatingActionButton" "Cannot resolve Symbol Snackbar" "Cannot resolve Symbol AppCompatActivity" "Cannot resolve Symbol Toolbar"
正如您在附件Image中看到的那样,错误是红色的.
请帮帮我.
我的构建文件内容:
defaultConfig {
applicationId "com.example.helloworld.helloworld"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile filetree(dir: 'libs',include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
好像我已经添加了所有相关的依赖项.
解决方法
将带有空白活动的新模块插入现有项目后,我遇到了同样的问题.
我的模块的build.gradle文件看起来像这样:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsversion "23.0.1"
defaultConfig {
applicationId "com.example.networkingtest"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
}
为解决此问题,我将appcompat和设计依赖项的版本从23.1.0更改为23.0.1(注意:这与buildToolsversion中的版本相同).接下来,我点击“使用gradle文件同步项目”,然后点击Build>清洁项目.完成后项目将运行,但我将依赖版本更改回23.1.0,点击“使用gradle文件同步项目”,然后是Build>再次清理项目.现在一切正常.