Android Studio and "error: cannot find symbol class" - android-studio

I there:
I am working in the last version of Android Studio, and I have the next problem. I am generating code (.java classes), so my code is generated outside Android studio and copied into the folder of the project. When I try to run the code, it shows the following message
error: cannot find symbol class XXXXX
Where XXXXX is a class that exists (I tried with other classes and it happens the same). The class is well defined, its visible by Android Studio but it still fails.
The code is generated, so it is copied directly into the folder of the project and I think it is the problem.
What I tried to do: (according to other answers).
Rebuild the project.
Close and open Android studio.
File - Sync with file explorer.
File - Sync Project with Gradle Files.
File - Invalidate Cache Restart.
And those solutions do not work.
However, this works:
Create a class using Android studio and now I can generate the class and replace the file. Apparently, Android Studio (or Gradle) is unable to recognize a file created outside Android Studio.
What I can do?.
I need to create many classes so I can't create each file manually.
Is there are an internal database?.

Related

Android studio 3.1.2 create new project gradle sync failed

I use this Android studio import existing project all the time and everything goes well. Today ,I first create new project which support c++ ,and after every step to the final, I got the error.Picture like below:
I don't know what's wrong,because when I importing existing project ,this error haven't shown.
And the project structure panel like below:
When I check connection in "Http Proxy" ,it returns successful :
Delete the corrupt files
When Gradle files are not completely downloaded or corrupted by some other reason,we have to redownload the files. The easy way is to delete the old files in.
C:\Users\username.gradle\wrapper\dists
Then rebuild the project.
Then Android Studio will automatically download the new files from the system.

Android Studio : Unable to add a new class or any file to a project

My Android was working perfectly and was able to add a new xml,activity or any new file to my project. Until recently, it gives an error whenever I add a new class or any new file. It always says:
Unable to parse template "Class" Error message: Cannot modify a
read-only directory
'C:\Users\jay\Desktop\CurLoc\app\src\main\java\com\example\jay\curloc'.
I already tried to change the attribute of the folder where my project is located by unchecking Read-Only box in the Properties. I also restart my computer and Android Studio over and over again and refresh the project but nothing works. Please help.
After spending countless hours trying to solve the problem I uninstalled Android Studio and installed it again, this solved the problem. I think it's a bug in Android Studio

What is the extension of a Android Studio project file?

What is the Android Studio equivalent of Solution file in (.sln) file in Visual Studio ? I created a project in Android studio and closed it. Now I am not sure which file should I open to reload it into Android studio.
Use the import project function on the build.gradle file in your project root (not the folder itself!) to open the project again in Android Studio.
I think ".iml" is the extension for Android studio projects.
".project" is for Eclipse projects
Opening a saved project on another drive
There is no such single project file that needs to be opened but rather the directory where the whole project is stored.
Find the directory where you have saved your project
In Android Studio -> Files -> Open->(click on the directory name where your files/project is stored)
Except using android studio unique method(import), you can also double click .iml file to open corresponding project.
If you using Windows operating system, you could right click .iml file in file explorer, and select studio64.exe to open it, then android studio start the project!
At least in the version I have, like intellij the "android studio project files" are stored in a folder called '.idea' in the root of your workspace (though you can explicitly create one that looks up the tree and have it not be in the root).
If you add this folder to source control, do not add the file "workspace.xml" as that is the state of the window positions on your machine and should remain local, checking it in will cause lots of confusion.
If this directory is present, android studio will give the containing folder an android studio icon in it's open file browser window in the windows version. You can click on the directory with this icon in intellij (android studio) and open the project.
In Windows, Click at projectname.iml under project directory root. If window is not does not have the .iml file association with Android Studio, you need to add it.
When you select File->Open in Android Studio and navigate through folders, you will notice that folders which consist valid Android projects would have the Android Studio icon, clearly indicating that this is all you have to select.
It is unusual approach in terms of normal behavior of programs under Windows, because since very first versions of Windows it's become accustom to be able to open a program by double-clicking on the file associated with such program, but I guess developers of Android Studio decided not to do that.
It is possible that ".iml" file could be associated with Android Studio but it doesn't happen by default and it's not associated on my computer neither.
I ran into this problem, after upgrading Android Studio to 3.0 on Mac. The previous projects I had created were not displayed, in the splash screen, during startup of 3.0, so what I did was:
1. Pick the option to Open a project
2. Navigate to the location where the project was previously saved (~/AndroidStudioProjects/projectFolder)
3. Select the folder (don't double-click it)
4. Click button: Open
5. Result: this opened the project.
So there is no need to select any particular file. I suspect the filer of this problem was double-clicking the project folder and then wondering what to select next, which is what I did, initially. But it turns out that the Open button is required, in order to open the project. Otherwise, Android Studio anticipates that your intention is to open the folder.
.iml file can be used to open the project directly into Android Studio (I am referring to Android Studio 3). Just goto your project folder and then double click on yourProject.iml file.
I know its late but better late then never :-)
Visual Studio uses one solution file. Android Studio does this different. It uses a directory for this purpose, namely the directory .idea in your project. In this directory several files make up how your IDE is configured for that project. The same as in Visual Studio. Those files can be edited and changed, but you will have to know what is what in those files.
I think the answer is .duh
Please see screenshot:

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.

"generator.exe" exited with code "-1073741819"

I'am developing a android application in Visual Studio and the Xamarin c# monodroid development tools.
I have some external JAR files that i embed into my projects. Most of the project work fine but when i try to embed the JAR from Yocto (yocto android lib) and place the YoctoAPI.jar into a new android project and link it as "EmbeddedJar" the compiler fails with the exception "generator.exe" exited with code -1073741819.
This is a NULL pointer exception in the generator and searching the net i found some people who have the same problem and tells me that obfuscated code is not supported (that i understand). But how can i find the obfuscated code in the JAR file? Or is there a other problem that i'am not seeing.
If i need to post more project settings or envirioment/system parameters, please let me know
Such issues with Visual Studio can be fixed by repairing it.
You need to repair Visual Studio. Go to Control Panel -> Programs. Then select your version of Visual Studio you are using and press "Change"(or right click it and press "Change"). When the setup appears, click "Repair".
I got same error while create binding project, in my case the problem is in resource file, you need to add the jar file and resource file like,
bin - contains all jar files,
res - contains all resource files,
and add the compressed 'bin' folder in your project and build works fine.

Resources