2015-09-04 141 views
2

由於Google最近宣佈Android Studio是Android開發的官方IDE,因此我決定將工作環境從Eclipse IDE更改爲Android Studio。Android Studio找不到現有資源

將項目導入到Android Studio後,我遇到了一個奇怪的錯誤。 錯誤表示它無法在一個R.drawable數組中找到兩個現有的R.drawable,這些資源是兩個png圖片。

這裏是陣列的語法:

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

兩個R.drawables導致該錯誤是thegodfather和kingofcomedy。

以下是錯誤消息: (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. 

後的cleansings,rebuildings,invertings無數的努力,並重新啓動同樣的錯誤依然存在。我已經檢查過資源是否真的在那裏,我已經刪除並替換它只是爲了確保。它仍然不起作用。

什麼導致Android Studio忽略這兩個資源?

這是我的Android清單文件的開頭:

<?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="11" 
     android:targetSdkVersion="23" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     > 

這裏是我的Gradle.build:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 

    defaultConfig { 
     applicationId "com.exple.v1" 
     minSdkVersion 11 
     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 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:support-v4:23.0.1' 
} 

同樣,我不知道是什麼原因造成了這個問題。在Stack上搜索之後,我發現有些人遇到了類似的問題,但是通過清理項目或重新啓動Android Studio來解決這個問題。

清單文件和Gradle.build用於額外信息 ,以防萬一需要查看它。

回答

0

您是否驗證了在Android項目中正確名稱的appropiate文件夾中是否存在?

編輯:

你試過從Android工作室,而不是進口的版本中刪除(刪除),並加入他們嗎?

+0

是的,我已經驗證,它們都存在。 –

+0

你能描述一下怎麼做,以避免潛在的誤解? –

0

我在Eclipse中導入的項目中存在與現有資源相同的問題。在我的情況下,問題是,名爲loading.png的資源實際上是.gif,在我修復了擴展後,編譯器生成了正確的R.drawable.loading變量。

當Android Studio中導入項目它顯示這個消息,但我並沒有出現在子序列彙編

:app:mergeDebugResources 
AAPT out(251470765) : No Delegate set : lost message:Done 
AAPT err(251470765): libpng error: Not a PNG file