2016-02-08 123 views
0

任務執行失敗:app:mergeDebugResources。 什麼是這個錯誤,以及如何解決它?'無法解析符號R'android studio錯誤

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

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

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
     App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
    <meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 
</application> 

這是我的XML以上...以下是onCreate()其中setContentView(R.layout.activity_main) 是造成問題:

無法解決標記R

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

    provider = locationManager.getBestProvider(new Criteria(), false); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 
+1

'Clean-Rebuild-Restart'&import'import PackageName.R' –

+0

請確保所有資源都作爲manifest中的相同包.mainactivity是否帶有紅色符號? –

+1

當你建立你的項目沒有警告或錯誤?也嘗試關閉並再次打開AS,有時適用於我 –

回答

0

可能是你的gradle這個同步失敗了,這就是爲什麼它不能解決resync gradle或者你還沒有導入yourpackagename.R;

0

R是android中的預定義類。 你應該清理你的項目,然後重新構建它。它將解析R

+0

或者在某個地方有一個不明顯的錯誤,並且它不能自動生成 –

+0

但是隻有兩種可能性,要麼'R'沒有正確導入,要麼沒有正確使用。所以在大多數情況下,它使用清理和構建過程來解決問題。 –

+0

乾淨和構建不會修復不正確的佈局xml,這會導致R不會被生成,這就是我所說的 –

1

'無法解析符號R'錯誤通常會發生,並且'符號R'在灰色同步未完成時變爲紅色。 因此,在運行任何項目之前,建議首先同步項目(如果已添加任何依賴關係或任何內容),然後清理項目並運行它。

它應該解決你的問題。

相關問題