Android Studio not detecting my module - android-studio

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!!

Related

could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRootsManager

My project works and builds successfully on my Mac but I cloned from github and although Android Studio appears to work normally, the project wouldn't build. I setup this project using Kotlin DSL.
Gradle sync failed: could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRoot
Tried invalidate cache, removed all .gitignore rules but it's still the same.
Any ideas?
I had the same issue (Note : Running Linux/Ubuntu 20.04 LTS and Android Studio 4.1.1).
Things I tried that did NOT work and error persisted :
Invalidate Caches / Restart
Reboot
Nuking the .gradle and .m2 folders
Android Studio re-install
Downgrade kotlin gradle plugin from 1.4.21 to 1.4.10
What did work :
Moving the project to a different folder/location on disk and open Android Studio
As soon as I moved the project back to the original location I would start getting the same error. This lead me to believe it was some sort of caching issue, separate from the caches "invalidated".
Solution :
Android Studio / Intellij creates a hidden folder called :
On Linux :
AS : ~/.cache/Google/AndroidStudioX.X
IJ : ~/.cache/Jetbrains/IntelliJIdea2020.X
On Mac :
AS : ~/Library/Caches/Google/AndroidStudioX.X
IJ : ~/Library/Caches/Jetbrains/IntelliJIdea2020.X
On Windows:
AS : %HOME%\AppData\Local\Google\AndroidStudioX.X
IJ : %HOME%\AppData\Local\Jetbrains\IntelliJIdea2020.X
Inside this folder are other various folders, however I removed the relevant workspace file (workspace/[project name].[hashed value].xml) after which problem went away when opening the project again, from its original location.
So it appears that "Invalidate Caches / Restart" does not "Invalidate" all caches!
I hope this resolves you problem!
Update
As this answer has had quite a few upvotes it would appear that this might be a ongoing bug with Intellij. If anyone has this problem, before resolving with the suggested solution consider checking there isn't an open issue on the bug tracker and submitting a new issue : https://youtrack.jetbrains.com/issues
Feel free to edit this update with issue if one is opened.
Update 2
Issue opened by #GeniusRUS :
https://youtrack.jetbrains.com/issue/KT-44937
For Mac users delete the following file:
~/Library/Caches/Google/AndroidStudio4.1/workspace/<your_project_name>.58dfbe93.xml
PS: Thanls #Mark Keen for solution.
basically i deleted .idea folder and then invalidate and restart ... error goes away and built successfull.
This probably isn't the "correct" solution, however, it worked for me. I had to download a newer (Canary) Version of Android Studio to get this error message to go away and to finally build my Android project once again. I found this YouTrack JetBrains issue where people also suggested reverting to previous, known working, versions of Android Studio to get their projects to build again.
This is a SUPER frustrating issue and I hope that one of the approaches resolves your build issues for you!
Here are the Android Studio Versions Download page for convenience.
After moving projects and files around I had also the honor to enjoy this error in Android Studio 4.1.1 (under Windows 10). Unfortunately, none of the above solutions worked for me but they helped me to narrow down the issue.
So, I found that there is a folder with workspaces under:
%HOME%\AppData\Local\Google\AndroidStudio4.1\workspace\
There are a couple of *.xml files named like the android projects. I deleted the one that didn't work.
Then switched back to Android Studio and used the Files > Invalidate Caches / Restart... feature. Android Studio restarted and the problem was fixed.
Bonus: How I found the workspace folder?
I used the Procmon.exe from Sysinternals where I filtered by the Process Name = studio64.exe. I then used the elephant-with-the-arrow button (Sync Project with Gradle Files) in Android Studio. At the end of the recording there was the workspace folder that Android Studio used just before Gradle failed.
I added a "problem" ticket to YouTrack, where I described my case in detail.
The support agent said the issue has already been fixed in the IDEA 2021.1 platform.
And also gave recommendations for this case
Link to issue
https://youtrack.jetbrains.com/issue/KT-44937
I fixed the issue by changing the root project directory name. You can try that.

