Unknown attribute layout_width - android

I am working on android project, all was working well, until suddenly I opened Android Studio and found warnings all my layout files. E.g unknown attribute android:layout_width, unknown attribute android:id etc. I tried creating a new layout resource file and it also did the same, only options available now are constraint_width,height and so on. What could be my problem here?

Just on menu bar invalide caches and restart Android-Studio:
File -> Invalide Caches/Restart
That should help

In your android studio try steps below:
File -> close project
From the list click on the "X" button in front of your project to remove it from the recent projects (As marked in image).
Click "open an existing Android Studio project", browse and select your project and reopen it.
By step 3 problem should be solved, if it wasn't, click Build -> Rebuild project.

Just go to Tools->Android->Sync Project with Gradle Files

I had similar issue but resolved by invalidating caches and restarting android studio:
Go to Android Studio: File -> Invalide Caches/Restart.

None of the suggested solutions worked, I had to remove all my configuration settings, gradle files and uninstall AS, redownloading it was the only solution.

Sometimes File -> Invalidate Caches/Restart. doesn't work, so do the manual clearing of the cache
1. Closed Android Studio.
2. Clear the contents of the C:\Users\MyUsername.AndroidStudio3.3\system\caches\ directory.
3. Relaunched Android Studio.

Related

Android Studio file mapping problem, not recognize files

Please look at snapshot of the opened file below.
When I double click on MyUtils.java it is showing this XML format:
But when I open it manually from Windows Explorer it already have correct Java code inside:
I have tried these but the problem remains:
clean, rebuild project
invalidate cache and restart
deleted .gradle and .idea auto generated folders from the project
updated and restart Studio.
It happens because of wrong File Encoding and you can see my answer about it in here.
Solution: The solution will be reinstalling Android Studio or, go to:
File -> Other Settings -> Default Settings, find File Encodings, change Project Encoding to System-Default or UTF-8 format.
try 'Sync Project with Gradle Files'. you can find it in top-left in 'File' tab or click on button at the left of 'Avd Manager' button.
go to Project mode and right click on the root folder of your project and Synchronize it
Actually you do not need to reinstall the Android Studio.
I met with the similar problem. The way to fix it is if you are using MAC OS then goto
'Android Studio->Preferences->Editor->File Types'
then check the Recognized File Types and look for your bug file in Registered Patterns and remove it.
Then all be good.

Android Studio waiting for build to finish

