【问题标题】:Cannot Resolve Symbol 'App'无法解析符号“应用程序”
【发布时间】:2016-12-21 15:41:58
【问题描述】:

所以我强迫 Android Studio 在停止 gradle 构建的过程中停止(我知道,我多么愚蠢),因为它需要很长时间并且它一直没有响应,当我打开它时它没问题,我可以创建一个新的布局文件,但是当我创建一个新的 java 类时,它决定不喜欢在我的任何 java 类中导入 android.support.v7.app.AppCompatActivity (但如果我不打开它们查看它们,没有红色波浪下划线),它说它“无法解析符号'app'”。我找不到与此特定问题有关的任何问题,并且我已经尝试了有关整个导入问题的解决方案。我尝试过清理和重建、使缓存失效并重新启动、制作项目、构建 APK、关闭和重新打开项目、关闭和重新打开 Android Studio...

除了上次编译说升级到 24.1.1 之外,应用程序文件似乎还可以,但是当我这样做时,它说“此支持库不应使用与 compileSdkVersion(23) 不同的版本 (24)”,但是如果我将 compileSdkVersion 更改为 24,它会说它“无法在 [sdk] 中找到带有哈希字符串 'android-24' 的目标”。
应用文件:

//noinspection GradleCompatible
//noinspection GradleCompatible
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "24.0.1"

defaultConfig {
    applicationId "abigailbannister.qmbtour"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

Build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

java类的一般结构:

package abigailbannister.qmbtour;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Created by Abigail on 15/08/2016.
 */
public class basic_activity extends AppCompatActivity{

     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basic_layout);

    }
}

布局文件的基本结构:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="."
android:clickable="true"
android:background="#FFFFFF">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/header_image"
    android:src="@drawable/qmb_logo"
    android:layout_marginBottom="483dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

Android 清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="abigailbannister.qmbtour">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".LanguageSelectionActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".EnglishWelcomeActivity">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".FrenchWelcomeActivity">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MenuActivity">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

抱歉所有代码,但我不知道如何解决这个问题:/

【问题讨论】:

  • 您的 android-studio 中是否安装了 API 24 SDK?
  • 看来这里的错误很清楚了;在尝试使用它们之前,您必须先下载最新的库;转到您的 SDK 管理器并安装它们
  • 我没有,但现在可以了!谢谢!
  • 小提示,将basic_activity重命名为BasicActivity,java类应该是这样命名的

标签: java android android-studio android-gradle-plugin android-studio-2.1


【解决方案1】:

这意味着您的系统上没有安装 android 最新的 SDK。请更新 SDK 并为支持库使用相同的版本 24。

【讨论】:

    【解决方案2】:

    我在 2018 年 12 月的 28.0.0 中遇到了同样的问题,我已经正确清理并关闭了项目。事实上,其他人已经从 Github 中提取了该项目并运行它没有任何问题。当我尝试打开它时,AppCompatActivity 导入无法解析应用程序。

    看完上面我打开SDK管理器,验证我安装了28;我做到了。所以我关闭了 SDK 管理器。

    并且AS必须在关闭窗口时刷新了它的SDK信息,因为所有错误在关闭SDK管理器窗口后2秒就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多