Android studio messed up every xml file. How to resolve it? [duplicate]

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.

Android Studio shows wrong file contents

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.

AndroidStudio not showing .gradle files

As said by the title, I cannot find any .gradle file and i dont understand why.
My project works and compiles fine, I dont have any problem inside the IDE but I would like to add SherlockActionBars, and to do that I have to modify settings.gradle and build.gradle, but I just can't find those two files anywere.
NB: The project was imported from eclipse
Thanks in advance
You can just create these files, if it is compiling and working fine in Android Studio 0.2.2 then likely they can just be manually created.
One thing, you said you imported from Eclipse - but did you do the manual step of exporting while in Eclipse? Also - I suggest the eclipse be the version that comes with the Gootle ADT download.
Steps on exporting: http://developer.android.com/sdk/installing/migrate.html

Android Studio: disabling "External build" to display error output create duplicate class errors

I am starting my migration from Eclipse to Android Studio, and start playing with new projects on Studio.
My test project was working fine till I got some errors messages.
I had to do some manipulation (https://stackoverflow.com/a/16876993/327402) to enable the error output to display, and found the issue that I fixed.
Unfortunately, after this "workaround" (Why the hell have I to make such things to see my errors?), I found that there was an error message that I cannot fix:
error: duplicate class: com.mypackage.name.BuildConfig
error: duplicate class: com.mypackage.name.R
I also noticed that I am not the only one to have this issue (see the comment in the SO answer I linked above)
First time, I was able to fix it by enabling "External build" again, but that happened again, because I needed to see the error output and everything is now broken, and I cannot find what happen.
With Eclipse, the R file was easy to find, in the gen folder, but with Android Studio, there are too many files, and I am a little bit lost.
Any idea/suggestion?
I've found a question like this that has some replies here:
Cannot resolve R.java, duplicate class
You can try this:
Delete the Build folder generated by Android Studio automatically
Also you can try to Rebuild project by clicking Build->Rebuild project after deleting build folder.
So, just to let you know...
A few minutes after I posted my question, Google released an update to Android Studio (0.1.5)
See link: https://plus.google.com/+AndroidDevelopers/posts/Y9vhvGaHCbh
Tor Norbye kindly answered my question in this community, and I am sharing here
So the workaround I quoted in the OP is no more mandatory.
Enabling again External build after upgrading Android Sudio let me see the real errors ( a library and some Gradle import that I fixed)
So, I consider the Android Studio upgrade as the best answer to this question...
Ok, I also have the same problem, and this is what worked for me.
I first unticked external build from compiler settings. Then when I compiled i get two errors related to R.java, duplicate class.
Then i delete the build folder manually from finder. Then rebuild it from android studio, but still same error.
Then I again go back to compiler preference and tick the external build setting, and it worked fine after that.
Looks like some bug.
apparently, or at least for me 0.1.5 has a bug and cannot run in external build
because of some path error you can read about here
https://code.google.com/p/android/issues/detail?id=56628
so i switched to internal building, and then i hit the double R symbol bug
after deleting the build path application is compiled without errors but the build folder is not fully rebuilt, I'm missing the R.java file which the internal builder does not make.
i've rebuilt it on the external builder on an unupdated version as a temp workaround while this issues is fixed.
btw if anyone knows how to tell internal gradle to rebuild the build folder please share.
I just had the same problem and found a way to solve it (You can do this with Android Studio open):
Go to you Android Studio projects folder located in c:\users[USERNAME]\AndroidStudioProjects
Locate your project folder and open it.
Delete the folder named build.
From here, enter your application name folder, where you can find another build folder among with libs and src folders and a file named build.gradle.
RENAME the build folder to build2 or something else.
Now in Android Studio go to Build->Rebuild Project.
And after the project was rebuilt, open again the folder where the build2 folder that you renamed is located.
Delete the new folder named build that was created.
Rename your build2 folder to build again.
Done.

Resources