I have a problem. When I start a new project in Android Studio and select a navigation drawer activity it happens. I don't have access to my activiy_main_drawer.xml on "Design" and it keeps saying "Waiting for build to finish.". I really don't know what I have to do. I tried to uninstall and reinstall Android Studio, and it didn't help.
I've just run into the exact same problem. I simply solved it by choosing Sync Project with Gradle Files. This will trigger a Gradle re-import and a build.
As of Android Studio v3.2, the icon is located near the top right tool bar. You can also find it using Find Action shortcut CtrlShiftA.
You can do the following:
"File > Sync Project with Gradle files" (worked for me)
File > Invalidate Cache & Restart > Just Restart
OR
File > Invalidate Cache & Restart > Invalidate & Restart
Close Project and Re-Import the Project
File -> Sync project with Gradle files
What worked for me was, from the top menu:
Build -> Clean
Build -> Rebuild Project
After that the xml design worked
Syncing gradle, reopening, rebuilding, invalidating caches and restarting, trying different Android studio versions. None of these helped. When I would open XML preview I would still see that damn issue.
What helped in the end is closing Android studio, going to gradle directory:
cd ~/.gradle/
And deleting caches folder:
rm -rf caches
After that reopening Android studio will take some time as it still has some rebuilding to do, but afterwards all xml layouts were being properly rendered again.
I am using Android Studio 3.1.3 (#AI-173.4819257), Android Build Plugin for Gradle 3.1.3 and Gradle 4.4. I tried all possible options mentioned on various posts but nothing worked for me. I want to use ConstraintLayout which is default with AS 3.1.3. My observation and workaround are as follows.
Observation: This issue occurs when a new project created with empty activity and default layout. I also get "IDE Error Occurred" once Gradle sync finishes.
Workaround: Create an empty activity, activity class (MainActivity.java) and layout (activity_main.xml). Once it is done, create a new layout file (say activity_cltest.xml) using New -> Android Resource File after clicking right button on "app". Create new layout as per your requirements. Once done, update MainActivity.java by replacing R.layout.activity_main with R.layout.activity_cltest.
I also tried to copy content of activity_cltest.xml to activity_main.xml but still for activity_main.xml, error persists. Effectively, once a new project is created, activity_main.xml should not be used and deleted.
However, for some reasons, syntax highlighting of "R.layout.activity_cltest" within MainActivity.java doesn't work.
Just create a new XML file using the same name and copy paste activiy_main_drawer.xml file codes. It works for me.
Have the save problem, the Android SDK was missing from my system.
After installation of this missing SDK, its running fine.
In my case it was because I specified recycler view's tools:listItem="<item_layout>" in body of <item_layout> (nested recyclerviews). Just removing this tools option solved it.
I uninstalled my 3.1.2 and installed version 3.2 Canary 18 from Android Studio download archives. Everything is fine now.
We welcome all constructive edits, but please make them substantial. Avoid trivial edits unless absolutely necessary.
Ah... I resolved it with the help on this page and a little bit more effort.
I installed Android Studio v.3.3.1 today on my Zenbook. I was stuck with the same error "waiting for a build to finish" and Display tab was not showing up for activity_main.xml
Here is what I did to resolve this error.
Step 1. I searched for SDK tools and downloaded required SDK versions.
Step 2. downloaded Gradle 5.2.1 and extracted the files in Program Files\Android\Android Studio\gradle
Step 3. File>Settings>Build..>Gradle and choose the local distribution of Gradle 5.2.1
Step 4. Go to File>Sync Project with Gradle files and allow some time to sync...
finish() :) developing android with Kotlin
My experience: I was accidentally importing "myself" into the view, creating infinite loop:
item_task.xml
<androidx.recyclerview.widget.RecyclerView
...
tools:itemCount="3"
tools:listitem="#layout/item_task" /> <---- circular dependency mistake
Setting a correct list item in the recycler view solved the issue.
I upgraded to AS 3.6 RC1 because of this time-waster but it still intermittently occurs!
Simply restarting AS has so far been working for me.
I've also faced this problem. The above solution wasn't worked for me.
I just restarted my Android Studio by closing the Android Studio application and opening it again from Start Menu. It works for me. Try this solution if the above not working. Hope this will helpful for you.
In my case, I was using an alpha version of material design lib, and it was not able to render any view in the project. Solved by downgrading to a stable version.
Stuck w/ the issue for a month, got it after AndroidX update.
Tried to invalidate caches, manually remove them (project, grade, studio), re-install studio, re-import project - nothing helped.
This script resolved it finally (w/ -nuke option)
https://github.com/rock3r/deep-clean
Sometimes while converting the code from java to kotlin some library may get imported like import android.R
Just remove this library.
Check this tools:context=".MainActivity" in xml while copying another XML the class name will also get copy.
Else try File -> Sync project with gradle or rebuild the project.

Why is the source code 'all red' in Android Studio

