Why is Android Studio reporting "URI is not registered"?
AndroidAndroid StudioAndroid Problem Overview
So I've given Android Studio a try, because I really like Resharper and noticed that the IDE had some of their functionality built into it. Having now created a default new project, I added a new layout file and wanted to change the existing default 'hello world' example layout, and I got an "URI is not registered" error on the following lines:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
I've done nothing else to the default generated project yet. I've come across another question that seems to be related (https://stackoverflow.com/questions/6147051/intellij-android-project-schema-uri-not-registered), but just ignoring something feels odd to me. I actually tried it, but that causes RelativeLayout
(and probably all other Android related stuff) to be not recognised any more (error message: "Cannot find the declaration of element 'RelativeLayout'").
Any ideas on how to solve this problem?
Android Solutions
Solution 1 - Android
You are having this issue because you are at the wrong destination! The correct directory for the Layout resource file has to be under "res-layout" not "res-all-layout"
Solution 2 - Android
For me this was because I was using a debug and release build variant. I added the new folders src/debug/res/layout/some_layout.xml file manually, and it didn't recognize the URI. I switched the build variant to release, and then back to debug. This caused Android Studio to reload something, and the error went away.
EDIT: Also check that you have the correct filename. I had this issue again by adding a debug AndroidManifest.xml, but mistakenly named it AndroidManifest.xml.xml.
Solution 3 - Android
I use Intellij IDEA but I think it will also work in Android Studio, can you see the "Event Log" at IDE right bottom corner, did it have some message like that "Android framework is detected in the project Configure", that means you should have a framework configuration. If so, just follow the message link.
In the same way, you can go to "File > Project Structure > Modules" , and then add a Android Facet.
by the way, if I want use a customized namespace like you do, I'll write the resource identifier as my package name as I define the AndroidManifest.xml package attribute of the manifest element, below is my code.
<manifest package="com.my.name.android">
...
</manifest>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/apk/res/com.my.name.android">
</RelativeLayout>
Hope this helps you.
Solution 4 - Android
This problem appeared suddenly for me, without any reason. I just closed all the tabs in Android Studio and re-opened the xml file which had problems. Problem solved! :)
Solution 5 - Android
In Android Studio 3.1.2 this error occurs due to Wrong validation of the cache memory.,
> Go to Project folder and delete all the contents in .idea folder
This will delete the cache memory and reloading the project will create new cache memory folder and makes it good to go.,
Solution 6 - Android
My problem was that my folders were structured as:
MyProject/ res/ layout/ main.xml layout-land/ main.xml
(My Slayout-land
folder was in my layout
folder)
I changed the structure to this and it worked for me:
MyProject/ res/ layout/ main.xml layout-land/ main.xml
I hope that this helps!
Solution 7 - Android
Its a plugins problems.
- Restart Your android studio.
- It will show a pop window for enable plugins
- click on enable plugins and then click on Okay.
then it will automatic restart your studio and works will fine.
hope it will works.
Solution 8 - Android
Select appropriate flavour in Build Variants.
If you are viewing a particular file under Flavour1, select that flavor in BuildVariants window.
If your IDE is Android Studio (3.2.1 as of this writing), you should find Build Variants window on the lower left, aligned vertically.
Solution 9 - Android
Don't know the reason behind this error but I found out this somewhere and it solved my problem.
- Go to "File > Project Structure > Modules"
- Click "add (+)"
- Click "android" and "apply" and then "ok"
Solution 10 - Android
it turns out I was editing the DEBUG version of the xml, to fix it, simply close the tab that has the error and re-open it
Solution 11 - Android
i had the same error. I solved it by importing the project again to the android studio.
Solution 12 - Android
For me Plugin Android Support
get Disabled somehow. Enabling Plugins again worked for me.
Settings > Plugins > Android Support
Solution 13 - Android
I had this problem now - I created a new folder under the layout folder which would contain all the xml relate to my "home" page of my app and then another folder that would relate to my "settings" page as I wanted to organise my xml.
However, android only recognises the layout folder for xmls, not the layout/home or layout/settings folder so that is why it was giving me the error.
Thanks to Mazen Kasser answer, he assisted me in figuring this out.
Solution 14 - Android
Sometimes this error is correlated to other errors in your manifest. Check if there are some missing dependencies and if all the tags are closed. In my case I had deleted a folder in /res folder, I restored it and that error disappeared.
Solution 15 - Android
For me, the offending xml files were missing the header line...
<?xml version="1.0" encoding="utf-8"?>
Adding that fixed it.
Solution 16 - Android
Started getting this again, What actually works now is to add some rubbish inside build.gradle. Then try and sync. When it fails remove the rubbish and re-sync. After indexing, it works.
Solution 17 - Android
- Go to "Preferences > Languages&Frameworks > Schemas and DTDS"
- Click "add(+)"
- Click "apply" and then "ok"
hope it will works.
Solution 18 - Android
Another suggestion, which was the solution for me: I got the error in the line
<resources xmlns:ns1="http://schemas.android.com/tools" xmlns:ns2="urn:oasis:names:tc:xliff:document:1.2">
in the values.xml file that was automatically generated during the build process.
It was solved by adding the android
prefix in the styles.xml file.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="textColorPrimary">@color/textColorPrimary</item>
<item name="colorBackground">@color/colorPrimaryDark</item>
</style>
had to be changed to
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:colorBackground">@color/colorPrimaryDark</item>
</style>
Solution 19 - Android
For me, i clone a project from gitlab, there is table of contents: >TradeClient/TradeClient/app/...
then i encounter this problem, i solve the problem by below method:
- remove the middle path "TradeClient", as TradeClient/app/...
- then File -> Invalidate Caches / Restart...
Solution 20 - Android
The new build system in Android Studio creates a build
folder. The code inspection barfs on this folder as well as the gradle
folder. These folders should proably be ignored when running code inspection.
I have raised an issue with the Android Studio team at:
Solution 21 - Android
Ran into this recently trying to migrating an existing app to material design. All I had to do to fix it was change the project's Compile SDK Version. File | Project Settings. Select app and pick a Compile SDK version for Lollipop or higher.
Solution 22 - Android
Any solution mentioned here helped me. I'll post my problem just in case is helpful to anyone. In my case the error was happening using data binding. It seems that using data binding xmls intermediates are created. If there is an error trying to open the error will show the intermediate xml with this "URI not registered" instead of opening the right xml with the error.
Solution 23 - Android
I had this problem and for me it was due to creating and manipulating resource files outside Android Studio. I followed the instructions on creating new resource files and folders through Android Studio and solved the problem. You need to create a new Resource File Not directory. It will let you specify or create a directory for you if you need it. If you are creating directories for layouts for different versions, enter the info at the top including the name of the resource file you want to copy to the new folder and select Version and enter the Android version. It will create the appropriate directory with a copy of your resource in it.
Solution 24 - Android
What fixed it for me that I haven't seen mentioned so far - if you have multiple 'flavors', make sure the currently selected 'build variant' matches the flavor for the layout file you're trying to view.
Solution 25 - Android
Anyone getting this error right after project import might be hitting an unsuccessful initial gradle import/sync. Usually it is encountered with serious errors (blinking exclamation mark in the lower right corner). For me this was the very strange cause (project folder was symlinked): https://stackoverflow.com/a/52952148/44166
Solution 26 - Android
I encountered same problem in opening android React Native Project in Android Studio.
The root cause is I opened the root folder of React Native Project instead of android folder of the React Native Project.
Reopen the project under android folder of React Native Project solved my problem.
Solution 27 - Android
Try to Install the android tracker plugin. you will find it on the studio.
Restart the studio