Sub folder yields "Package R does not exist" - android

Using Android Studio. I have one single app Project. com.myapp.app. In this project, I have a sub folder sub - implying a new namespace: com.myapp.app.sub
In this sub folder, all references to R.string.some_string produce the following error:
package R does not exist
How can I make my sub folders aware of the auto-generated R.java file?

This does the trick: Accessing R.java from different packages
Not sure if this is the best solution though.

Related

Can I make R file path independent from packageName?

For exampel my application has com.example.app1 packageName. When importing R file it hase com.example.app1.R path. If I change packageName to com.example.app2 it will have com.example.app2.R path. So it must be changed in all files (Eclipse does it atomatically) but I don't want to do it. So can I have path to R file independent from packageName?
No, you can't do that.
R is generated at compile time by the Android development platform as a class (and a collection of inner classes) belonging to the package your.app.package.name. As of today (API 20), no user preference or setting allows changing the way it is generated.
Can I make R file path independent from packageName? NO
Eclipse will immediately generate the resource file R.java related to your package name, if it changes the imports must chage since R.java file have all the resources IDs provided to resources related to your package.

Reference Android Library project from another android library project

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

How to resolve the issue of android resources

i'm new to android, i'm getting this error. please help me in providing the solution
Thanks in advance.
R cannot be resolved to a variable When we will get this error.
R.java is an automatically generated file to hold all your resources used in project. It will be created under gen folder when you build your project. While building your project it will assign IDs to each resource you used in project and keeps them in their individual classes (drawable, id, layout, etc.) and creates a file R.java, place it in your package.
If anything wrong in your resource files (drawables or xml layouts) it won't generate R.java file.
So please check it once. I too faced same problem previously.
All the resources in Android are referenced by an 'id'. This 'id' is generated automatically in the file 'R.java', which itself is generated in automatically in 'gen' folder, once you build the project.
So, what you have to do is just 'Build your Project'
Build you project and you will get you.package.name.R.java file - and just import it.
I think I saw the problem. You are having 2 folders named 'res'.
Just delete the res folder which is empty and Clean, build the project
if your gen folder is still missing then check whether you have done installation properly and then check if you have any error on any of the xml files in your project
refer following links
R cannot be resolved - Android error
No generated R.java file in my project
No generated R.java file in my project
http://www.joshuakerr.com/2009/10/23/android-and-the-missing-gen-folder/

How to find the resource name from exception

While running an application, I got the following exception.
android.content.res.Resources$ResourcesNotFoundException: Resource ID # 0X7F03000a
The exception trace points to the method- setContentView(R.layout.main)
But main.xml is present in the application directory.
How can I identify the resource name from the resource ID?
Thanks in advance!
Usually when something like that happens, it's because the build screwed up somehow so the generated R class doesn't have it.
In Eclipse, go to Project->Clean... and select your project. It will build your application from scratch.
Also, make sure that the layout main.xml is in the res/layout folder. It must be in that folder for Eclipse to auto-generate properly.
You can find it in the R class, it is a class generated automatically. If you are using eclipse, you can find it in the "gen" folder.

r cannot be resolved on ubuntu + eclipse + android sdk

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

Categories

Resources