无法解析的符号“支持”(采用Android工作室,下面的入门指南)符号、入门、工作室、指南

2023-09-06 03:45:03 作者:顾凉

我开始学习Android开发。 我跟了这Getting入门指南,使用 Android的工作室(不偏食)。

我跑的Hello World我的设备上,到目前为止,一切顺利。但是..

问题将在此导入开始:(按指示由导)

 进口android.support.v4.app.NavUtils; //无法解析的符号支持
 

好像它需要通过这条线(注释,并自动解决进口没有工作)

  NavUtils.navigateUpFromSameTask(本);
 

支持导入红色下划线,鼠标悬停告诉我无法解析符号支持

构建无法工作或者ofcourse。我见过的答案类似的问题,例如; 这表明清除缓存和retarting(试过了), 提示运行SDK管理器作为管理员和更新(试过了), 还有一些其他的问题/解决方案显得黯然失色具体。

我是新的Andr​​oid开发和IDE。关于如何在Android的工作室v0.2.9修复此?

编辑:

我build.gradle文件的内容

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径com.android.tools.build:gradle:0.5.+
    }
}
应用插件:'机器人'

库{
    mavenCentral()
}

安卓{
    compileSdkVersion 17
    buildToolsVersion17.0.0

    defaultConfig {
        的minSdkVersion 7
        targetSdkVersion 16
    }
}

依赖{

    //您必须安装或通过SDK管理器更新支持库使用这种依赖性。
    //的支持库(独立于相应的库)可以在额外类别下找到。
    //编译com.android.support:appcompat-v7:18.0.0
}
 
Android学习笔记之 Android Studio的安装 java的基本语法及Android的概述

解决方案

修改您的摇篮文件,如下图所示,并尝试是否可行。

  ......

    依赖{
       编译com.android.support:support-v4:18.0.0

        //您必须安装或通过SDK管理器更新支持库使用这种依赖性。
        //的支持库(独立于相应的库)可以在额外类别下找到。
        //编译com.android.support:appcompat-v7:18.0.0
    }
 

I am getting started with Android development. I have followed this Getting Started guide and use Android Studio (not eclipse).

I ran Hello World on my device, so far so good. But..

Problem starts when adding this import: (as instructed by the guide)

import android.support.v4.app.NavUtils;  // cannot resolve symbol 'support'

Seems its needed by this line (commenting it and auto-resolving the import didnt work)

NavUtils.navigateUpFromSameTask(this);

The support import is red underlined, mouseover tells me Cannot resolve symbol 'support'

Build wont work either ofcourse. I have seen answers to similar questions such as; suggesting clearing cache and retarting (tried that), suggesting running SDK Manager as Administrator and updating (tried that), and some other problems/solutions that seem eclipse specific.

I am new to Android development and the IDE. How about fixing this in Android Studio v0.2.9 ?

Edit:

Contents of my build.gradle file

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

解决方案

Modify your gradle file like below and try if it works.

......

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