无法解析符号'支持'(使用Android Studio,以下入门指南)

Bar*_*aes 7 import android android-studio

我开始使用Android开发了.我已按照本入门指南使用Android Studio(不是eclipse).

我在我的设备上运行了Hello World,到目前为止一直很好.但..

添加此导入时问题开始:(按照指南的说明)

import android.support.v4.app.NavUtils;  // cannot resolve symbol 'support'
Run Code Online (Sandbox Code Playgroud)

似乎这条线需要它(评论它并自动解决导入没有工作)

NavUtils.navigateUpFromSameTask(this);
Run Code Online (Sandbox Code Playgroud)

mouseover告诉我,支持导入是红色下划线 Cannot resolve symbol 'support'

建造不会在任何一个地方工作.我已经看到类似问题的答案,如; 建议清除缓存和重新启动(尝试过),建议以管理员身份运行SDK Manager并更新(尝试过),以及其他一些看起来特别具体的问题/解决方案.

我是Android开发和IDE的新手.如何在Android Studio v0.2.9中修复此问题?

编辑:

我的build.gradle文件的内容

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

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

dependencies {

    // You must install or update the Support Repository through the SDK manager to use this dependency.
    // The Support Repository (separate from the corresponding library) can be found in the Extras category.
    // compile 'com.android.support:appcompat-v7:18.0.0'
}
Run Code Online (Sandbox Code Playgroud)

red*_*lue 15

修改您的gradle文件,如下所示,并尝试它是否有效.

......

    dependencies {
       compile 'com.android.support:support-v4:18.0.0'

        // You must install or update the Support Repository through the SDK manager to use this dependency.
        // The Support Repository (separate from the corresponding library) can be found in the Extras category.
        // compile 'com.android.support:appcompat-v7:18.0.0'
    }
Run Code Online (Sandbox Code Playgroud)


Fir*_*his 8

使用GUI修复Android Studio,无需直接编辑Gradle文件(从Android Studio v1.0.1到v2.2.3开始验证):

  1. 在项目树中右键单击您的模块.它是根节点中的一个,在大多数情况下是第一个.默认情况下,它被调用app.

  2. 在菜单中选择" 打开模块设置":

    在此输入图像描述

  3. 切换到" 依赖关系"选项卡.

  4. 单击对话框窗口底部的添加按钮(+).

  5. 选择Library Dependency.

  6. support-v4从列表中选择.

  7. 单击" 确定"并重建.


Seb*_*Roy 6

而不是编辑build.gradle我在你的根项目上使用鼠标右键 - >打开模块设置 - >依赖项选项卡 - > + - > Maven依赖项 - >搜索"NavUtils"并选择com.google.android:support-v4:r7@jar.

SDK版本19和Android Studio 0.4.2