There's a single project in one of my working sets that completely broke my Eclipse. I can't refresh it, I can't close it, I can't delete it. Usually, the way I fix other projects is by deleting them in Eclipse and reimporting them. I can't do that for this one. Because of that, I can't use this working set, there's walls of error everytime there's a SVN status cache refresh.
I don't know where the resource should be, where Eclipse is looking for it. The project-name folder does exist in \workspace\.metadata\.plugins\org.eclipse.core.resources\.projects\. Where else should I look?
In the error log, there are tons of Resource '/project-name' does not exist. errors. Same message, different stack trace depending on the call. An example:
org.eclipse.core.internal.resources.ResourceException(/project-name)[368]: java.lang.Exception: Resource '/project-name' does not exist.
at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:39)
at org.eclipse.core.internal.resources.ResourceException.<init>(ResourceException.java:35)
at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:327)
at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:201)
at org.eclipse.core.internal.resources.Project.checkAccessible(Project.java:142)
at org.eclipse.core.internal.resources.Project.getDescription(Project.java:394)
at org.eclipse.wst.validation.internal.ValidationRegistryReader.getValidatorMetaData(ValidationRegistryReader.java:817)
at org.eclipse.wst.validation.internal.ValidationRegistryReader.getValidatorMetaData(ValidationRegistryReader.java:795)
at org.eclipse.wst.validation.internal.ValidationRegistryReader.isConfiguredOnProject(ValidationRegistryReader.java:1053)
at org.eclipse.wst.validation.internal.ProjectConfiguration.extractProjectValidators(ProjectConfiguration.java:259)
at org.eclipse.wst.validation.internal.ProjectConfiguration.getValidators(ProjectConfiguration.java:145)
at org.eclipse.wst.validation.internal.EventManager.closing(EventManager.java:96)
at org.eclipse.wst.validation.internal.EventManager.resourceChanged(EventManager.java:248)
at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:297)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:287)
at org.eclipse.core.internal.events.NotificationManager.handleEvent(NotificationManager.java:251)
at org.eclipse.core.internal.resources.Workspace.broadcastEvent(Workspace.java:371)
at org.eclipse.core.internal.resources.Project.close(Project.java:190)
at org.eclipse.ui.actions.CloseResourceAction.invokeOperation(CloseResourceAction.java:168)
at org.eclipse.ui.actions.WorkspaceAction.execute(WorkspaceAction.java:156)
at org.eclipse.ui.actions.WorkspaceAction$1.runInWorkspace(WorkspaceAction.java:456)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
When I try to close the project, I get this nullPointerException:
An internal error occurred during: "Close Project".
java.lang.NullPointerException
at org.eclipse.core.internal.resources.Project.internalGetActiveBuildConfig(Project.java:752)
at org.eclipse.core.internal.resources.Project.getActiveBuildConfig(Project.java:349)
at org.eclipse.core.internal.resources.SaveManager.getTreesToSave(SaveManager.java:1879)
at org.eclipse.core.internal.resources.SaveManager.writeTree(SaveManager.java:2030)
at org.eclipse.core.internal.resources.SaveManager.writeTree(SaveManager.java:2075)
at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1216)
at org.eclipse.core.internal.resources.SaveManager.save(SaveManager.java:1145)
at org.eclipse.core.internal.resources.Project.close(Project.java:194)
at org.eclipse.ui.actions.CloseResourceAction.invokeOperation(CloseResourceAction.java:168)
at org.eclipse.ui.actions.WorkspaceAction.execute(WorkspaceAction.java:156)
at org.eclipse.ui.actions.WorkspaceAction$1.runInWorkspace(WorkspaceAction.java:456)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
How can I fix this?
(I use project-name in lieu of the actual project name.)
Hmm, might there be some handles alive? The error seems to indicate eclipse's not able to flush the closing-project change - if possible you could maybe try shutting the jvm instances.
If you didn't already, try to remove project from the working set(configure working sets -> edit) /remove the working set and create again without the plugin.
When importing - do you copy the project to the workspace or leave in the original place? I know you have already imported the project so it's just a thought for future I found myself useful :)
I've got a problem
I created the activity and xml files in a git branch.
Commit these tasks, and change the branch to do something else.
However, when build app, the following error occurred.
/Users/xxxx/Desktop/product/product-app-android/app/build/generated/source/kapt/stgDebug/kr/co/product/product/databinding/ActivityDebugUserInfoBindingImpl.java:8: error: cannot find symbol
ActivityDebugUserInfo is the file I created in the previous branch.
There is no such file in the current branch. Nevertheless, it was created automatically
I repeated clean project and rebuild, invalid cache and restart. However, the problem was not solved.
The automatically generated file has been revived like a zombie.
Obviously, I think the file will be automatically generated based on some cache data.
But i don't know what it is.
How can i refresh generated databinding file?
self answer.
In my case, after fixing the following code, the problem was solved.
To speed up the build I used the following code in gradle.properties:
org.gradle.daemon = true
org.gradle.parallel = true
org.gradle.configureondemond = true
org.gradle.caching = true
Because of this, clean did not work properly. After commenting the code, it worked.
The same error as you.
Need change org.gradle.caching = true toorg.gradle.caching = false, and then everythis is ok.
But why? We can't use incremental builds? What's the actual problem?
org.gradle.caching = true can dramatically speed up clean and incremental builds.help provide quick build performance wins
I am trying to make dlib-android on Android Studio. It was downloaded from:
https://github.com/tzutalin/dlib-android.
After changing a couple of things such as a mips64... file, it synced and built successfully. But when I try to run with a device or a virtual device, I always get
"Cause: invalid code lengths set" error. The run tasks ended at App:packageDebug. From the long list of things, three under compiler are more informative I guess:
org.gradle.tooling.BuildException: invalid code lengths set
java.util.zip.ZipException: invalid code lengths set
java.lang.IllegalStateException: Still waiting to inspect output APK's res/raw/shape_predictor_68_face_landmarks.dat
On the right side there was: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:packageDebug'.
I searched all over the places and tried everything I could find, but it did not work. Also, I cleaned the cache and restarted, I tried different emulator and devices. I also tried different project settings and structure settings.
I also noticed that a very similar post was not answered:
build failed because of "org.gradle.tooling.BuildException: invalid code lengths set"
I would like to add that other projects made on the same machine went through fine and ran well on phones or virtual devices.
Or, is it caused by the large res/raw/shape_predictor_68_face_landmarks.dat file that it could not compress?
Or, should I remove the current android studio and install an older version?
Thanks a lot for any suggestion!
I came up with is by downgrading your project level gradle to 3.1.0. It seems to be working on it. The only reason why I think it is causing the problem is latest gradle plugin try to validate every file in your project and somehow it cant read the shape_predictor_68_face_landmarks.dat.
Reference: https://github.com/tzutalin/dlib-android-app/issues/47
I am new to kotlin, i have converted some code from java but it seems like there's something wrong, The R in findViewById(R.id.my_id) is highlighted in red and it shows this message : "Unresolved reference: R".. I've been looking for a solution but i seem not to figure it out, So what should i do?
Here's a screenshot :
The issue can be caused by many factors,
as mentioned by martomstom in this Answer the issue is sometimes caused by com.android.tools.build:gradle version, changing it's version to a more stable one would solve the problem: for example: com.android.tools.build:gradle:3.4.0-alpha02 with com.android.tools.build:gradle:3.2.1
Also, having libraries from the same group, but with different versions may cause the problem or even more runtime errors. use the exclude group method like the following : implementation('com.squareup.picasso:picasso:2.71828') { exclude(group: 'com.android.support') } in this case, picasso library uses android.support components, the android library version used in picasso is different than the one you're currently using in your app, so in order to solve this issue, we have to exclude it completely from its sub library and class groups.
It can also happen by the mismatch of resources and code, including this importation line in your activity may solve the problem too : import com.package.name.R
Sometimes it can happen because of the IDE, performances or memory.. Cleaning the project from time to time may save you some time, on Android Studio it would be something like this : Build -> Clean Project / Rebuild Project - Cleaning IDE cash also helps with performance and memory, on Android Studio it would look like this : File-> Invalidate Chases/ Restart -> Invalidate Cashes and Restart
I noticed that this problem happens to me the most of the time when importing new resources, Using prohibited characters in their names would fire the error, such as . , , - , UpperCase or special Letters
And as a suggestion , if you're using Kotlin, i really recommend using Kotlin extensions in your activity such as : import kotlinx.android.synthetic.main.activity_page.* or if you're using a custom view : kotlinx.android.synthetic.main.view_layout.view.*
after that, in onCreat() method of an activity , you'll only have to call the id, for example : my_edit_text_ID.text = "Kotlin Dbest!", or from a custom view : mCostumView.my_edit_text_ID.text = "Kotlin Dbest!"
EDIT :
I have faced this issue againe and the problem was the '' R '' library was imported from 2 different sources :
com.android.R
com.example.package.R
You must only import the '' R '' library with your application package name,
in this case com.example.package.R
Sometimes the library is not imported at all, to import it, click on the
unresolved reference R and press Alt + Enter
EDIT:
As tobltobs mentioned in the comments section: " Most of the time the problem is caused by another error which prevents the build system from creating generated sources. To find the root cause look at the gradle log (the "toggle view" icon below of the green hammer in the Build output) and look for errors unrelated to R or BuildConfig (also generated). If there is no other error left and the problem with R persists then maybe something of this list might help. "
EDIT:
As Patrick Beagan mentioned, Kotlin extensions are now deprecated - I'd advise using ViewBinding instead
I used com.android.tools.build:gradle:3.3.0-alpha13 and had the same issue. Changing to stable Version 3.2.1 solved this problem for me.
So this is a misleading error.
The fastest way to get to the root cause is to run:
bash gradlew assembleDebug --debug
then scroll up and look for the real error happening.
However, if it still doesn't seem like you have the answer you are looking for, then read on.
I'm going to explain the 30,000 foot view of what is happening. This is not EXACT order or EXACT flow, it is just pretty damn close ;) so if you know more then I do of the exact order and care to make corrections with links, feel free I won't stop ya :).
The Process
The R file is generated code.
There is an order to the generation.
Gradle will do it's magic, pull it's dependencies and kick off it's
warning and error tree first,
then Android converts all Kotlin to Java behind the scenes. Yup that's
right, our beloved Kotlin still has to be Java to compile for our
beloved ART virtual machine.
Then it runs through and does the adapters that you have created for
JVM Statics and a few other tasks.
Next up it compiles all the xml databinding files first to create the
generated databinding files.
If everything succeeds it moves on to processing the assets and
resources. Which creates pointers or IDs for each resource that you
reference in code. Next it will run through and begin compiling the
code and packaging process after that.
Pretty straight forward process, but here in lies the problem.
The misleading Error
If any step fails before the R generation is complete, then the R does not get generated. Sometimes a simple rebuild is all you need to do, sometimes a simple File->Invalidate Cache and Restart is all you need. However, more often than not you have a code issue in your gradle, your xml, your databinding or your adapters that are preventing the compiler from even reaching the R generation stage.
So the next question is
"Well shoot, how do we troubleshoot it if the errors are worthless or
non-existent".
Well first let's talk about the many ways these errors present themselves.
Duplicate Databinding class found
xml Binding Error at line #
Couldn't find matching signature of bind:customAdapterMethod
Can't find R file of the correct project, only shows import options for sub modules or incorrect namespace R files.
Couldn't find DataBindingUtility or DataBinding for activity/fragment
And many other various ways as well, too many to list them all
Next, let's talk about potential candidates causing the problem. As there are sooo many lol.
Gradle Syncing issues
Bad versions of Gradle or Tools, you may have gone too far forward in your last gradle file modification. Try stepping back one version and "invalidate cache and restart" if that fixed it, great, if not, read on.
Caching Issues (File->Restart and Invalidate Cache)
xml elements with wrong namespace
xml elements with bad IDs or references IDs out of order (i.e. you say align to right of an element that is lower in the xml document then the sibling element that is trying to reference it)
xml data binding issues referencing namespace or member that doesn't exist or is not typed correctly
xml data binding issues in non-auto-filled spots like custom attributes using adapters as those are harder to spot. i.e. bind:myCustomMethod=#"myObject.mistypedProperty()"
JVM Static adapters with issues or duplicated signatures
Duplicated or bad character in the Strings or Dimens file or any other xml file for that matter
Private variable marked for #Binding without properties to access it
Member variable marked for #Binding that matches a parent class method causing duplications that manifests itself in almost impossible errors
Mismatch of types like using an adapter that takes (Int) but you are passing (Int?) via data binding and it isn't recognized with JVM Statics until compile time
You selected IMPORT on a popup to import R file of a sub module instead of the application file
Having bindable members in a child or parent class, but not giving fully qualified namespace to class cast in the XML usage of the parent or child class. As the databinding compiler is not smart enough to realize the variable provided for class Foo is also parentFoo baseclass, so you have to qualify it as android:text="#((com.path.parentFoo)foo).parentMethod"
Having a method name in a class, that matches a "generated property from #Binding member variable" i.e. firstName as a variable, but then having a method called getFirstName in a parent or child class, because you are now matching a method name that will get auto generated, thus causing dataBindingUtility duplication class errors.
There are more causes, but this should give you a series of places to look, but the list can go on and on seriously.
Unfortunately this happens a lot in bleeding edge technologies where the UI tools are not up to speed with the terminal based tools yet. So I suggest you run from the project root in a terminal with
bash gradlew assembleDebug --debug
When it fails, and it will. Start scrolling up through the logs until you find the red where you see what is actually failing and preventing the next stage from occurring.
You will find this especially useful when you start dealing with databinding.
TIP:
When you start dealing with databinding, make sure you compile and run often because the goal is to recognize right away before doing other files to make sure you didn't break generation and make your life MUCH easier to know code you just added caused the issue before getting too far.
Times to compile and run to confirm no issues before moving on.
If you add a few JVM statics compile and run
If you add variables to your XML to use
If you bind to properties of your model in 1 file
If you add a binding to a JVMStatic
If you add bindable members or properties to an model
If you refactor moving observable member variables or properties into children or base classes
Any other xml or binding related elements that can effect the generated code.
Like I mentioned above, the reason is to avoid getting so many changes, that it becomes a troubleshooting nightmare to find a generic vague, horrible error related to generated databinding code. I'm sure the tools will improve, but for now, do yourself a favor and compile and run often when changing Databinding related items.
Happy Coding
Use gradle commands.
In Android Studio, on the right menu:
Gradle -> :app -> Tasks -> build -> clean.
After that, Gradle -> :app -> Tasks -> build -> build
I had wrong import statement import android.R instead of import my.project.package.R. Fixing it solved the problem
I had the same problem, and I tried not to downgrade from gradle version 3.3 to gradle version 3.2.1. Instead I updated Android Studio to version 3.3, which made the trick for me ;-)
This worked for me. How much work it is depends on how big your project is. I started a new project, created the required modules (XML, Kotlin, colors, strings, etc.), then copied the code into the modules in the new project from the modules in the old project. Copying XML saves a lot of time compared to recreating the UI. All in all, it take a little while, but I have spent much more time tring to fix the unresolved reference error without it.
TRY THIS
Go to the content_main.xml file and there you need to change the
android:id="#+id/??????"> line of code to whatever id you have given to your file.
Replace question mark ?????? with the related file id name.(IF you dont know the id go to the design tab on the bottom and click on the related Asset.
On the right side below attributes, you can find the ID you have given to it.
If it is blank you can freshly name it and Android Studio will write the code.
Then restart Android Studio. Hope this will help. Happy coding.
I believe that I came across the real answer (though by accident).
I also, as the OP had my KT file fail to location R. as well as other classes that happen to be in java. What I noticed was that there was a case difference I the filenames. Once I corrected the import statements to match the case of the package (aka, folder) the errors resolved.
I had the same problem with R reference too.
Finally Android Studio 3.3 has been released and using 'com.android.tools.build:gradle:3.3.0' the problem has been fixed!
I update Android Studio to version 3.3.1 and solved this problem.
Downgrading gradle version worked for me.
I changed :
Gradle version from : 4.10.4 to 4.4.1
and Gradle Plugin version from : 3.3.1 to 3.1.3
If your are experiencing this issue in Kotlin because you cannot reference the elements of the xml layout by ids. (e.g. R.id.adView) then try removing the line import android.R from your kotlin file.
For me it was because I had created a new package and R wasn't available until I imported it from the package above
I faced the same issue. I restarted my Android Studio, invalidate caches, Sync Gradle but nothing was working. Then I looked into my file and there are 2 imports of my R. 1 import was related to my application package and the other was related to Android.
import com.example.myApp.R
import android.R // This import was added accidentally during the build.
Removing second import related to android solved this issue.
I had an issue because of this import:
import android.os.Build.VERSION_CODES.*
In the latest version it contains R
I had same problem while using auto-manifest plugin. Adding AndroidManifest.xml explicitly solved the problem to me.
I used to File --> Invalidate Caches... and issue resolved.
Just restarting Android Studio solved it for me.
I also had this problem, Gradle Sync, and Invalidate Cache, and Restarting Android Studio Didn't help. Upgrading and Downgrading Gradle were also not helpful.
What worked for me is: Make Project (Ctrl + F9) and then try to run the project.
I solved this error by following Android Studio's lint tools to upgrade the version of a dependency in the project-level gradle file. In this case, I upgraded androidx.navigation:navigation-safe-args-gradle-plugin from 2.3.2 to 2.5.2 (latest version), then synced the project.
Here is the solution,
File->Project Structure->Project, select Android Gradle Plugin Version as 3.2.1 from the drop-down. then click apply.
I keep getting this when trying to start a new project
ERROR: Unable to open class file C:\Users\Levi\Desktop\Android\workspace\Droid1\gen\com\androidbook\droid1\R.java: No such file or directory
I tried changing preferences to alter build path to project, but it still wouldnt work,,,
Is subfolder on desktop a bad place to install Eclipse?
Clean works sometimes and should be tried. I also find that blowing away the gen directory and refreshing will cause it be to rebuilt. Try that as well.
However, sometimes even that doesn't work and I've been forced to remove the project from Eclipse and then re-import it. This, unfortunately, works for me every time if the above has not.
Good luck.
Im also getting that error, running a Project->Clean in Eclipse helps for me.
Project->Clean should certainly fix this (unless your resources won't compile for some seperate reason).
I remember that the first time I ran Eclipse (in mid 2009, can't remember if it was Galileo or Ganymede or whatever) on Windows Vista, it presented several problems that were eventually traced to Eclipse itself being in a directory whose path contained a space...
Usually, the above tips (refresh, clean) work for me. But lately I had a very persistant instance of this error, which was caused by something else:
One of the layout .xml files in res/layout contained a reference to a custom view (org.company.project1.MyView). However, I had changed the package path (org.company.project2.MyView), so the reference had become invalid.
Thus, if everything fails try browsing your layout .xml files for invalid custom element definitions.
Cheers
after spending hours trying to ultimatly discover the issue behind the Class Issue not being found, resolved,or directory not there issue....
sometimes yes the issue is due to a bad binary or xml... as sometime a clean will do the trick or a xml edit will solve the day.. when all else fails.... this may do it..
"create a new workspace"
go into the workspace.... and then
Switch to your old workspace... in the newly formed workspace...
this was my silver bullet. so frustrating to not have a solid answer.
using Version: Helios Service Release 2
Build id: 20110218-0911