I have an Android application under development which makes use of a separate library project of my own. These two projects are stored in separate Git repositories. The application project references the library project by means of the .gitmodules file.
I'm now trying to work on both of these projects together (the application and the library) on a new machine. I cloned the application project, which resulted also in the library project being automatically cloned into my ~/git/ directory as well. So far so good.
I notice also that in Eclipse Package Explorer, the library project root has a commit hash within brackets (e.g. [MyLibraryName 0123ABC]). This presumably means that the library clone is from a certain commit point, and I understand that I could update this (i.e pull in the latest commits for this library) using git submodule foreach git pull.
Question is, what is the best way for me to continue separately developing the library project now? I tried to modify a file and stage it, but when using Team->commit, the dialogue didn't list the modified file. I assume this might be something to do with it being a submodule, pointing at a particular commit.
Should I clone my library project again, completely separately into a different subdirectory, and import as a separate project into Eclipse in order for me to do work on that library?
Having read various other SO questions, it seems apparent that there's no elegant solution for this. The steps I eventually took to solve this are:
Assuming not done so already, clone the application repository that makes use of submodules. Import all projects into Eclipse workspace, including the submodule repository (or repositories). Note that the submodule repository is a repository within the main application repository, and it's not on a particular branch; it's a reference to a particular commit (detached head).
In the Package Explorer, rename the submodule project that was imported. I gave it a name that relates to the application repo it's inside of. For instance, for an application project called ABCD, rename it from SomeLibrary to SomeLibrary_ABCD.
Next, clone the library separately from its own Git repository. Now, the point of renaming the submodule project is that it's now possible to import the Eclipse project from the standalone clone of the library repository, without Eclipse giving the "Some or all projects can not be imported because they already exist in the workspace" error.
Having done this, we have SomeLibrary_ABCD project which is not on a branch but points to a particular commit, and is a submodule of project ABCD. That submodule is updated using git submodule foreach git pull. Then, we have project SomeLibrary, which is on a branch (e.g. master).
My planned workflow is to locally switch the application project to point at my 'standalone' project of the library instead of the submodule version when I want to do development on the library. I then commit changes to SomeLibrary.
Any better suggestions than this (or corrections to anything I've stated) would be appreciated - but for now this is my own answer to the problem.
I have just set-up my local jenkins installation on my mac...
Now i have tried to create an ant built which builds my app as soon as i check-in a new change. The ant script is working great as long as i only use it in the project...
cd into the folder
ant release
It is able to find all library projects i'Ve included (ActionBarSherlock, ViewPagerIndicator, NineOldAndroids, HoloEveryWhere, PocketChange)
As soon as i put this on my jenkins installation everything breaks.
My main folder-organisation is like this:
Projects/Project
Projects/ProjectLibrarys/Library
Eclipse referes to those libraries like this: android.library.reference.2=../Project Librarys/ActionBarSherlock/library
I can't use absolute links (because i think they will fix the issue) but eclipse or ant doesn't like them.
I have really no idea how to fix it?
Will i have to edit the build.xml (i've added it into the folder ext/commonbuild/commonbuild.xml so i have the same android build file for all my projects)
If you need more code let me know.
Thanks in advance...
Ok i was able to solve my issue by adding a customproject.properties file with a seperate link for the build.
There is still one issue. It seems that ant doesn't use the customproject.properties for my library project i've added. This library project includes another library project and as soon as i build it has a wrong relative url.
Does someone know how to use the customproject.properties even for the project libraries?
As bluszcz mentioned, I checked out two modules and i was able to build my apk via Jenkins without having two project.properties or customproject.properties file.
On Jenkins Configure Screen, Under Source Code Management - Subversion Modules,
Give the url for your android project (say, SampleAndroidProject)
https://goxxx.com/svn/repository/projects/trunk/SampleAndroidProject
Provide local module directory as 'SampleAndroidProject'
Provide the svn url for your library project (say, google-play-services_lib)
https://goxxx.com/svn/repository/projects/trunk/google-play-services_lib
Provide local module directory as 'google-play-services_lib'
Save and build again.
I finished a "base app" for all my next apps in eclipse, with admob, contact us...
Can i sort of import this project in a new app and work from there? Or just copy and paste everything and just change the name? How? Like just start a new app with every thing like that app and the work it out from there?
thanks
You can turn your base app into a Library project (see http://www.vogella.com/blog/2011/03/03/android-library-projects/) and your other apps will include this library.
One gotcha with this is that the AndroidManifest.xml from your library is ignored, so you may need to manually copy activities, services, etc. from your library manifest to the real manifest.
I would put my "base app" project in a code repository (git in my case), and then just clone it, change the output name, libs etc in any build scripts. Check that into a new repository and keep working from there.
If you don't use git/svn/whatever just copy your source files and create a new project in eclipse, it's probably easier and less error prone than copying the project files as well and trying to remember all the places that refer to your old project.
Might be a little off-topic but what I usually do is I have pure source (and some build scripts) in a code repository and then outside that (in my eclipse workspace) I create the eclipse project and link the source files into my project. So if I trigger builds with eclipse I get the build output in my project directory while keeping my source directory clean.
As I was writing up this question I managed to solve it so repeat it here for the benefit of others. Here is the initial problem:
I have created a very simple library project which I want to reference in another project. I have done this previously with no problems so not really sure why it is not working this time. I have:
Flagged the library project via project properties. The default.properties file has this set : android.library=true
In my other project added reference to my library project via project properties. The default.properties file has the reference added as expected ie android.library.reference.1=K:/android_test_ws/applicationRegistrar
The green tick against the referenced library project starts off green and then changes to a red cross.
This implies that there must be something wrong / missing from the library project but I don't know what. My library project on this occasion is MUCH simpler than the previous one I created.
OK Here is the solution which I found when I was looking for the default.properies file of the referencing project (not the library) in my file system. Although the referencing project was in the same eclipse workspace as the library project, the actual files were somewhere else in the file system ie they were'nt in the same parent folder of the library project. As soon as I placed the referencing project in the same physical folder as the library project it all went fine.
I guess that this must be something to do with android using ant underneath the covers.
Edit: The project name needs match the folder name on the file system. What you are seeing in the Project Properties->Android->Library Reference is a relative file system path.
Make Sure both the projects are present in same work space.
To Do it, while importing the projects make sure "copy project into work space" check box is checked.
the same problem will occur if your library project is in different partition from your current workspace. I have the same problem just now. My git source is in C: and I just move my workspace to D: and everything start to collapse.
Simplest way to get the library paths paths correct is to use the GUI from Eclipse to add the library as shown in the following screenshot and let Eclipse take care of putting the correct relative paths in project.properties. Its a common setup to have your library projects hosted at directories vastly different than your main projects that uses the library. This method will work if the "libary project" and the project using it are in the same eclipse "workspace" (they "need not" be in same parent folder):
Please ensure that the library project is marked as "Is Library" - right click on the library project - properties - Android - mark the "Is Library" checkbox - in project.properties of the library project you should have a new entry:"android.library=true. Now add it into the project you want as described in the post below.(the post with image integrated - from Nilesh Pawar).
This bug is referenced several times here 27199, 35786, 36460 & 38052
Maybe by voting for them, it will be fixed one day...
Yet another observation on the same issue.
For me the two projects where on the same parent folder, and were both local inside the workspace. Even then the issue was still happening.
The I edited the "project.properties" file and put the absolute path(with forward slashes '/' for seperator) of the library project. Saved and closed it. Then went to the project properties dialog, removed the library(which was still showing the cross icon but with abs path) and added it back as usual.
Surprisingly the issue is resolved, and the project compiles and runs.
This is really strange and must be a bug with the ADT.
I am using ADT version 20.0.2
when developer referencing the facebook or any other library project then first of all clean the project from eclipse->project->clean project.
that want allow the error of red cross in referencing screen.
For me, I just restart the eclipse and the added library works fine.
I mean first time it showing red marks after adding the library project.
Though eclipse main project and library project are in same workspace folder and no resources files are in outside of the project folder.
So, you can try with to restart your eclipse. Happy coding....
Workaround for me was to
Create a new workspace
Import Library Project in that workspace
Import The desired project in that workspace
Having both project and library project the same target Android OS version
Reference library project in my project
solved my problem
i had the same problem there when i try to change my workspace so this my solution:
import and copy all project data including library project into workspace
delete the old project reference by Right-click on the project-->Properties-->Android-->Library, and select corrupted library(so that waht i call it) and choose Remove
clean project first (to refresh ur project properties)
go to library project Properties-->Android-->Library and check the is library if it does'nt click Apply then OK
if the library project is library is already checked, first Unchecked it then Clean the library project after that do the Step 4 again
go to project that u want the library are in then Right-click on the project-->Properties-->Android-->Library, Add then choose the library project (it should be there) and click Apply then OK
if still doesn't appear clean the project once more time and that should do
Just restart your eclipse. It's solve my problem
When you have a look at the reference-path before and after, it comes from i.e. "C:/workspace/mylib" and goes to "../../mylib" when copied to the correct location, quite interesting.
FYI,
What worked for me was to delete the 'library' projects (the actual projects) from my workspace (without deleting the files), and then re-importing them using the wizard (import existing android project from source code).
Thanks for posting the question.
I had exactly the same problem while integrating Facebook with my Android application. I fixed the issue by moving my development project to the same Windows drive in which library project was located. Somehow Eclipse is unable to read the library project's location properly from default.properties file if it is in a different drive.
Similar to Sufi Khan's post I also solved this issue with a reboot. My case differed in that when I first accessed Properties->Android and added the library I got a lovely green checkmark. When I closed the dialog Eclipse was still showing class-not-found type errors. When I checked the properties again I saw the red X. But Mr. Kahn's solution (delete the bad lib, restart Eclipse, add the lib again) worked fine.
I'm using the 0702 version of the ADT bundle (starts with "cluster", rhymes with "duck").
I followed the accepted answer but also had to make sure my "project.properties" file was readable.
If the file is readonly (checked into source control) eclipse will not edit it. Adding the library reference will succeed, but the change won't be persisted after hitting OK.
If closing the preferences window and reopening in again removes the library you just added, this may be your solution.
In case your library project still doesn't show up try adding library flag in your library project properties
Add android.library=true
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library=true
I'm developing an application that is supposed to run on both Android as well as regular Java SE.
I have an eclipse project called foobar-core which contains code that is used both by the Android and the SE version. I have another project called foobar-android, which contains all android-specific code.
I need to reference some of the foobar-core code in the foobar-android project, so I added foobar-core to foobar-android in Settings -> Java Build path -> Projects -> Required projects on the build path. This works fine, as I can use code from foobare-core in foobar-android now.
Here's the problem: Both foobar-core and foobar-android are independent git repositories, which means they both have a .git subdirectory. Now I get a lot of warnings on the "Console" tab whenever I compile foobar-android. They look like this:
/foobar-core/src/.git/HEAD conflicts with another file already put at .git/HEAD
/foobar-core/src/.git/config conflicts with another file already put at .git/config
/foobar-core/src/.git/description conflicts with another file already put at > .git/description
/foobar-core/src/.git/hooks/applypatch-msg.sample conflicts with another file already > put at .git/hooks/applypatch-msg.sample
How can I tell Eclipse to ignore the .git files when importing sources from the foobar-core project?
Even if you just have a single git repo, it is good to ignore the .git directory because other Eclipse will waste a lot of time looking at the files in it even though it never needs to do anything with them. In particular, when you do a project wide search, Eclipse will search through the all the files in .git directory, which takes a long time and ends up showing you lots of duplicates (or almost duplicates, older versions of the same file with the same search term found).
I think the Eclipse git extensions probably take care of this but if you don't want to install yet another extension, the best way I have found it to tell Eclipse that all .git directories are "Derived", which seems to make Eclipse somewhat ignore the contained files.
You do this by switching from the Package Explorer view to the Navigator view, where you should see the .git folder. Right-click on the .git folder, selecting properties, selecting Resource from the settings selector, and then checking the "Derived" box.
I would setup a .gitignore file that simply ignored the entire foobar-code project.