tags:

views:

163

answers:

2

Hi all,

I am creating a library for Android that others can include in their own project. So far I have been working on it as a normal Java project with JDK 1.6 setup as system library. This works just fine in Eclipse when I add the android.jar.

The issue comes when I try to my build script. I am running Gradle and doing a normal compile and test build cycle. My thoughts were that it does not matter if I compile it with a normal JDK, since this is not a standalone application. The benefits by creating a normal Java project is that Gradle does support this much better. My project also does not contain any UI at all. However, the problem is that of course android.jar and the JDK contains lots of the same classes and I think that this is what messes up my build script. Everything crashes when running the tests (the tests are in the same project under src/test/java).

My question is, how should I create this project that is meant to be included in Android projects as a third party library? Should I create it as an Android project in Eclipse even though I am only creating a library that does not use any of the UI features? Also, should the tests be in a separate project?

Thanks for all responses!

+1  A: 

Hi,

I will start with the simple question, the one regarding the test project. My experience is that is is better to have a separate test project. I have done this with success in many Java ME project, where the problems are similar. The test project only need to import the source code, not the libraries. Then there should be no problems with duplicate classes.

The other question is a little more difficult. My intuition tells me that the core project should be an Android project.

Johan Karlsson
+1  A: 

Have you looked at the Android plugin for Gradle? It incorporates the ProGuard tool to package only necessary classes into your Android APK file, so might address your scenario. Have a look here: http://wiki.github.com/jvoegele/gradle-android-plugin/

Jason Voegele
I have looked at the plugin :)- Doesn't proguard also obfuscate the classes as well?- My experience with the plugin was ok. I had some problems with it not working all the time and decided in the end to not use it yet. The reason was that sometimes it seemed like it did not find the debug key to sign the test package (used the androidInstall task and it just started to hang). Also it really needs an eclipse task to generate the project files. Its on the right way though, so keep up the good work!
Jarle Hansen