Reputation: 26525
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.
Upvotes: 5
Views: 7566
Reputation: 661
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.
Upvotes: 1
Reputation: 1325996
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
Upvotes: 4
Reputation: 4258
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.
Upvotes: -1