Android的工作室,标志着中的R红色与错误信息"不能解析符号R"但是生成成功标志着、错误信息、符号、红色

2023-09-12 21:49:17 作者:感情不属于我

[编辑:这很有趣,近两年来,许多后来的版本这个问题却依然向新的答案。这个问题被写回天,当机器人工作室是一个不成熟和不稳定的α或β,我终于放弃了。两年后,Android的工作室现在是一个稳定的产品,我还没有遇到过这样的错误最近。]

[ It's funny that almost two years and many versions later this question is still getting new answers. This question was written back in the days when Android Studio was an immature and unstable alpha or beta which I finally gave up on. Two years later, Android Studio is now a stable product and I haven't encountered such bugs lately.]

在每一个项目中,我一直在努力,创建Android的工作室,R的所有用途都标记为红色,并显示错误消息无法解析符号R,但编译成功并运行应用程序。这实在是烦人,因为它会阻止自动完成,显示巨大的红色挥手线都在我的code。

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 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
    }
}

这是怎样的项目结构是这样的:

This is how the Project Structure looks like:

不知道如何解决这一问题?

Any idea how to fix this?

推荐答案

下面是我的临时解决方案,直到我找到更好的:

Here is my temporary solution until I find a better one:

使用一切,找到其中创建R.java。在我的情况下,它是 C:\ Program Files文件(x86)\Android\android-studio\system\compiler\<project-name>.cb969c52\.generated\aapt\<module-name>.6badd9a4\production\com\<project-name>\<module-name>

Using Everything, find where R.java is created. In my case it was C:\Program Files (x86)\Android\android-studio\system\compiler\<project-name>.cb969c52\.generated\aapt\<module-name>.6badd9a4\production\com\<project-name>\<module-name>

在项目视图,单击模块和preSS F4。忽略警告。

In the Project view, click the module and press F4. Ignore the warning.

点击+添加内容根,并选择上述文件夹中。请确保它被标记为蓝色(作为源)。

Click "+ Add Content Root" and select the aforementioned folder. Make sure it's marked in blue (as a source).

在我这样做,突然间所有的警告都没有了。问题是,如果你与其他人协作,文件夹名称为每台机器上的不同,因此在同步时要小心。

After I did this, suddenly all the warnings are gone. The problem is that if you collaborate with other people, the folder name is different on each machine so be careful when synchronizing.