Reference Android Library project from another android library project - android

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

Related

Android project not generated regurlary after import from svn in ADT eclipse

Whenever I import an android project from svn the project doesn't generate properly.
So I have errors in the values files and the R.java is not generated.
Be sure about that, if any errors on your res file
Clean your project
Restart your ADT
You can update the whole project folder from outside but while doing a commit instead if committing the the whole project folder only update the following from inside the project folder:
src folder (to update the code)
res folder (to update the UIs, XMLs images, etc.)
AndroidManifest.xml if anything added to it.
libs folder if you have add any external libraries and JARs.
clean and/or refresh your project after each update.
Ask your team to follow this approach because folders like gen etc are auto-generated by the SDK.

Importing the desk-clock android project into eclipse

I copied the code onto my computer via
svn checkout http://desk-clock.googlecode.com/svn/trunk/ desk-clock-read-only
into the folder C:\Programming\desk-clock-read-only
I try to create the project via File/New/Other/Android/Android Project from Existing Source.
I select the C:\Programming\desk-clock-read-only path.
For some reason eclipse only wants to import C:\Programming\desk-clock-read-only\res.
The source files are in C:\Programming\desk-clock-read-only so they don't get imported.
There's just an empty src folder.
What do I have to do to import the project correctly?
I dont't know how the developer of this project managed it to run this but usually the java files belong inside the src folder and the manifest definitely not inside the res folder. If you change this Eclipse(or the IDE of your preference) might recognize it, but you'll maybe get some errors because just putting the java files inside the src folder shouldn't solve it. You actually need a package. Check your manifest for that.

Android: Source path not being included

In my project I have added some folders that I want included in my project for source files. But no matter what I do, the source never gets recognized. I tried refreshing, clean up, restarting but nothing works. Here is the project's source folder:
I want the folders integration/android added. This is how it is showing up in Eclipse:
And here is what my build configuration looks like:
I could be wrong, but it looks like you have added them as a folder, but not actually added the folder to your project.
The folder should show up in your src folder in the solution explorer window under your other package.
Try creating the package name in your project, then move all the src files into it.
And when its in the src folder, in its correct package, you dont need to include any extra build paths.
(You can have multiple packages in a single application)
Importing someone elses project that is over 2 years old is almost always problematic. I found the easiest solution just to create a fresh project and add the files manually from the old project.

Eclipse Import Custom Class from /src

Hey I'm having a pretty basic problem importing classes into my Eclipse based Android app. I have included the class directory into the /src directory where I figured the classes would be easily included, but Eclipse is saying it "cannot resolve the classes".
One thing I noticed is that the project folder that I included and the subfolders are just regular folder and not package folder icons. Is that a problem? If so, how do I change them to packages? This is an external git repo, so I'd rather not do anything beyond just including them in my project.
Here are some pics of how I set up the project to help:
The Activity where the error is:
Here is the package structure in the project, and the package called "android-utils" where the files I'm trying to import live:
Here is how I'm importing the files:
Btw, these classes are just some utils and I'll be improving and adding to them during the development process.
Let me know if you need any in more info to help me get these files imported the right way. Thanks!
Did you try dragging the .java files from Windows Explorer directly onto the package in Eclipse you want to put the new classes into? It should then ask to copy or link to files.
As your folder contains only java files Add them as Jar File in your Buildpath project, and your problem will be solved.
Also your jar file you can put it under the /libs folder
see this link to lean how you create jar file

Java/Android: How do you properly import a library in Eclipse?

I'm working on an Android project and i need to import an XML library called XOM. The only way i found was to right click on the project name -> Properties -> Libraries tab -> click on "Add external Jar". But that only references it from it's original path, what happens when i compile the app and move it to my phone? Will the Jar be in there?
Might be a stupid question, sorry if that's the case.
It's fine to do that but what I normally do is create a folder called liband then add Jars from there. I find that makes it easier to see what Jars I have in my application.
The main disadvantage of your original approach is that what if the path to that library externally accidentally changes? then your program will not compile. It's better to have everything in the one place to make things easier.
.apk is nothing but a collection or zipped version of a file. it contains all the resources and compiled java files.
So you need not have to worry about the inclusion of your library files. if you have set proper path to your libraries in eclipse then these will be included in your apk file.
Create a directory called "libs" in your under your root directory. You can do it by,
Right click on the project which is in the Package Explorer window in
Eclipse.
New -> Folder -> give "libs" as the Folder name
Copy your jar file and paste it to in the "libs" folder
Expand the "libs" folder
Right click on your copied jar file -> Build Path -> Add to build
path
That's it

Categories

Resources