4

I am attempting to run the following project I cloned off Git hub: https://github.com/googlecast/CastHelloText-android .

For some reason even after multiple cleans and project builds and restarts I get the following error:

R cannot be resolved to a variable .


Found the culprit in the provided manifest file.

No resources found that matches given name :

android:value="@integer/google_play_services_version" 
android:theme="@style/Theme.AppCompat" 

and the provided menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/media_route_menu_item"
        android:title="@string/media_route_menu_title"
        app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
        app:s="always"/>

</menu>

No resource identifier found for attribute 'actionProviderClass' in package 'com.example.casthelloworld'

No resource identifier found for attribute 'showAsAction' in package 'com.example.casthelloworld'


Imports:

import com.example.casthelloworld.R;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.MediaRouteActionProvider;
import android.support.v7.media.MediaRouteSelector;
import android.support.v7.media.MediaRouter;
import android.support.v7.media.MediaRouter.RouteInfo;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.cast.ApplicationMetadata;
import com.google.android.gms.cast.Cast;
import com.google.android.gms.cast.Cast.ApplicationConnectionResult;
import com.google.android.gms.cast.Cast.MessageReceivedCallback;
import com.google.android.gms.cast.CastDevice;
import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
Fabii
  • 3,820
  • 14
  • 51
  • 92
  • 3
    Are you using some IDE? If yes, clean and build the project, it should regenerate the R.java file – BackSlash Feb 14 '14 at 16:31
  • 2
    If it doesn't, then you have some troublesome XML file (not necessarily layouts - can also be a "strings" or a "dimens"). – Phantômaxx Feb 14 '14 at 16:33
  • 1
    @BackSlash Yes I am using eclipse. Clean and rebuild does not solve the issue for me. – Fabii Feb 14 '14 at 16:38
  • 1
    @ArtooDetoo yes that was the issue, check out the edits above. – Fabii Feb 14 '14 at 16:49
  • 1
    It's a recurring mistake. The first times you get crazy before you find the culprit! ;) – Phantômaxx Feb 14 '14 at 16:52
  • @ArtooDetoo please make your comment an answer so I can accept it. :) – Fabii Feb 14 '14 at 17:11
  • @Fabii Done right now ;) – Phantômaxx Feb 14 '14 at 17:13
  • possible duplicate of ["R cannot be resolved to a variable"?](http://stackoverflow.com/questions/7824730/r-cannot-be-resolved-to-a-variable) – Jorgesys Feb 14 '14 at 17:42
  • possible duplicate of [Developing for Android in Eclipse: R.java not generating](http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating) – flx Feb 24 '14 at 03:24
  • @Fabii what did you do specifically to get rid of the 2 'No resource identifier found...' errors (from menu/main.xml)? For the life of me I can't figure out out to do away with them! – Hugo Mar 16 '14 at 22:51
  • @Hugo I had some bad references in my manifest.xml : android:value="@integer/google_play_services_version" and android:theme="@style/Theme.AppCompat". I was referencing the integer value google_play_services_version but hadn't specified it in my values.xml file. This what caused the build to fail. – Fabii Mar 18 '14 at 00:39
  • @Hugo I would say comb through your xml files and make sure that all reference resources and values actually exist (values, strings,dimens etc). – Fabii Mar 18 '14 at 00:41
  • @Fabii Thanks! I just (finally) figured that the root cause was a missing resource. I had simply added the app-compat-v7 jar to my /libs folder instead of creating a library project and referencing it from my own project as documented here http://developer.android.com/tools/support-library/setup.html – Hugo Mar 18 '14 at 04:20

1 Answers1

2

If a Clean & Build of the project doesn't fix the issue, then you have some troublesome XML file (not necessarily layouts - can also be a "strings" or a "dimens").

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115