I'm always using Android Studio's debugger to walk through the code and see how things work.
As I dive deeper into the SDK, I get to lisView.java for example, and now it's class members are mostly red? (see link)
Why is that?? I could see my code and parts of the SDK prior to 'stepping in' listView.java? Why suddenly is it all red on the right-had column?
As you see in the screenshot, now I can't see the value for
the member variable, mOldItemCount for example.
Try file -> invalidate caches / restart -> Invalidate caches and restart
Sync Gradle and Rebuild Project.
Try deleting .gradle and .idea folder of project. For me its solved the problem.
Possible Fixes:
Sync Gradle
Restart Android Studio
Clean and Rebuild
A Possible other problem that can occur is that you moved the location of the file. Its happened to me before.
When you have a red code like the image is because the autogenerate files and de gradle its not working well.
I try this options in order:
First, Check de import and be sure are the rigth imports
Second, Sync Gradle and Rebuild Project.
Third, Clean project
If the problem persist try checking the android dependencies and see which one is creating the problem.
Just removing .idea or at least files inside of it, even if while you're opening Android Studio a popup alert will be shown to tell you to reload your project and it everything will go back normally
If Methods named (A) (B) (C) (D), do not help you, then the following 4 steps are AGNI ASTRA.
Step 1 : Go To App Folder In Android Studio.
Step 2 : Locate Build Folder.
Step 3 : Delete Build Folder.
Step 4 : Sync File.
I will advise to use AGNI ASTRA, after trying, Methods named (A) (B) (C) (D) .
The Methods Are :
Method (A)
CLICK ON FILE IN ANDROID STUDIO
CLICK ON SYNC PROJECT WITH GRADLE FILES
Method (B)
CLICK ON FILE IN ANDROID STUDIO
CLICK ON INVALIDATE CACHES
Method (C)
CLICK ON BUILD IN ANDROID STUDIO
CLICK ON CLEAN PROJECT
Method (D)
CLICK ON BUILD IN ANDROID STUDIO
CLICK ON REBUILD PROJECT

"AndroidManifest.xml doesn't exist or has incorrect root tag" Error

I am new to AndroidStudio AND Gradle.
I imported a project from eclipse, created a module, and tried to run the project, but I got this error:
AndroidManifest.xml doesn't exist or has incorrect root tag
I have been looking at this previous solution for it:
How to build an android library with Android Studio and gradle?
But that solution is WAY too advanced for me.
Could someone please help me understand in simpler terms what is going wrong and how I can fix it?
Thank you!
Update after one of the answers:
These are the options I have under the build menu:
clicking on Sync project with Gradle files button will solve your problem.
That button is under File section on Android Studio 3.6.1
Close your Android Studio
Goto C:\Users\user\.AndroidStudioX.X\system and DELETE the cache
folder
Launch the Android Studio
Goto Build (menu) -> Clean Project when done click the
Build (menu) again and click rebuild project.
That should solve the problem.
For me the issue went away once I opened the android folder of the project in Android Studio to run the project.
So basically, because I was trying to run the Android project from the Root folder, it gave me the error. We need to run the project by selecting the android folder of the project only.
Hope this helps someone!
Click on File > Invalidate Cache/Restart, and that's it. Your project should start working.
For me clicking on Sync project with Gradle files button did not solve the problem alone.
After Syncing project with Gradle files, I explicitly had to invalidate the cache and restart studio. Only after this action, the red cross-mark over configuration disappeared and everything started working.
In my case, my android project got corrupted and some of the files were showing characters, binary numbers, etc. I tried the following solutions
Invalidate & Restart
Rebuild Project
Sync with Gradle File
But none of the above solutions worked for me.
Then I just deleted the cache folder under C:\Users\username\.AndroidStudio3.6\system
and all the invalid characters disappeared and the actual contents of all the files were displayed. This solution worked for me.
Every Android project needs a file called AndroidManifest.xml to tell Android about itself. Either your project doesn't have one, or it's not in the place that Android Studio expects it to be. Try to find it, and move it to the root folder of the project.
1.Check whether the manifest file is there or not.
2.If it is there, check whether the package name is correct or not..
3.If you project has small number of classes, then you create new project in android and then copy paste your code from eclipse. It will be simple. But it is recommended only for small project.
And finally click 'Sync' in the Gradle file. Followed by Rebuilding the project will do a trick.
In my case the Manifest file seemed to be corrupted or maybe its meta data. Trying to open it in Android Studio will show some characters that you see when opening a binary file with a text editor, for ex. Anyway, my project is under Git, so I just deleted it and restored it back, problem fixed.
Go to C drive click User then select your android studio folder then select System find Cache folder and delete this folder before doing this close your android Studio.It will surely work.
I also had this problem, things I tried:
I delete user->gradle-> delete cache folder
Android studio-> file-> Invalid cache/restart
Using my problem is get resolved
I also had this problem, things I tried:
Syncing the file with gradle
Invalidate/Restart
But the problem was still there in the manifest folder-> manifest.xml file it had only 1 line.
So I went to User-> your_username -> Android Studio v -> caches and Deleted the cache folder.
Started Android Studio, and my problem was gone.
But I am not sure which of these might solve yours.
I have opened AndroidManifest.xml in file editor. Add some letters, save it, then android studio found AndroidManifest.
After this I can build project successfully
if your AndroidManifest.xml looks wierd than you can try checking local history or git history. by doing that you can copy paste the previous version AndroidManifest.xml
Experienced that too, there is a line on your manifest code that's incorrect, simply go through it and make necessary corrections.

