I was working on a project in Android Studio when I update my Android studio to latest stable version. After updating Android studio, it prompted me to update Project build.gradle for the project (from com.android.tools.build:gradle:2.1.3' to com.android.tools.build:gradle:2.2.0'.
Since then most of the files are in grey colour and are not showing File Status in Views and Line Status in the Editor on making modifications to the files. It used to highlight all changes to the files since the last synchronisation with blue colour.
I have tried to revert to com.android.tools.build:gradle:2.1.3', that didn't work. Then I tried deleting.AndroidStudio and .gradle folders from user folder, reinstalling android studio and also deleting the project from the directory and cloning a fresh copy from Github.
That fixed it for once when imported the project in the Android studio for the first time, but the problem came back after a restart.
I have checked, There are no changes to the code on GitHub that could have cause it. I only did changes to resource files
It's working fine on other projects, and just this project is having the issue so far.
I believe this is a bug in Android studio's latest update, so I have also reported the bug on Android Studio bug tracker.
https://code.google.com/p/android/issues/detail?id=223359&sort=-opened&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened
Hi I had the same problem and it is solved for me in this way:
https://stackoverflow.com/a/41211805/1498586
Related
I have an odd problem with Android Studio.
Here is how my class file looks like on Android Studio
And here is what it looks like on a text editor.
Any ideas why it is happening? I have tried closing then reimporting the project, invalidate caches and restart, clean project, build project, delete .idea folder and .iml files. All of my files are broken when opening in AS but looks fine on text editors.
UPDATE: Quicker solution by the user Hong given below:
Delete the caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches
=====================
Here's what worked for me.
Close Android Studio
Go to C:\Users*your username*
Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
Rename it to something like old.AndroidStudioX.X
Start Android Studio, and when it asks if you want to import settings, choose the old directory
This should fix the issue.
Thanks to the Answer of Asim, I found deleting folder caches fixed the problem for my case (all gradle files in Android Studio show contents that have nothing to do with the actual contents of these files):
C:\Users\my_user_name\.AndroidStudio3.3\system\caches
Edit[2020-07-17]:
This is still happening with Android Studio 4.0, so I have to delete the following folder to fix this problem:
C:\Users\my_user_name\.AndroidStudio4.0\system\caches
Edit[2021-11-08]:
This solution no longer works for Android Studio Arctic Fox. Please see the new answer by Nikunj Paradva. I have used the new solution and it works.
Solution for Android studio Arctic Fox and Higher Versions
Steps
Exit Android Studio
Delete caches folder from
C:\Users\{username}\AppData\Local\Google\AndroidStudio2020.3 // For Arctic Fox
Open Android Studio and your code has being Perfect
Check your Android studio version and Target that version folder at below location
C:\Users\{username}\AppData\Local\Google
Note : AppData folder is Hidden in Windows
Does this situation warrant a bug report?
Yes! In fact this problem has been reported to the Android Studio team, and anyone willing to help us investigate is welcome to contribute there. Thanks!
You can also try the workaround in Hong's answer.
Close Android studio and then delete the caches folder: C:\Users\user_name\.AndroidStudio3.4\system\caches
Try to delete the Android Studio IDE cache data listed below per your platform:
Windows:
%USER%\.AndroidStudio[Preview]_X.Y_
Mac:
~/Library/Preferences/AndroidStudio[Preview]_X.Y_
~/Library/Caches/AndroidStudio[Preview]_X.Y_
~/Library/Logs/AndroidStudio[Preview]_X.Y_
~/Library/Application Support/AndroidStudio[Preview]_X.Y_
Linux:
~/.AndroidStudio[Preview]_X.Y_
See: https://developer.android.com/studio/releases#delete-unused
Updated my android studio days ago and was faced with the same problem. Solved it by uninstalling android studio and reinstalling the previous version set up I had left the SDK intact so I didn't have to re-download them working perfectly guess I won't be updating again soon.
Thanks to #Henry for confirming, by several similarly observed whacko problems the past two days, that my problem is indeed caused by a bug in AS. Follow his links to become convinced yourself. I'll let Henry file the bug report.
So there's no fixing my problem in situ without great effort--wait for bug fix.... which could take awhile.
So here's what I did to work around it and get back to work (it took less than 10 minutes):
create new project with no activity
(Do the rest inside the IDE, not using Windows or DOS.)
copy all .java files into the java folder in the IDE (it's ...\app\src\main\java\)
copy all res folders into the res folder (...\app\src\main\res\)
copy all asset files into main folder (...\app\src\main\assets\)
copy androidmanifest.xml into main folder (...\app\src\main)
do a global replace of old project name to new project name
I didn't change any of the files in the new project's ...\app\ folder because compilation was normal.
(I'll tell you this: when I saw what I THOUGHT were mangled FILES and looked at the History and saw nothing resembling what should have been there, I got a sick feeling, but I immediately opened Windows Explorer, selected all of the project's java files, and opened them, en masse, with Notepad++. Whew. No problems seen. (I didn't really think AS could actually mangle the files and I doubt it ever could. But it did wake me up at 5am!))
copy your android project to another location then open it from android studio
I changed my projects location and it solved my problem. This happened when my system was accidently shut down due to power failure.
I have an odd problem with Android Studio.
Here is how my class file looks like on Android Studio
And here is what it looks like on a text editor.
Any ideas why it is happening? I have tried closing then reimporting the project, invalidate caches and restart, clean project, build project, delete .idea folder and .iml files. All of my files are broken when opening in AS but looks fine on text editors.
UPDATE: Quicker solution by the user Hong given below:
Delete the caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches
=====================
Here's what worked for me.
Close Android Studio
Go to C:\Users*your username*
Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
Rename it to something like old.AndroidStudioX.X
Start Android Studio, and when it asks if you want to import settings, choose the old directory
This should fix the issue.
Thanks to the Answer of Asim, I found deleting folder caches fixed the problem for my case (all gradle files in Android Studio show contents that have nothing to do with the actual contents of these files):
C:\Users\my_user_name\.AndroidStudio3.3\system\caches
Edit[2020-07-17]:
This is still happening with Android Studio 4.0, so I have to delete the following folder to fix this problem:
C:\Users\my_user_name\.AndroidStudio4.0\system\caches
Edit[2021-11-08]:
This solution no longer works for Android Studio Arctic Fox. Please see the new answer by Nikunj Paradva. I have used the new solution and it works.
Solution for Android studio Arctic Fox and Higher Versions
Steps
Exit Android Studio
Delete caches folder from
C:\Users\{username}\AppData\Local\Google\AndroidStudio2020.3 // For Arctic Fox
Open Android Studio and your code has being Perfect
Check your Android studio version and Target that version folder at below location
C:\Users\{username}\AppData\Local\Google
Note : AppData folder is Hidden in Windows
Does this situation warrant a bug report?
Yes! In fact this problem has been reported to the Android Studio team, and anyone willing to help us investigate is welcome to contribute there. Thanks!
You can also try the workaround in Hong's answer.
Close Android studio and then delete the caches folder: C:\Users\user_name\.AndroidStudio3.4\system\caches
Try to delete the Android Studio IDE cache data listed below per your platform:
Windows:
%USER%\.AndroidStudio[Preview]_X.Y_
Mac:
~/Library/Preferences/AndroidStudio[Preview]_X.Y_
~/Library/Caches/AndroidStudio[Preview]_X.Y_
~/Library/Logs/AndroidStudio[Preview]_X.Y_
~/Library/Application Support/AndroidStudio[Preview]_X.Y_
Linux:
~/.AndroidStudio[Preview]_X.Y_
See: https://developer.android.com/studio/releases#delete-unused
Updated my android studio days ago and was faced with the same problem. Solved it by uninstalling android studio and reinstalling the previous version set up I had left the SDK intact so I didn't have to re-download them working perfectly guess I won't be updating again soon.
Thanks to #Henry for confirming, by several similarly observed whacko problems the past two days, that my problem is indeed caused by a bug in AS. Follow his links to become convinced yourself. I'll let Henry file the bug report.
So there's no fixing my problem in situ without great effort--wait for bug fix.... which could take awhile.
So here's what I did to work around it and get back to work (it took less than 10 minutes):
create new project with no activity
(Do the rest inside the IDE, not using Windows or DOS.)
copy all .java files into the java folder in the IDE (it's ...\app\src\main\java\)
copy all res folders into the res folder (...\app\src\main\res\)
copy all asset files into main folder (...\app\src\main\assets\)
copy androidmanifest.xml into main folder (...\app\src\main)
do a global replace of old project name to new project name
I didn't change any of the files in the new project's ...\app\ folder because compilation was normal.
(I'll tell you this: when I saw what I THOUGHT were mangled FILES and looked at the History and saw nothing resembling what should have been there, I got a sick feeling, but I immediately opened Windows Explorer, selected all of the project's java files, and opened them, en masse, with Notepad++. Whew. No problems seen. (I didn't really think AS could actually mangle the files and I doubt it ever could. But it did wake me up at 5am!))
copy your android project to another location then open it from android studio
I changed my projects location and it solved my problem. This happened when my system was accidently shut down due to power failure.
I have recently upgraded my laptop and re-installed Android Studio to the latest version and imported my app. The problem I am facing now is that when Android Studio start it finishes the gradle build etc, but shows errors all over my code. I can still debug the app on my phone and all is working.
How can I get this resolved?
Thanks
I finally resolved this when it happened to me. The steps I did to resolve my problem
Build -> clean
File -> invalidate caches / restart
Delete .idea folder, close and reopen project
Normally one of the first two first steps is enough but today I actually had to delete the entire .idea folder and reopen the project to get rid of the "errors" (only IDE errors, project still ran for me).
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
In my case (Windows), I have faced the same issue with 2 version of Android Studio,
1. Android Studio Arctic Fox | 2020.3.1 Patch 4 (My previous/normal IDE used)
2. Android Studio Dolphin | 2021.3.1 Patch 1 (My updated/current IDE used)
First, I thought this problem can be solve by Build>Clean Project, or Build>Rebuild Project, or File>Invalidate Caches..., but sadly won't work. So, I decided to update my IDE Arctic Fox to Dolphin.
Download from official site, installed with different folder (C:\Program Files\Android\Android Studio1), but project folder still same. During opening project, it won't run unless change Java version to Java 11 (File>Settings>Build, Exectuion, Deployment>Build Tools>Gradle>Gradle JDK>11 version).
Try opening several projects, however the IDE sometime still show the redline code, but the app can still debug/run as usual. Latest method I used, File>Invalidate Caches... And IDE haven't show any redline code.
*Remark: Don't know how long the latest method I used will work.
I cloned my repo and now Android studio (1.3.1) is having hard time detecting my module 'app'
It is not showing any module in edit configuration(as in image below).
It's already defined in 'Settings.gradle'
include ':app'
I tried importing this app module but it says project already contains module with this name
Tried other solutions too. Stuck here.
Note: This repo doesn't have .iml file of project.
Had a similar issue with Android Studio 3.5.3.
Deleting .iml and local.properties files along with .idea and .gradle folders before reopening the project fixed my issue.
Different SDK installation worked for me.
How I came to know?:
(Meanwhile 2 days passed in this issue, I tried all possible solutions like adding facets, adding modules etc. (I came to know it is working in other collegue's machine ) But they didn't work, So last option for me was fresh installation of Android Studio. So I...)
1. Installed Android Studio 2.2.3 with different sdk location unknowingly(Let's say loc2).
2. It was working, later I made batch update to 2.3.2. After update, I chose project location as sdk location (Lets say loc1 ). This time it din't work and I got same error. This was a moment when switching to loc2 worked!!
Using Android Studio 1.0.2 (Windows).
How to make a res/layout-land folder?
I try, it seems to work (no error messages), but the folder does not show up in Android Studio.
However, the folder does exist in the file system.
I have some old project (converted from Android Studio 0.9.x): They seem to work better.
I had the same problem. You have to change your structure explorer from Android(I think its default) to Project. You will see the layout-land folder under res.
You can change the structure explorer in Android Studio from Android to Packages:
g
Also after restarting the Android Studio application I was able to see the land folder.