2016-02-08 120 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'在灰色同步未完成时变为红色。 因此,在运行任何项目之前,建议首先同步项目(如果已添加任何依赖关系或任何内容),然后清理项目并运行它。

它应该解决你的问题。

相关问题