Android Support Library v7 R.id. Error - android

I have added the support library v7 to my project and I think it worked because ActionBarActivity is recognized (import android.support.v7.app.ActionBarActivity works).
The problem is that for all my R.ids the R is underlined with the message R cannot be resolved to a variable.
What am I doing wrong?

The problem is probably with R, not anything to do with the support library. Sometimes cleaning the project solves the problem.
A Google search with that message ("R cannot be resolved to a variable") returns tons of answers, try those. Also Stackoverflow is full of these:
"R cannot be resolved to a variable"?
Eclipse error: R cannot be resolved to a variable
Eclipse giving error, missing R.java file after recent update
If it's got nothing to do with that, then maybe you've got an error in some XML file.

Related

Program type already present: android.support.annotation.PluralsRes error in Xamarin.Android project

I created a Xamarin.Android project and after I set the configuration:
- Dex compiler: D8
- Code Shrinker: R8
- Linking: Sdk Assembleies Only
I am presented with this error:
Program type already present: android.support.annotation.PluralsRes
I also have the LinkerPleaseInclude file.
I have to say that I am in Debug configuration.
I solved this issue by clearing cache for Nuget Packages.
I know I'm a bit late but since the answer for this matter did not work for me, here is how I solved it:
First of all, it's obviously a NuGet packages problem, so I searched in my .nuget folder at C:\Users{yourUser}.nuget\packages and looked inside some of the folders, in my case the Android support libraries folders, and saw that there were folders for many versions of that library excetp for the one I was referencing in my project wich was 28.0.0.3, the last version at this moment, the newest I had in the folder was for 28.0.0.1 so instead un uninstalling and installing everything again I just modified the android.csproj, changed the referenced versions for the support libraries for 28.0.0.1 and then it gave another error, I just literally downgraded some other libraries to 28.0.0.1 from Visual Studio NuGet package manager and then everything worked fine.
Have a nice one. It took weeks for me of trying to find out.
Neither of the above solutions worked for me. I encountered the error opening an Xamarin project that was created in VS 2015 on VS 2019. I changed the "Compile using android version" in the manifest to Android 9.0, updated the NuGet packages, but this error remained. I also attempted the tried-and-true deleting ".vs", "bin" and "obj" folders.
What finally got rid of the "Program type already present: android.support.annotation.PluralsRes" error was deleting everything in the "Packages" folder for the project. My understanding is that directory was eliminated in VS 2017, but suppose because the original project was VS 2015 it was still being utilized and causing the conflict.
I was getting
Program type already present: androidx.appcompat.content.res.AppCompatResources$ColorStateListCacheEntry error.
I had 2 references
a)Xamarin.AndroidX.Appcompat and
b)Xmarin.Androidx.appcompat.content.res.AppCompatResources
I removed the reference Xmarin.Androidx.appcompat.content.res.AppCompatResources
And now the project builds without errors

Android TabLayout CompatTextView can not be resolved

I was using TabLayout, but after copying it in my src, I am getting following errors:
(1) android.support.v7.internal.widget.CompatTextView can not be resolved
(2) styleable cannot be resolved or is not a field Though I checked other answers in stackoverflow, but failed to get proper solution. I already imported android.R
(3) I checked that in my android-support-v7-appcompat.jar the class CompatTextView is missing. How this can be possible.
(4) Will there be any legal issue if I copy the TabLayout class given by google for my app?
Please help.
Update:
I added import android.support.v7.appcompat.R; instead of android.R and getting following several error like Widget_Design_TabLayout cannot be resolved or is not a field TabLayout_tabIndicatorHeight cannot be resolved or is not a field TabLayout_tabIndicatorColor cannot be resolved or is not a field etc. Please suggest.
Converting comments into the answer as you have found them helpful and able to resolve your issue.
I don't know why are you importing/copying it manually in your project, because TabLayout is part of design support library, you just need to include its artifact ID in your build.gradle file to access its classes and resources!
compile 'com.android.support:design:+' //replace + with latest version

R cannot be resolved issues in my android project

I already cleaned the project , and set the automatic build after clean it up
but there are 50 errors regarding the 'R cannot be resolved to a variable'
how to fix this issues ? i really confused ...
Thanks before
This error is usually caused by either of these possibilities:
The most probable: You have a syntax error in any of your layout files (i.e., the files located under the res\layout folder of your project). The bad thing of this is that Eclipse won't warn you and tell you what's the error, so you'll have to go one by one looking for the syntax (probably an unmatched tag, an unmatched attribute, etc.) and fix the issue.
The other possibility is a syntax error within your AndroidManifest.xml file. Same goes here, check it for syntax errors.
One of these two will fix your issue.
I've had problems like that before, while importing a project to my workspace, I don't know if that's your case, but this answer helped me in those cases:
Android Eclipse - moving project caused all R reference errors

R cannot resolved to a variable in android

I know this question is asked many times. But still that answers are not resolved my problem. My code shows an error "R cannot resolved to a variable in android". I cleaned and build automatically many times and also fix the project properties but the error still same. How can I resolve this error ?? please help me and thanks
look for the errors in res folder and resolve it first.
It can be an error in layout, drawable, values etc..
Check the last layout, drawable, values etc where you made changes prior to getting errors. You must have made an error there. It usually is using captial letters or - in drawables or import to "R" in your activity or some problems in xml like name match_parent to Match_parent etc. Here are some links with similar problems
Android Development- Where is my R.Java file?
R cannot be resolved - Android error
R cannot be resolved to a variable
R cannot be resolved to a variable -- mailing list entry
Fixed: R cannot be resolved to a variable
Try one of these.
1>Could be a problem in your xml
2>right click on the project->Android tools->Fix Project Properties (check if the build target is checked)
3>SDK update (Build tools would have not been downloaded) go to android sdk manager and download tools (to find out create a new project if it cannot resolve R then go ahead with this step.)
Hope this helps
Try to remove "import android.R ;" at the top of your code.

Android: R cannot be resolved after adding a new class

I get the following error in eclipse: r cannot be resolved. However that appeared just after I added my own library as a resource to my project. It seems that eclipse cannot resolve which R to use, the library one or the project one. Note also that the library is marked with the is library check box in the project set-up. Also whenever I remove my library from the reference list eclipse does not show any errors, but upon compiling logCat shows a Class Not Found exception. How do I fix this issue?
Thanks
R is an autogenerated class. If you clean the project, the error should dissapear.
R.java is not getting generated for your project which is done automatically, pls check whether something wrong with any XML file or check console if there is any problem in XML it will show you something related to XML or check something wrong with importing packages. If its not about any XML errors then check on importing that library project in your project. you may get some imports related to something like this: com.android.R then remove this if you see this and then manage imports again.

Categories

Resources