Hi i have erorr "R cannot be resolved" everytime when i create android project in eclipse under ubuntu with android sdk. In windows everything ok. What's wrong?
R is a Java class created in source form by the build process. It contains definitions of locally unique numbers to refer to the assets under your project's 'res' directory.
See if you have a 'gen' folder in the route of your Eclipse project. Then look in this folder and see if you have R.java class under a package structure representing the same as the 'package' attribute in the manifest tag in your AndroidManifest.xml.
There is a common problem where the 'gen' folder gets deleted by Project->Clean, or where a project is copied from one workstation to another it seems sometimes the 'gen' folder does not get generated. You could try making a 'gen' folder of your own in your project root to see if this fixes it.
If you are referring to this file from a Java file with a package different to this you will have to explicitly 'import' it, but Eclipse should prompt you with assistance about this.
There is one useful trick, you just go to strings.xml and then press space than back space and CRTL+S this will rebuild your code and also generate everything in gen folder that is connected with strings.xml
Related
I was working on my app, editing and coding some xml and layouts when suddenly I got an error on my libs folder. It's very weird because I haven't actually modified or changed any base classes or something. Moreover, I just noticed I lost also my R.java file and all of the references are gone.
What possibly can be the problem? I tried to clean+build the project but it didn't work.
Here is a screenshot of my eclipse:
http://i.gyazo.com/959040321d1fd6d00ee0b9a90133aa9c.png
Place the jar in the root folder of your project. Then you can add it to your classpath . (you cannot place a jar and access it using android.R)
You can add the jars to your build path by right clicking on your project->properties and going to Build Path. Then you can add an external jar
After switching to my release branch the project had a missing gen file so I added the gen file from java build path.
Now the assets and the res folders are show like gray packages and not folders and I get the errors like res/values/ is missing.
How to return to the standard android project structure in eclipse?
Is there a standard way of returning to the standard Android project. I have become tired to fix project properties and I have tried to clean and restart eclipse It seams that some project metadata is saved the wrong way.
Thanks .
/gen/ folder is automatically generated during compilation. You should include that and /bin/ and also /.properties/ to .gitignore to avoid having to fix properties all the time and also minimise the amount of unnecessary data stored in your repo.
I learned that in every project we have only 1 AndroidManifest.xml file.
BUT I found two of the same file name !!
One is in the root folder, and the other is in the /bin folder...
How come, and what shell I do ?
thx !
project/bin folder is for compiled (to bytecode) source code and project resources.
Do not worry about it, your IDE is handling content of bin folder automaticly.
When all code is compilled, your IDE (I think, it is Eclipse) can build your project.
When your project builds, it creates a copy of itself for execution in the bin folder.
You can ignore everything in the bin folder as its automatically generated and it doesn't require any edit directly of you.
The only AndroidManifest.xml you have to worry about is the one in your root project directory
One is created by the developer (the one in root folder) and the other one (the one in /bin) is created by eclipse or whatever IDE you are using.
The other one is a compiled binary. This is totally fine. You don't have to do anything. Continue developing!
I have an android library project (say A) in eclipse that is trying to reference another library project (say B). Both projects have res folders, and what I see is that A is unable to reference anything in B's res folder, basically R.java can't be resolved (no strings, no layouts etc).
Am I missing something crucial? Is this even possible?
Thanks!
You could just export one of your library projects as a jar file.
Then create a new folder name "libs" (name is important) and then import that jar file into the project. As long as you've included the right files when creating the jar file, you should be able to reference those files from the second project.
Now when it comes to manipulating files in the res folder, that might get trickier. If you are trying to do any UI stuff where the resources are in the library project, then I'm not sure if this is possible.
Hopefully this helps!
Cheers!
----------------------- Update ------------------------------
I'm not sure where you are going wrong. If you do what I suggested, make sure that you add the "gen" folder when creating the jar file. Then make sure you add the right import, and voila you can reference that file.
For example: say your library file has the package com.test.Test1
then in your gen folder you should have the package com.test.Test1 with your R.java file in it.
Export this project making sure to include that gen folder.
Then in your other project make sure you include "import com.test.Test1"
now in code you can just type R.Whatever. There might be some confusion if you are including another import for R.java.
Now if you want to access the "res" folder, I would imagine you could just change the res folder into a source folder (Build Path->Use as source folder) and then export the jar making sure to add the res folder.
Hopefully this works for you.
Cheers
You should use the full namespace before the R class. For example if the name space on project B is com.projectB.* then you can reference the R from project A by referencing R as
com.projectB.R.xxxx
I am creating a app from a existing source (Gingerbread download softkeyboard) when it loads into eclipse it only loads empty folders, there isnt even a Java file other then the gen java file.
It says the manifest is missing but when I look into the Gingerbread folder outside of eclipse the manifest file is there along with a slew of other files that eclipse did not load. What could be the issue?
Also when I try to import (I've tried by root and archive) it gives an error of no projects found.
What you need to do is going into the folder that you imported your project from. Copy the files from it, including the Android Manifest file. Then go into the folder eclipse created in your workspace and paste the contents into it. This will overwrite the default folders that eclipse created. Go back into eclipse and f5 and you should see your files how up.