【发布时间】:2019-03-25 02:31:53
【问题描述】:
帮帮我,我的 Android 无法解析符号 R(R 变为红色)但是当我尝试构建项目时,它成功了。有人知道为什么吗?我已经尝试过清理项目,重建项目,将项目与 gradle 文件同步,并使缓存无效并重新启动,但仍然无法解析 R
这是我的 gradle(应用程序):
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.justinjunias.stockitem"
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// Butterknife
implementation 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
//Design
implementation 'com.android.support:design:28.0.0'
//Volley
implementation 'com.android.volley:volley:1.1.1'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'com.google.firebase:firebase-firestore:18.1.0'
}
还有我的 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.3.2'
//Firebase
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
【问题讨论】:
-
“cannot resolve symbol R” 是构建 Android 应用程序(针对初学者)时最常见的错误。我们需要查看错误来隔离它。
-
如果你的所有依赖都添加好了,做无效缓存并重启Android Studio。也许它会工作。
-
当我运行应用程序时,它成功但 R 仍然是红色/无法解析
-
你的 android studio 版本是多少。
-
@VishrutMavani 我的安卓版本是 3.2.1
标签: android