Combining packages from different projects into a single project in eclipse - android

As part of the Android application I am developing in eclipse, I need to combine two packages from different projects into a single project. I tried copying the files in the package of the second project under the src folder of the first folder and copied other files required for second package into the res folder of the first project.
But the auto-generated Java files i.e R.java doesn't get updated on copying. I tried right clicking on the project and clicking on Android Tools -> Fix Project Properties. But nothing changed.

I would rather add a second source directory through a linked folder.
(Especially since they now support relative path (3.5), as the following picture illustrates (3.6 only)
alt text http://img411.imageshack.us/img411/1299/dynamicpathvariables.png)
Another solution is simply to add the second project in the "Project dependencies" of the first.
alt text http://img24.imageshack.us/img24/9511/eclipsebuildpath.png

I ran into difficulties with VonC's method producing force-close noclassdeffounderror at run-time since referencing the external project doesn't make the class available run-time. Perhaps I was not doing it correctly, but I found a different solution to share:
Put both projects that you need to combine into the same workspace and open both. Set one project as a library, and reference the library in the other "main" project, as shown in:
http://developer.android.com/guide/developing/projects/projects-eclipse.html
Don't forget to declare any applications you use from the library project in the main project's manifest.

You shouldn't have to resort to importing or cross-referencing projects.
As far as I am aware, the R.java file is generated from the XML files in res.
Specifically, it is created based on the "id" in layouts and "name" in the strings.xml file. (There are probably other things that do it, but this is what I know).
Perhaps, when copying your files, your ids are not formatted with the "+" that encourages the values to be created if they do not already exist.
For example, a TextView in a layout would contain:
<TextView
android:id="#+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
The plus there is crucial to new creation of values.
It may also help to put a basic edit into an xml file, save it, then undo the edit and save again. The saving may trigger the Eclipse plug-in to regenerate the R.java file.

Related

Using android library project, with multiple src / res folders?

Sorry for what is probably a rather basic question, but I can't find the answer...
I downloaded a project from github, and I'm having trouble setting it up. I have virtually nill experience using code repositories. The project is is flagged as an android library project, and has two sets of source folders and resource folders buried in sub directories. Each src folder is dependent on its own resource folder.
You can see the project layout in the pic below.
Android gives me error that there are no "src" or "res" folders in the main directory. I tried using "build path > use as source folder" options to make android recognize them, but this leads to errors about not being able to find the resource folders.
How am I suppose to set this up?
I have used that library before. the problem you are facing is due to wrongly importing the whole repository as 1 project.
it is actually 2 separate projects:
two-way-gridview. this is the library project. you should import this subfolder on its' own.
sample. this is a sample project with examples how to use two-way-grid correctly.
you need to import both separately for it to work.

R.java file doesn't allow creation of new folder in the project

I have been trying to create a folder manually to keep all the styling xml files inside my android project using eclipse in windows 7. As soon as I create a xml file inside that new folder and save the xml file. My R.java goes missing. I understand that R.java is not taking in the manual changes to the project. I believe there is a way we can make changes to the project by manually adding folders and reflecting the changes to the R.java file accordingly.
So can anyone please help me out as to what do I have to do to allow manual changes in my project as described above?
the only way you can create a styles xml file, is inside a values folder, so you can't assemble all the styles files inside one folder, android will not recognize it, thus, not allowing what you are trying to do
here is a link to follow when creating a folder,
http://developer.android.com/guide/topics/resources/providing-resources.html
check this part within Table 1. Resource directories supported inside project res/ directory.
Styling XML files should go someone in your RES folder, typically some flavor of "values" (like just "values" or "values-hdpi", etc.)
Putting them somewhere else can cause errors, usually they just can't be used but also could cause Eclipse to not be able to build the R.java file correctly.

How to create an android library project with no resources

I want to create a library project with just java/Android classes - but no resources. Basically it will contain helpers for IO etc. I have manually deleted the resources etc - the project is here - but I wonder if this can be done out of the box - or is my way not proper
NB: I need Android classes - so creating a regular java project is not an option (?)
Edit : if there is no out of the box way is there any catch in deleting the (edit: contents of the) res/ folder and the support library ? I would appreciate a 1-2-3 procedure
You need to keep project structure, incl. having res/ foder with drawable/ etc, but these folders can be empty. There's no requirement for your library to reference any drawable.
Others suggest it's mandatory for "app icon" but your library does not need any <application> entry in manifest, so it does not need any icon. The same applies to values/ and layout/ folders. Your library project have to have these folders (as required by build process), but having no file in them (so basically keeping them empty) is perfectly fine and valid and meets your requirements.
I believe you should keep all the required folders (including res) but you can leave them empty. Here is a guide for it.
http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject
I believe you cannot delete the res folder completely since the app icon is contained in it. However you can delete the default layout if you do not need it and any other content that is required for the app to work.
If you would like to access the Android classes you will have to create an Android project.
I hope this helps.
I have created a git repository to illustrate - I created a vanilla eclipse android library project (screens) added a git ignore (bin/) and then proceeded to delete unneeded resources (all the contents of the res/ folder) along with libs/ and assets/ and edit the manifest. The changes are in this commit for reference. Cleaning the project removed R.java along.
Will be adding more (.gitattributes and eclipse settings for android) but this is for now.

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.

How to create a linked folder in Eclipse Android?

I have imported a project test1 which contains two weird linked folders. (at least for me they are weird :)
They look like this but I can't see any content, one can't open them.
Now I would like to write my own project and need to create these two folders but I do not have any idea how I do this.
When I go on the first linked folder of the imported project i see:
Path: /ImportedProject/org_taptwo_android_widget_viewflow_src
Location: _android_org_taptwo_android_widget_viewflow_7cfa4d63/src
I get many errors if I do not have these two linked folders. Can anybody help and tell me how to create these in my project?
I tried copy paste, but that did not work
I also tried to link source in the Java Build Path -> Source but that links the source folder and shows all the files and is somehow different from what I need.
Many thanks!
You can copy paste "Linked Folders".
(I can't figure out how to create them, so I just copied an existing one)

Categories

Resources