java - 无法解析符号 'App'

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

所以我强制 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 list 文件:

<?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 最新的 SDK。请更新 SDK 并为支持库使用相同的版本 24。

关于java - 无法解析符号 'App',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955002/

相关文章:

android-studio - 使用其他 gradle 文件中的 Gradle 函数

java - Hibernate Natural ID 重复问题

android - 在android中编译boost时出错

android - Android客户端错误-java.lang.IllegalStateException : Could not execute method of the activity

java - 在 Java 和 Android Studio 中检查当前时间与特定时间

android - 安全异常 : Not allowed to start an Activity Intent

java - 将字符连接到字符串 - 使用 StringBuilder 的 append()

java - 如何从 xhtml 中的 commandButton 重定向到 Servlet

java - 使用循环创建待定数量的对象

android - GridView ImageView 在不同屏幕下的大小