Android Studio无法找到现有符号

时间:2021-12-02 00:28:33

I've recently decided to change my work environment from Eclipse to Android Studio. I decided to import my Eclipse project through Android Studio.

我最近决定将我的工作环境从Eclipse改为Android Studio。我决定通过Android Studio导入我的Eclipse项目。

Problem is, when I compile my code, I come across 2 errors which says that it cannot find two existing symbols. These symbols are in fact two png pictures which are saved in res < drawable < hdpi. Still, the program can't locate just these two pictures. I have a bunch of other pictures which works perfectly in the same folder. I have controlled this by removing the two pictures causing me the errors and tested the app with successful results.

问题是,当我编译我的代码时,我遇到了2个错误,说它找不到两个现有的符号。这些符号实际上是两个png图片,保存在res

Here is the entire error message:

这是完整的错误消息:

(1)

Error:(101, 32) error: cannot find symbol variable thegodfather
Error:(101, 78) error: cannot find symbol variable kingofcomedy
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

(2)

/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol
            flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy,
                                        ^
  symbol:   variable thegodfather
  location: class drawable
/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol
            flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy,
                                                                                      ^
  symbol:   variable kingofcomedy
  location: class drawable
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

(3)

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0.
         Searched in the following locations:
         file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom
         file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar
         https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar
         Required by:
         :v11:unspecified
         Consult IDE log for more details (Help | Show Log)

The pictures are saved in an array and here's the array:

图片保存在一个数组中,这是数组:

flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy,
                     R.drawable.drstrangelove}

The two R.drawables which aren't working are .thegodfather and .kingofcomedy.

没有工作的两个R.drawables是.thegodfather和.kingofcomedy。

I have checked that the resources actually exists, and even removed and replaced them, without any luck.

我已经检查过资源确实存在,甚至删除并替换它们,没有任何运气。

I have looked around Stack to find an answer and found many similar problems but those one's were solved by either cleaning the project, invalidating and restarting or rebuilding or even restarting the program. None of these have worked for me.

我查看了堆栈以找到答案,发现了许多类似的问题,但是通过清理项目,无效并重新启动或重建甚至重新启动程序来解决这些问题。这些都不适合我。

Here is my gradle.build code:

这是我的gradle.build代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"


    defaultConfig {
        applicationId "com.exple.v1"
        minSdkVersion 15
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])

}

And here is the beginning of my manifest file just in case anyone needs to have a look at it:

这是我的清单文件的开头,以防任何人需要查看它:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exple.v1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="23" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

After looking around a bit, I think I've found my problem but I'm not sure where to Implement the solution code, which is in the link if you click on it. Is it the upper or lower gradle build ?

看了一下后,我想我已经找到了我的问题,但我不确定在哪里实施解决方案代码,如果你点击它就在链接中。是上层还是下层建筑?

2 个解决方案

#1


0  

It is one of your issue. I don't know if it will solve the others.

这是你的问题之一。我不知道它是否会解决其他问题。

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0.

This version doesn't exist.

此版本不存在。

Check your top-level build.gradle. You should use the version 1.3.0 instead of 23.0.0.

检查您的*build.gradle。您应该使用版本1.3.0而不是23.0.0。

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

It is the gradle plugin for android, and it is not related with the sdk.

它是android的gradle插件,它与sdk无关。

#2


0  

Your problem is not the resources. The problem is that your build tools cannot be found:

你的问题不是资源。问题是找不到您的构建工具:

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0.

The tools needed to generate your resource file (containing all your resource id's) cannot be found, which means that your R class is never generated and so the Java compiler complains that the symbols cannot found.

无法找到生成资源文件(包含所有资源ID)所需的工具,这意味着您的R类永远不会生成,因此Java编译器会抱怨无法找到符号。

You've indicated that you have all the latest Android SDK updates, but are you sure that Android Studio is pointing to the correct Android SDK location? Presumably, you were using some instance of the Android SDK for Eclipse - but Android Studio comes with it's own instance of the Android SDK and may not be using the one you think it is.

您已经表明您拥有所有最新的Android SDK更新,但是您确定Android Studio指向正确的Android SDK位置吗?据推测,您使用的是Android SDK的一些实例 - 但Android Studio附带了自己的Android SDK实例,可能没有使用您认为的那个。

Have a look at the paths in the error:

看看错误中的路径:

Searched in the following locations:
         file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom

Does this path exist on your computer? Is it where your Android SDK is installed? And can you find the 23.0.1 build tools folder in that location? If not, you probably need to fix this to resolve your issues - this question might help you out.

您的计算机上是否存在此路径?它是安装Android SDK的地方吗?你能在那个位置找到23.0.1构建工具文件夹吗?如果没有,您可能需要解决此问题以解决您的问题 - 这个问题可能会帮到您。

#1


0  

It is one of your issue. I don't know if it will solve the others.

这是你的问题之一。我不知道它是否会解决其他问题。

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0.

This version doesn't exist.

此版本不存在。

Check your top-level build.gradle. You should use the version 1.3.0 instead of 23.0.0.

检查您的*build.gradle。您应该使用版本1.3.0而不是23.0.0。

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

It is the gradle plugin for android, and it is not related with the sdk.

它是android的gradle插件,它与sdk无关。

#2


0  

Your problem is not the resources. The problem is that your build tools cannot be found:

你的问题不是资源。问题是找不到您的构建工具:

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0.

The tools needed to generate your resource file (containing all your resource id's) cannot be found, which means that your R class is never generated and so the Java compiler complains that the symbols cannot found.

无法找到生成资源文件(包含所有资源ID)所需的工具,这意味着您的R类永远不会生成,因此Java编译器会抱怨无法找到符号。

You've indicated that you have all the latest Android SDK updates, but are you sure that Android Studio is pointing to the correct Android SDK location? Presumably, you were using some instance of the Android SDK for Eclipse - but Android Studio comes with it's own instance of the Android SDK and may not be using the one you think it is.

您已经表明您拥有所有最新的Android SDK更新,但是您确定Android Studio指向正确的Android SDK位置吗?据推测,您使用的是Android SDK的一些实例 - 但Android Studio附带了自己的Android SDK实例,可能没有使用您认为的那个。

Have a look at the paths in the error:

看看错误中的路径:

Searched in the following locations:
         file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom

Does this path exist on your computer? Is it where your Android SDK is installed? And can you find the 23.0.1 build tools folder in that location? If not, you probably need to fix this to resolve your issues - this question might help you out.

您的计算机上是否存在此路径?它是安装Android SDK的地方吗?你能在那个位置找到23.0.1构建工具文件夹吗?如果没有,您可能需要解决此问题以解决您的问题 - 这个问题可能会帮到您。