I have a Kotlin-based Android Studio project located at C:\DEV\PROJECT1 which works fine. I copied the project SOURCE to C:\DEV\PROJECT2 and loaded it into Android Studio.
All of my classes as well as my namespace have a red underline under their names in the Project panel to the left and each editor tab. The IDE thinks there are duplicate classes because it's still referencing the source code in the OLD directory.
When I debug, the IDE says there are multiple versions of a class and at the top of the editor window you can choose from either directory.
This is causing a huge problem for me for multiple reasons, so I'd like to get the IDE to forget about the old directory when loading the new copy of the project.
I've tried all the tricks I found on the Internet but none of them work. I've manually deleted the "caches" directory in C:\Users\me\AppData\Local\Google... I've done the same thing within the IDE with File->Invalidate Caches. I've manually deleted the .gradle and .idea directories, as well as all build directories.
I had a friend load the project SOURCE on his computer the same as I've done above, and he experiences the same issue. So I don't believe it's an environment issue.
Does anyone know what's going on here and how to fix it?
Thanks.
None of the other answers mentioned worked for me. What I had to do was change the value of 'rootProject.name' in settings.gradle. Until I did this, it would always remember the old directory where the project used to be and would always use source from that directory.
This makes no sense to me so I'm going bo post another question to see if someone can explain why Android Studio NEVER forgets the location of a project name. I can't imagine anyone ever wanting that behavior.
I'm building an app with NativeScript using TypeScript and Angular. This has happened twice while building the app.
In order to add resources (like images), I add them to my_app_folder\app\App_Resources\Android\src\main\res. I accidentally added a folder called "video" with a file called "sample_video.mp4" into the res folder. When I tried to run my app on my Android emulator using the cloud build, I received this error in my NativeScript Sidekick console:
/mnt/storage/builds/_/b10d99b4991d936c4896cd72f0628901fa996d4c/4.2.4/saintstanreal/platforms/android/app/src/main/res/video/sample_video.mp4: Error: The file name must end with .xml
I realized I had placed the file in the wrong place, deleted the video and the video folder, and tried to build the app again, but now I am consistently getting the above error, even though the offending file is long gone.
This has happened to me before (with a .png file with a capital letter in the name, which android does not like) and I would love to know why. Last time I had to delete my whole project, revert to my previous commit, and rebuild the app, which is frustrating.
My app ran perfectly fine before I added that file, so I know that the problem is not being caused by my code. I tried deleting the android platform and reinstalling it, to no avail.
Any help would be amazing as I am very confused as to why the file, which is no longer in my project, would continue to cause this problem.
Try a clean build to reset the data that was cached.
In Sidekick go to Build and from the menu options check Clean Build
When you enable the Clean Build option, any previously cached data
will be ignored and the application will undergo a complete rebuild.
This type of build will not take advantage of certain optimizations
and may take longer to finish.
As of the resolution of this issue in NativeScript Sidekick, using File -> Clean Cloud Workspace fixes this problem.
If I add an incorrect resource file to Android's "res" folder, try to build (and fail), remove the incorrect file, and use the "Clean Cloud Build" command, the Android cloud build will then work as intended (without having to use the "Clean Build" checkbox when building).
When I start to debug my first Xamarin Android application, I set some breakpoints. Whatever I do, it will still not hit the breakpoint. What's wrong with this?
I have tried many times, but it did not help.
I've found that the name of the folder that contains your project can make a difference. Do you have any spaces or punctuation characters in yours?
The folder name is often the same as the project name, but it doesn't have to be. I had a Xamarin Android project called "Engagement (Android)" within a solution, and by default it was stored on disk at ...\Engagement (Android)\Engagement (Android).csproj
No matter what I did, it wouldn't hit breakpoints. Brand new projects that I added (called Test1, Test2, etc) - debugged perfectly.
When I changed the folder name to "Engagement_Android" (keeping the same project name) - it started hitting breakpoints again.
Other symptoms that went with this included the "Clean Project" option not clearing all the files from the bin/debug folder (it left behind the project's main DLL and PDB file).
The thing that nailed it for me was noticing that when I did a clean build, the bin/debug folder did not contain an "MDB" file for the main exe (in this case Engagement Android.dll.mdb) and so was not been packaged into APK file.
It turns out that the MDB files are the way that debugging information gets packaged up into the APK - without it you can't debug! I think they are created by a tool called PDB2MDB.exe during the build process.
If you try this, bear in mind it is the physical folder name not the project name that is important. Also, you need to edit the SLN file because it contains a reference to the path of each project in the solution - so make the change there too.
I experienced the same issue before and, I've managed to find a workaround for this. I have tried cleaning all of my project’s bin\Debug folders manually and this worked. Just never rely on the clean solution/project alone because this doesn't delete all the files in your output folders. After, rebuild your projects.
Also, try save all your work and shut down Xamarin Studio and restart it.
I have had a few issues in the past that only disappeared when I restarted the IDE.
I just did an update of Android Studio and the project I was working currently on was completely erased. I think it prompt me on "terminating the main process" and I accidentally clicked ok. Is there a way to recover my project somehow? Why would the files be erased by simply updating?
In my case i didnt lose the whole project just the main folder which contains the java and the ressource file
I right click the project --> local history --> show history
--> revert selection
If you dont have the project you can create one with the same name same file names then do exactly the same thing as mentioned
Its a lesson to use github :v
I've had the same situation. I haven't been able to replicate the behaviour. My hope is the details bellow will contribute to some answer.
I was working on a project that required the addition of some JAR dependancies. The JAR dependancies, were added to the lib file and I was editing the project build.gradle script to compile them.
I was adding a dependency for jackson JSON to the build.gradle file when the issue occurred.
While typing 'compile com' android studio locked up for a moment. All the files in the project manger disappeared. Android Studio ran thru a gradle build.
Initially I though I'd inadvertently opened an new empty project. Unfortunately my files were gone.
Android Studio Never Closed or Crashed
The Folder which contained all the project files was completely empty. As if a batch deletion had occurred.
'File -> Open Recent' showed no evidence that the given project had been opened.
I had been working on this file during the previous 24 hours, opening it thru the 'File -> Open Recent' that morning to pick up where I left off the previous day.
It was Disconcerting.
I got the answer from the same problem here.
The project is not erased,just moved to another place, I also don't know why.
I just search my project's name in all my disk, then find the project under another folder.
I use the Mac OS, so the new folder is-
/Users/jokerlee/Applications/AndroidStudioProjects
I am having the Same problem even now on Android Studio 3.1.4.
The entire project folder is wiped out.
But what I do currently is immediately save the entire project folder somewhere, like Company Folder, then Copy and paste again. Hectic though.
Done this ten times now. I will test not using default project location like /users/........
I face same problem too. I solved the problem by doing following steps.
In Android Studio, open the project main directory.
File -> Open -> Folder path where your missing project existed.
Lets say if your missing project is under ../AndroidStudioPrj/MyApp, please open AndroidStudioPrj directory.
Then VCS -> Local History -> Show History
In history, you can revert to get back your code.
[
After I added some .png files into my Project Workspace drawable folder I refreshed my drawable folders in Eclipse and the newly added files showed up. But when I tried to access those resources using R.drawable.xyzimage, xyzimage although in the folder could not be resolved.
So I did a Project Clean and guess what after this clean R.java is totally gone and all my classes accessing resources using R.java is showing all sorts of error and Eclipse won't let me run the code anymore.
I have backup of my source code but I want to explore if R.java can be regenerated and how?
Thanks for all the help.
Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml. Triple check everything.
You have to build the project to be able to use the newly added resources.
Cleaning a project removes all auto-generated files. Building the project it should automatically create them. When you Clean a project, there's an option to start a build immediately after clean up.
Here's a few things you can try (did the same procedure after manually deleting the "gen" directory.
After you have deleted the gen directory, go to Project > Clean ...
You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.
Let me know if this works for you.
Here is what the problem was. I added those new png images to the project and android has rules as to what characters are allowed in the names of these images. Once I changed the uppercase letters in the image name, it was back on track again and Build Automatically generated the R.java file and all errors were gone. Eclipse console is the place where I found all the errors related to my resources.
Thanks Guys....I tried your solutions but my error was something specific which was due to my image naming convention so this is the way I fixed it.
I would agree this is usually a XML problem but moreover that it is something within your res folder that is the problem and may be highlighted with a red cross after the clean attempt.
I have just had this problem and it was because I had created my own folder called 'data' within res folder. After the clean it had a little red cross against it. I removed this folder and R built again.
Regards,
Mark
Several things you should check in your project:
Check the Problems tab in your Eclipse IDE. Are you sure that you did not introduced building problems while making changes with drawables? To check that you need to check xml source of affected layout and see if something is marked red.
In File explorer go to the directory where your Android project is. Check that you have file default.properties (.classpath, .project and AndroidManifest.xml should be there). If default.properties is missing it may be easily replaced by correct version.
Which is the Android version you are working with? If that is 1.5 or lower be sure that in the res directory you have directory named drawable, not drawable-hdpi, drawable-mdpi and drawable-ldpi. Last three are valid for version 1.6 and higher.
Right click on your project in Package explorer in Eclipse. You will get a number of options. Go to Android Tools-> Fix Project Properties so see if that helps.
I had an invalid jpg in my res/drawable folder. I removed the jpg and it worked.
I had this problem on my Mac too and I think it could be good to know for all Mac users how I managed to solve this error.
I had a .DSStore file automatically imported to my project inside the res directory and when I removed it and rebuilt the project all went well.
Everytime you clean the project and it rebuilds, it imports
import.android.R
so, delete this import and remove all errors from xml files. It will work.
This happens to me if I move my project to a new location. I have found that the answers above didn't fix my problem, but that creating a new project and importing the source did.
This may be simple but check to make sure you don't use
import android.R;
If you add an external resource file with capital letters for example
"Hello.png or WelcomeSound.mp3 etc etc" like if you add upper case letters and clean your project you'd surely loose your R.java file. So if you already lost it, either rename the file externally and then clean your project or else right click on the project Refractor->Rename and then rename your file with all letters in lower casing. Next, delete the 'gen' folder in the project explorer and now right click and "Build Project". If Build Project option is grayed out, go to Project-> Deselect "Build Automatically" option.
Regards,
Kshitij Thube
Check at the Console View If there in message Error, It will Help you to find out the source of the probleme.
I had i similar probleme and i find out that the probleme was from the pic name even if the name respect the Syntax so I change it to img1 and it worked fine.
Try editing one line of code in your project, then build the project once more.
Another thing: never try to run an application with the texteditor opened with a xml file. That will create a wierd run configuration that can only be fixed by project clean-up and sometimes can make the xml file to vanish (happened to me twice already).
All my R.* files stopped working after I did a Project->clean in Eclipse. The issue was that I backed up a XML file attached to one of my activities in the layout directory. This causes errors in every activity of my project.
After deleting the file I still had R errors in one of my Activities and it only was resolved after I tried importing different files and then deleting them. I actually made no change to the previous imports but for some reason deleting them all and re-pasting them fixed it.
I have got the same problem after lots of cleaning and building project again and again. I found that on console there is this error:
res/drawable-hdpi/Blue Blank.png: Invalid file name: must contain only [a-z0-9_.]
and this is not appearing as an error in xml. I changed the name and save the file, clean project and build. Now it's working. My suggestion check your res folder and name of files you use in it and name only [a-z0-9_.].
Delete related tag in xml, save xml, clean project, build project. Now again put that resource in xml and save!
Check your file in drawable folder ensure that all are resource file (image) remove unwanted file Like thumb.db. Remove those all files and check again
Make sure your png files have lowercase names. That is what kept throwing mine out, because I capitalized the first letter, or I used an unallowed non alpha numeric in the naming. Check that before destroying any of your code.
just check your image folder (usually created res > drawable files) and be sure dont use capital letters on .png files, every type must be in small letters then you can find again your R.java under the gen file folder
i removed 'import android.R;' then commented out the offending lines, then did a build, ok
then i removed the comment and it fixed it
I had the same problem when I cleaned my project. I got crazy to solve it, I searched and searched but solved it in my way.
First of all, delete all needless files in your /res folder. I had some notes in it, I took them to another project that I don't work on it and build the project manually. It worked! Try this I'm sure it will help.
Good developing!
Was there an XML file with the naming convention of "somthing.out.xml" generated? If so you should delete this file (an unwanted file of this name can cause major problems for your somthing.somthing.R file import).
In some versions of eclipse (I know eclipse javaEE does this for sure), running the project while viewing an XML file will create a file called filename.out.xml in your res->layout folder. You must delete this generated file if this has occurred otherwise you wont be able to get the java.R file to import.
Try Project -> check Build Automatically
If you are using 64-bit Ubuntu, try to install the 32-bit libraries (ia32-libs)
$ sudo apt-get install ia32-libs
it worked for me
This exact same thing happened to me. coincidentally I needed to update my adk that day, so i did so and after restarting eclipse it worked again. My recommendation would be to build the project and restart eclipse. It is not due to any error in your code.
I read and tried many of the above after simply doing a clean on one project. Eclipse would not build anything afterwards.
Fortunately I had last-nights backup of the workspace and my source is copied in from VS 2010.
No more cleaning!
Delete your project from workspace witout source deleting and then import it into workspace.
RightClick on your Project -> Delete /Don't select "Delete project content on disk (cannot be undone)"/ -> Ok
File -> Import -> General -> Existing Projects into Workspace -> Brouse -> /Look for your workspace(!) folder/ -> Ok -> /your cleaned project will be automatically checked/ -> Finish
I had the dreaded missing R problem yesterday with Eclipse Juno after a routine clean. StackExchange is full of suggestions and extensive googling revealed only the usual suspects (XML naming conventions problems, etc) none of which seemed to apply directly, although it is certainly possible I missed something.
The best summary comprehensive list of possible causes and fixes was here:
http://www.techrepublic.com/blog/software-engineer/a-comprehensive-troubleshooting-guide-for-androids-r-cannot-be-resolved-error/
One useful tip there was to try to create and run a simple "Hello World" in my workspace. If that does not run, the setup is corrupted. My Hello World was just as full of errors as my custom app.
The solution that worked for me (perhaps great overkill but nothing else worked) was to completely uninstall Android SDK and delete Eclipse (Juno), download Eclipse for Developers (Kepler) and reinstall Android ADT plugin and ADK and recreated my AVDs using the latest "compile with" version in options.
So far so good, although I am recreating the app from scratch. I will be more cautious about using clean from here on.
I have same problem occur just now I renamed invalid png file like *demo.1.png as demo.png * and its work.
Proven successful method, check the file (AndroidManifest.xml) and delete all comments in it, and make sure there are no errors in this file, I tried and did work with me.