Android studio Error "Unsupported Modules Detected: Compilation is not supported for following modules"

I am using Android studio 1.0.1. I have a java module referred by other modules in my project. I have checked it out from SVN But now every
Unsupported Modules Detected: Compilation is not supported for following modules: . Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
After getting this error AS stop compilation of this module so that I am not able to compile/run my project any more.
1- close the project
2- close Android Studio IDE
3- delete the .idea directory located inside the project folder
4- delete all .iml files
5- open Android Studio IDE and import the project
First of all you should update to Android Studio 1.2
Source: https://code.google.com/p/android/issues/detail?id=77983
Then you should go to File -> Invalidate Caches / Restart -> Invalidate Caches & Restart.
Then try to build the application again.
Invalidate Caches and Restart did not work for me. I also updated all my Android Studio files with no success.
The solution I found was importing the android folder by clicking "Import project (Eclipse ADT, Gradle, etc.)" rather than clicking "Open an existing Android Studio Project" or dragging the folder onto the app icon.
Apparently the problem is caused because a module in the project has an *.iml file that does not contain external.system.id="GRADLE".
When you import the project (as opposed to opening it), the iml files are completely re-written, thus removing the error.
I found the info here: https://issuetracker.google.com/issues/37008041
Goto .idea/modules.xml & delete the invalid/not existing path <module />. Then File => Invalidate Caches / Restart.
Try this if it helps File -> Invalidate Caches / Restart.
If it still doesn't help click on the button in the image.
'Sync Project with Gradle Files'
I know it's an old question. but I faced this problem after updating to Android Studio 3.0. I solved it by deleting app.iml file inside my app module and then Invalidate Caches / Restart.
In my case settings.gradle contained invalid configuration.
I changed:
include ':app'
rootProject.name='<somthing else>'
To:
include ':app'
Error is gone. So maybe check your settings.gradle for potential errors. If this won't work try to remove cache and other tips.
Delete .idea/modules.xml
Reload All Gradle Projects
You do not want to remove entire .idea directory, because it contains e.g. dictionaries and shelved changes.
If the above doesn't help you - check your module .iml file and see if it contains any errors. (for the app module it will be app.iml).
Invalidating caches/Restart didn't worked for me.
But simply deleting the caches folder in \Users\user.AndroidStudio(version)\system worked like a charm
You may resolve by below process:
In Android Studio, go to left panel, switch from Android to Project pane
Expand .idea folder, you can see modules.xml and open the file.
In the modules.xml file, you might see like below:
<component name="...">
<modules>
<module fileurl="file://$PROJECT_DIR$/[check...].iml" filepath="$PROJECT_DIR$/[check...].iml" group="myProject" />
<module fileurl="file://$PROJECT_DIR$/app/[check...]-app.iml" filepath="$PROJECT_DIR$/app/[check...]-app.iml" group="[check...]/app" />
Check that match the module name correctly in module element
And then, sync the gradle file
Close the Android Studio and Move ".idea" Folder and paste it outside Project root folder( For Back up if you need).
Open the Android studio.
On Opening the project it"ll ask add module (app) to your project. You can ignore the same.
It set set default build variant to be "debug".
You can see build variant tab on left corner or hover on "Monitor" Symbol on left bottom
Note: No need to change your .iml file of your project.tom to get build variant option and "Invalidate Cache and Restart" will also not work rather it will clear your history files too!.
I solved a similar problem by closing the project, then re-importing the project (not opening, but re-importing as an eclipse or other project)
Try the below,
Close android studio
Then delete .iml , .idea files
Open again the android studio
Sync with Gradle.
In My Case
I have deleted
android -> .idea Folder
android -> appname.iml file
android -> app -> app.iml file
Open project in Android Studio and no need to File -> Invalidate Caches/Restart
You can do Invalidate Caches / Restart for your case.
The above solution I've tried but didn't work for me.
I deleted the .idea folder from project directory.
Invalidate caches using Android Studio menu File -> Invalidate Caches / Restart
Deleted .gradle folder from user profile directory of Windows 10 operating system. (i.e., C:\Users\YourUserName\.gradle)
Try this solution if the above not working.
You should import the the project
https://issuetracker.google.com/issues/37008041
This error shows up when there is a module in your project whose .iml file does not contain:
external.system.id="GRADLE" Can you please check your .iml files? Also, instead of opening the project, import it, that will completely rewrite your .iml files and you won't see that error again.
Try this steps Individually:-
1) Go to File->Invalidate Caches / Restart.
2) Close android studio, Go to C:\Users\(Your UserName)\.AndroidStudio(version)\system and delete caches folder.
If till now nothing worked, then this step will definitely work...
3) Simply change project location and import project with new location.
Enjoy :-):-)
Step 1 : Delete .iml file
Step 2 : Check if your Project Directory Contain any white spaces if so then Rename your project directory leaving space
ex:
Before : My Project
After rename : MyProject
and open Android Studio...
For windows users, this can also be caused by filesystem corruption.
If all steps above do not correct the error:
Close Android Studio
Open Command Prompt as Administrator
Run a chkdsk /f on the drive your app is stored
Delete .idea folder
Restart Android Studio
save .idea folder somewhere else (for backup)
remove .idea folder
start AndroidStudio
select project
[there may be an error, ignore that]
click File -> Invalidate Caches/ Restart
click button: Invalidate Caches/ Restart
resolved
Delete .idea folder
Close project ->
Reopen Project ->
Invalidate Caches / restart
You can update new version of Android studio then go to invalidate catches/restart.Click sync button build application.
In my case I cloned a git-project where both Java and Kotlin included. Then checked another branch and pressed "Sync Project with Gradle Files". Android Studio 3.0.1.
I had the same issue on androidStudio 3.2 and clonning the project worked for me
In my case it is because the root project name have a space.
So instead of naming it as sample project, it should be sample-project or sample_project.
click File -> Invalidate Caches/ Restart doesn't help you anymore
Delete .iml , .idea files & folders from file explorer not inside android studio
1) Open android studio with different/another project
2) import project newly not from recent
3) build the project again
sure it will work
I had the exact same error and it was so annoying to see the alert every time I stared Android Studio. I tried the solution mentioned above including invalidating cache, restart etc, nothing made it go away.
In my case, we had a module that was deleted from source and the reference also removed from settings.gradle. Turns out, .idea/modules.xml was still referencing that module.
All I needed to do was remove that line from <modules> in .idea/modules.xml and it made it all go away.
I have the same issue. I was tried Invalidate Cache / Restart & also sync project with Gradle Files but still didn't work.
But worked by use the following steps:
upgrading gradle distribution version at gradle.wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
And also Android Gradle Plugin at build.gradle project
classpath 'com.android.tools.build:gradle:4.1.2' //upgrade gradle plugin here
Then Invalidate Cache / Restart
That's all solved my problem. Hope you too
rename project directory fix error for me, android studio 3.4.2

Categories

Resources