Hello, today I’d like to describe a process of integration commonly used library for emulation action bar in old Android versions - ActionBarSherlock into maven - Eclipse project. In a result we’ll get a project with:
support of Action Bar Sherlock
support of integration tests as a separate project
configured Maven build and release targets
configured Eclipse for develop and debug
This is my first post, so don’t be too critical :)
At first let’s create empty Android mvn project. In order to complete this step we’ll need:
JDK 1.6+ installed as required for Android development
Android SDK installed r17+ , preferably with all platforms
At first let’s create Android project using akquinet android-archetypes. In a result, we’ll get a sample project with configured release targets and integration tests project. Copy following code to the terminal, replacing highligted lines with your values:
Once generated, the application is ready to be built and tested. Start an Android emulator, or plug an Android dev phone, and execute:
Besides your application, this commands will also install and execute integrations tests application.
Generated project goes with test keystore that could be used for test, but not for deploying to market, run this command to get signed apk:
Latest version of the library always is available in the project download page. When it’s ready, unzip archive, copy library folder to your project root and rename it to actionbarsherlock:
As it is stated on abs usage page the only thing we need - is to add this lines to my-android-project/my-android-project/pom.xml :
Also you need to extend HelloAndroidActivity from com.actionbarsherlock.app.SherlockActivity instead of android.app.Activity and change activity theme in AndroidManifest.xml to android:theme="@style/Theme.Sherlock". Checkout git patch file for details. Try to build app. From parent project folder execute:
You’ll get following error:
If you carefully take a look at the last error, you’ll notice that a problem is with generation2 goal. It uses dex tool from Android SDK to generate class files for Dalvik. During the execution, it includes actionbarsherlock and support-v4-r7 dependencies two times (second time like transitive dependency from our application project). Check out it --output parameter values (here is a bit formatted text from maven error):
We can fix this error by adding actionbarsherlock and support-v4-r7 dependencies with scope provided to my-android-project-it/pom.xml:
Now project should build successfully.
Next step is to configurate eclipse. Rename parent folder of a project from my-android-project to my-android-project-parent.
Open Eclipse, import my-android-project-parent using existing maven project wizard. As actionbarsherlock is not part of our parent maven project you’ll also need to import it as existing maven project (don't import it as Android library project!). After this steps you should have following project structure:
Let’s fix build path problems that we have.
Go to my-android-project properties
Open Android section
Add actionbarsherlock as a library by pressing Add button
Now you should see actionbarsherlock in a library section
As we are using separate project for integration test, we should remove src/test/java folder from my-android-project and my-android-project-it build path:
Go to my-android-project (or my-android-project-it) properties
Open Java Build Path section
Under Sources tab select src/test/java folder
Press remove button
Now all errors from Eclipse markers view should disappear, and we can run our project. Select my-android-project and run it as Android application… but you’ll get:
In console view, you’ll find an error like this one:
Remember our problem with maven configuration? Here we have quite the same issue with double inclusion. In order to fix it remove libs folder with android-support-v4.jar from actionbarsherlock project.
Finally, clean all projects and run my-android-project. We’ve got working application: