Android Studio 将 R 标记为红色并显示错误消息“无法解析符号 R",但构建成功 [英] Android Studio marks R in red with error message "cannot resolve symbol R", but build succeeds

查看:24
本文介绍了Android Studio 将 R 标记为红色并显示错误消息“无法解析符号 R",但构建成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我尝试在 Android Studio 中创建的每个项目中,R 的所有用法都标记为红色,并带有错误消息无法解析符号 R",但编译成功且应用程序运行.这真的很烦人,因为它会阻止自动完成并在我的代码中显示巨大的红色波浪线.

In every project I've tried to create in Android Studio, all usages of R are marked in red with the error message "cannot resolve symbol R", but the compilation succeeds and the application runs. This is really annoying, as it blocks auto-completion and shows huge red waved lines all over my code.

我正在运行 Android Studio 1.7.0 并使用默认设置创建项目.附上截图:

I'm running Android Studio 1.7.0 and creating the project with default settings. A screenshot is attached:

这是我的build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

这是项目结构的样子:

知道如何解决这个问题吗?

Any idea how to fix this?

推荐答案

确保您的 AndroidManifest.xml 中的包名称正确.当我的 R.whatever 被标记为红色时,这为我解决了问题!

Make sure in your AndroidManifest.xml the package name is correct. That fixed the problem for me when my R.whatever was marked red!

我还建议您检查所有 gradle 文件以确保这些包名称正确.这不应该使所有内容变红,但它会阻止您的 gradle 文件正确同步.

I would also recommend checking all your gradle files to make sure those package names are correct. That shouldn't make everything red, but it will stop your gradle files from syncing properly.

这篇关于Android Studio 将 R 标记为红色并显示错误消息“无法解析符号 R",但构建成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