Gradle screwed up my app in AndroidStudio, how to fix? - java

I'm working on a new app in AndroidStudio, everything was working fine, I was testing the app on my phone, etc.
Then at some point AndroidStudio gave me a popup in the lower right corner, something about Gradle. I didn't quite understand it, and hit Accept or something like that. Then suddenly something happened to all my projects in AndroidStudio (not just the one I was working on):
All build modules are gone.
I can't make any new build modules, because "Error: Gradle project sync failed. Please fix your project and try again". I never synced anything with Gradle previously, why do I suddenly need to do something like this?
Clicking "Sync project with Gradle files" doesn't work: "Plugin [id: 'com.android.application'] was not found in any of the following sources". Where does "com.android.application" even come from? I never added any plugins anywhere.
"Everything" is wrong in all my Java files, I even get "Cannot resolve symbol 'AppCompatActivity'" and "Cannot resolve method 'OnCreate(android.os.Bundle)'". Wtf?
All my Java files have this red symbol, which says "Java file outside of source root". Why are they suddenly in the wrong place?
Nothing is working anymore, restarting AndroidStudio doesn't change anything, switching project doesn't change anything, and where did my build modules go?
How do I make this go back to normal?

Try:
Build -> Clean Project and then Build again
File -> Invalidate cache/restart
check your run/debug configuration in the top toolbar, it should be app by default.

Related

Android java class/symbol not found despite being placed in the same directory

I have encountered issues in my android studio regarding java classes/symbols not found, despite these classes and symbols being placed in the same directory, or under the same parent directory. I am making use of the DJI's mobile SDK for android.
Example of errors:
Cannot resolve symbol 'DJISampleApplication'
For illustration, here are 2 screenshots
First example. Clicking on "import class" causes android studio to create a brand new class instead of linking it to the existing one.
second example
However, oddly, when I go under "Build >> Make Project" , or "Run" to deploy on a real android device, the app can be installed, and there are no errors (only warnings).
Things I have tried:
Uninstalling and re-installing android studio
copying the whole project from the original files in again
Trying on another computer, which works. However, as i am only assigned this pc, i have to get this to work here as well.
Thank you in advance !
Your best bet is to invalidate caches and restart. Solves 99% of problems like this for me.
You can also try to reimport the project using the gradle tool window ...
Click the reload button here ...

IntelliJ is giving cannot resolve compiler issue

I am getting "Cannot resolve symbol" for almost all classes in my intelliJ.
But when i build it, build gets successfull.
Only the compiler will show these errors.
I have tried following things:
deleted .idea folder, deleted build folder
, Invalidated caches and Restart,
Reimport Gradle project.
When I check the Gradle properties, it is pointing to the right JDK(OpenJDK 14)
and this issue is intermittent, not exactly sure whats causing this issue.
let me know if I am missing something here.
below is my compiler settings
All that i see is unresolved classes.
and Project JDK is correct and my Project is referring to same JDK.
check jdk setting in project structure as per picture below, or from main menu file -> project structure -> platform settings -> sdks, this is a typical error when project SDK is not set
also, run graddle refresh dependencies(3) and refresh dependecies in intellyJ(4):

R.layout.main Cannot Be Found / Cannot Resolve Symbol R

All of a sudden I am getting red underlinings under my references to elements e.g R.textboxID. I did some googling around and I found that the error occurs when Android Studio can’t generate your R.java file correctly.
My question is how does Android Studio just suddenly not know how to generate my R file correctly when it was generating it well all along? How can I fix this problem permanently?
Select Build > Clean Project from the Android Studio toolbar, wait a few moments, and then build your project by selecting Build > Rebuild Project.
If a single clean/rebuild cycle doesn’t work, then try repeating this process a few times, multiple clean/rebuild cycles in quick succession usually work.
This usually happens when some unexpected event, like an IDE error occurs and the project needs to be rebuilt. Just hit Build -> Rebuild Project.
Sometines this may occur after you modify your build.gradle file, and sometimes, if it only occurs within one of your classes, you might not be inflating it correctly.
Gradle sync succeded? Try one of the following:
Clean end rebuild your project
From Android studio menu: File->Invalidate cache/restart, then clean and rebuild project
If none of above helps, close Android studio and remove ~/.gradle directory. Then run Android Studio, open your project, wait for finish sync, then rebuild project
Also make sure your gradle configuration is correct and resource xml files syntax is correct.
Please check the import statements at the top of file some times there may be import com.android .R will be there so you should delete that statement and it will work fine

java.lang.ClassNotFoundException DexPathList . Causes?

Can anyone explain to me the cause of this error? I know what is dexpath and dex class in android and how to fix this error. but don't know what is the cause of this error popping up every now and then.
This error occurs when
I transfer my project from one pc/laptop to another pc/laptop.
Whenever I've updated my android Studio lets say from AS 2 to AS 3 canary or stable release.
Uninstall and reinstall the Android studio and try opeining the Project again.
How I'm Fixing it:
Just remove all the dependencies and everything related to DEX Class file from gradle and sync it and then revert back to gradle settings with all the DEX file and dependencies added and Sync again. VOILAAA ..
And this is really annoying. How I can avoid this issue for my other projects without going through all this gradle sync tweak.
I had the same issue with moving projects to different system. when you move your project folder just leave out the build folder and you'll not see the error next time.
The error says a lot more then just class not found exception in the log. The path of the files/ app-parts.apk gets invalid when you move your project to a different system.
Just don't copy or just rename the old build folder to something else and open your project in AS. Build->CLEAN , BUILD->REBUILD and everything will work.
Happy Coding..

Error sign in Maven project

I have this in my eclipse workspace:
As you can see there the main folder of the maven project has an error sign, even though it's subfolders contains no error.
Why do this happen?
Could this possibly result with an error?
Or could it possible be a bug?
Just for clarifications:
This project doesn't seem to have any error and is working fine. But this error sign is bothering me, that maybe this error sign could possibly result with an error in the future. I just need an explanation on how did this happen?
Again, Many thanks to all of you..
There could be some error which is not being displayed in package explorer or project explorer. You can find it in Problems view.
Later you may right click project Maven > Update Project. If the symbol still exists, refresh the project using F5.
Hover that error sign and look if hint will popup. What does it says, if any?
Try to clean Eclipse cache. This solution, for example.
If Cleanup won't fix that:
Start new workspace.
Import yours project to that new workspace.
If it worked - try again with new workspace but with workspace settings, imported from initial workspace.

Categories