Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find problems in Android XML

I am facing the typical cannot resolve symbol R problem in Android Studio after moving some Class and XML files to a new com.android.library module from my main com.android.application module.

I tried already to Invalidate Caches/Restart and Cleaning/Rebuilding my project several times. I also deleted the .iml files of my project and restarted Android Studio.

Nothing has worked so far and I can't seem to find any specific pointer to the actual error. I think it should be an XML problem as it is often the case.

Is there a way to check the XMLs for errors in a more systematic way than opeing all the files and copy editing them line by line? The Messages Gradle Build window is not showing any XML conflict.

As an extra, one interesting thing is that Android Studio recognizes some of the references to XML resources, even in this broken state.

In this case it is recognizing a resource linked from a different module referenced in Java even if the R class is not recognized nor imported:

Java problem

In this case, it is recognizing a string resource on the same module in XML:

XML problem

Could it be an issue with Android Studio itself?

like image 880
buzoherbert Avatar asked Jun 22 '16 15:06

buzoherbert


2 Answers

Is there a way to check the XMLs for errors in a more systematic way than opeing all the files and copy editing them line by line?

You could try analysing the code with Lint. Maybe analyse the whole project in case it's not actually an xml problem, although it often is with R errors. Right click project -> Analyse -> Inspect Code

https://developer.android.com/studio/write/lint.html

like image 92
Karen Forde Avatar answered Oct 19 '22 14:10

Karen Forde


In Android Studio 3.3.2 Go To Tools> XML ACTIONS > VALIDATE Its redirects to the xml in which you making mistake.

like image 1
Sumit Kumar Avatar answered Oct 19 '22 15:10

Sumit Kumar