After I had emergency reboot my computer I have problems with imports from JDK and SDK for all my projects even new. Android Studio doesn't see any imports except Gradle libs and R.class. Moreover, it does not see packages which I were created. I clean project, rebuild it but nothing has changed. Maybe someone had something similar?
In the File menu, you should see an option for "Invalidate caches and restart". Select it and allow the application to restart.
This will clear any corrupted symbol caches and allow them to be rebuilt.
You may need to rebuild after this step for everything to show up correctly.
Do this
File-> invalidate caches/restart
an option for "Invalidate caches and restart". Select it
See Image :
Related
what is the actual root cause of this issue? I already sync with gradle files but eventually failed.
Just sync your project with gradles. File --> Sync Project with Gradle Files
Build -> Clean Project
Build -> Rebuild Project
File -> Sync project with gradle files . If not worked then try
File -> Invalidate Caches / Restart .
It's work for me !!!
That could be fixed in one or two steps, depending on how nice is Android Studio today:
Try to sync your project with gradle files:
If that doesn't work, invalidate Android Studio caches and restart. That should fix the problem:
The reason behind the first solution not working could be related on gradle cached dependencies problems, but who knows 🤷
This error mostly occurs when you're trying to open Android App from existing application and probably developed using different computer.
Almost all the troubleshoot methods like File->Sync Project, Build->Clean, etc. Might not work.
This is applied only if you are trying to open the Adroid Application from existing application.
The proper way to evoid errors is only to open sub folder from the path not the root folder. Below is the example of how to properly open the Android application from existing application.
For example in your Message_App/messages/msg path, you must open msg folder not your Message_App folder.
Message_App/messages/msg
>msg
>manifests
>java
>res
Just you have to do >> open File --> Sync Project with Gradle Files
and then after >> open File --> invalidate Android Studio caches / restart so done this problem.:)
sometimes Sync project with gradle File dosent work; you should check the compileSdkVersion in the "build.gradle" file , make them is the same number within all library/modlue
This issue is because the gradle file is not found when starting the project. To fix this ensure your connection to the internet is stable during project startup, the gradle file is downloaded automatically, after a successful download, You should be good!
Issue happened to me when I changed the res>values>styles.xml
What I change was
"Theme.AppCompat.Light.DarkActionBar" --->>> "Base.Theme.AppCompat.Light.DarkActionBar"
Solutions I tried.
Build -> Rebuild Project (Not worked)
Close all files and Open again. Then
Build -> Clean Project (Not worked)
File -> Sync project with gradle files (Not worked)
Close the Android Studio while project still opened. Opened it again. - It Worked.
If nothing of the above steps work, Then simply undo the changes that you have recently made, and then build gradle.
In my case, I have added one dependencies and this problem raised, so I removed that dependencies build the gradle and then again add it.
Problem Solved..!!
I had this problem and it was because I didn't have the right API level installed (and I was also getting an error to that effect). I went into Tools --> SDK Manager and installed the API the system was telling me I needed (in my case, 30). I did that and restarted Android Studio and was able to get into XML files.
I am using Android Studio(3.0) to make an Android App. But suddenly the Android Studio has stopped showing inline errors where as there are still errors which are shown while building the app.
Till now I have tried the below solution
1) Clean Project
2) Rebuild project
3) Invalidate cache and restart
4) Check if the power save mode is on
5) Resync the Gradle
6) Delete the .gradle and .idea folder
But none of them have been useful. This problem has started suddenly.
Any help would be really appreciated.
Try running inspection manually with Inspect Code on the Analyze menu.
If that doesn't work then try doing this:
BACK UP your project.
Delete all .iml files and .idea folder.
Relaunch Android Studio and import your project
In my case, deactivate "Power save mode" solve the problem.
In menu "File->Power Save Mode" (just in the end of menu, preview to "Exit" option)
Slds!
Error:Could not open initscript class cache for initialization script 'C:\Users\Avishek\AppData\Local\Temp\asLocalRepo14.gradle' (C:\Users\Avishek.gradle\caches\2.2.1\scripts\asLocalRepo14_dkwbdtenxxgt2q2wfe57wj30b\InitScript\initscript).
java.io.FileNotFoundException: C:\Users\Avishek.gradle\caches\2.2.1\scripts\asLocalRepo14_dkwbdtenxxgt2q2wfe57wj30b\InitScript\initscript\cache.properties (The system cannot find the file specified)
This error gives when I want to rebuild a project or clean project or run project.
Please someone help me...Thank you...
Don't use Gradle with a fresh version of JDK. It may not support it. In my case, downgrading JDK solved the issue.
You should delete "scripts" folder from "C:\Users\user.gradle\caches\2.4\" via this answer. Then refresh gradle from Android Studio. This worked for me.
You may have opened Android Studio twice. In that case close one of the instances and click on Try Again or Synchronize Gradle, or restart Android Studio. It is because the gradle build was not completed and other dependencies like classpath did not initialize at startup.
You should check android studio power save menu in file. If it was previously selected, then it should be unselected the power save mode in android studio in file menu. I hope it will be worked.
In my case I have deleted .gradle folder and clean the project on re run the project was working fine.
Close the android studio
Delete this file from your pc C:\Users\Avishek\AppData\Local\Temp\asLocalRepo14.gradle
Delete folder from your pc C:\Users\Avishek.gradle\caches\2.2.1
Your app in .gradle and .idea file is also delete
And start your android studio
2022 New Answer for Kotlin base projects
Open IntelliJ IDEA CE
Click Create New Project or File/New/Project
Important !!!
Select Kotlin from left side of window.
Select IntelliJ in Build System.
Click Next.
Done. You will not have this error when you run your Kotlin file in the IDE.
I'm fairly new to Intellij and Java and am unable to use libraries from one "module" in another. I am seeing red class names and getting "Cannot resolve symbol ..." errors all over the place:
The other modules are referenced in File | Project Structure all the other module's Paths are correct and include the *.classes I'm trying to use:
I have also tried a File | Invalidate Caches but am still having the same problems.
What do I need to do to fix this?
Listed below are steps which may fix the problem:
1.Invalidate and refresh the IntelliJ's caches
File Menu -> Invalidate Caches / Restart -> Invalidate and restart
2.Project SDK selection
Check project settings from File Menu -> Project Structure
Ensure an SDK is selected for the Project SDK. If is selected, click the 'New' button, select JDK and then select the correct path to the JDK e.g. /opt/java/jdk1.8 or c:\Java\Jdk1.8
3.Corrupt JDK
There may be a problem with your JDK installation, re-install JDK
4.Re-import the project
Close the project if it is open in IntelliJ
Delete the .idea folder in the project source code folder.
Start IntelliJ and Import the project.
You can choose any of them which will work for you.
I faced a similar problem for no reason, I think it was caused by IDE(android studio). I have tried all of the above solutions but not worked. Finally, in my own situation, I solved this problem by the following actions:
Delete your .idea folder in your local project.
Reopen this project and just let Gradle run itself.
It was worked for me. I hope that my experience will be useful for you.
You need to add your external libraries/classes under dependencies in order for IDEA to see them when doing code analysis/autocomplete.
You can go to "File->Project Structure"
From "Project Settings", Select "Project" tab and there make sure that "Project SDK" has proper JDK selection.
After you add dependencies to POM file, make it a habit to refresh POM by clicking on the 'Reimports maven projects' icon. Its the first icon in the maven tool window located to the right of the main intellij editor. Its a blue icon with 2 circular arrows. Clicking it ensures that the added dependencies are fully integrated into your project
Run it from the project's root folder.
$ mvn -U idea:idea
One more advise would be to make sure that you import the project properly. If it's a maven project, import pom.xml and if it's a gradle project, import gradle.build file to make sure that all the dependencies are downloaded correctly.
Just got this.
Just went there.
Invalidated the cache.
Seemed to work until I wrote further lines.
Then noticed that I was writing my code outside of the main() function.
Moved the ending curly bracket further and voila.
Whenever I clean my project is says: PSI and index do not match
What should I do?
Important note: This will wipe the shelf, local history, and potentially other cached data.
File menu > Invalidate caches and restart. The PSI cache is one of the caches that are affected by this command, so this should fix it up.
Whenever I navigated to a class, I'd get this PSI error. Clicking the details in Android Studio, it included the following:
viewProvider=SingleRootFileViewProvider{myVirtualFile=jar://<user-directory>/.gradle/caches/modules-2/files-2.1/com.squareup.haha/haha/2.0.3/e0672395ac43377f2510b14839342a24fdf35c18/haha-2.0.3-sources.jar!/com/squareup/haha/guava/io/GwtWorkarounds.java, content=VirtualFileContent{size=5678}}
Based on this info, I tried deleting <user-directory>/.gradle/caches/modules-2 and restarting Android Studio and it seemed to fix the PSI error, and it didn't seem to delete local history (though I don't know if anything else important was deleted).
Invalidating caches didn't work for me.
Only a complete re-install of AS and all relevant SDK, Gradle etc... did the trick.
I started by uninstalling AS.
Then I manually deleted the SDK folder.
I also deleted the .gradle and .android folders in my C:/Users/[my.user]/ folder.