1

My app uses ActionBarSherlock, and everything has been working okay (after a LOT of hassle with Dalvik error 1 and such). Now I want to use a class from the Android support v4 library, but I can't find it to import. It works if I set the v4 library (under ABS' properties) as exported, but then I get the Dalvik error 1 (already added) error.

How can I use both of these libraries?

Steven Schoen
  • 4,366
  • 5
  • 34
  • 65

3 Answers3

4

If you are still experiencing problems with ABS, this might be helpful:

  • Creating a new project from scratch worked fine with ABS & support lib but my existing projects would not work after upgrading ADT, no matter what (ClassNotFoundException for main Activity)
  • I added the newest version of the support library to the ABS library project and the referencing projects but the exception still occurred
  • Finally I compared all configuration files of the working new project and my existing projects and found the following difference:

Existing projects:

<classpath>
  <classpathentry kind="src" path="src"/><classpathentry kind="src" path="gen"/>
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>  
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
  <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
  <classpathentry kind="output" path="bin/classes"/>
</classpath>

Newly created (working) project:

<classpath>
  <classpathentry kind="src" path="src"/><classpathentry kind="src" path="gen"/>
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
  <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
  <classpathentry kind="output" path="bin/classes"/>
</classpath>

Note that the attribute exported is set to true on different nodes in the XML files. Adjusting the XML file in my existing project fixed the problem for me.

Hope this helps others not waste as much time with it as I did :)

Edit: code formatting

wkarl
  • 781
  • 1
  • 8
  • 19
2

Since ActionBarSherlock itself depends on the Android Support package, merely adding ActionBarSherlock as a library project to your main project will give you access to the Android Support package automatically, without any modifications. You will see android-support-v4.jar in your Android Dependencies in the Package Explorer.

For example, this sample project references this copy of ActionBarSherlock as a library project, and it uses android.support.v4.app.NotificationCompat without issue.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That's my issue then. I don't see the support .jar in Android Dependencies. – Steven Schoen May 26 '12 at 13:55
  • @D_Steve595: Make sure you are on the latest version of the Android SDK tools and the ADT plugin, in case you are tripping over a bug that was fixed in the current edition. Make sure that your main project has a line in `project.properties` like `android.library.reference.1=../../external/ActionBarSherlock` (replacing the path shown there with the relative path to your copy of ActionBarSherlock. – CommonsWare May 26 '12 at 13:59
  • It has: android.library.reference.2=../ActionBarSherlock Library which I'm guessing is what I need. Still not working. – Steven Schoen May 26 '12 at 14:13
  • @D_Steve595: I have no idea what to tell you. Presumably, somewhere in your struggles, you smacked something that didn't like to be smacked... :-) – CommonsWare May 26 '12 at 14:18
  • Probably :( I guess I'll just recreate the projects and copy only the source files. Is there a step-by-step I can follow so I know I'm doing exactly the right thing? – Steven Schoen May 26 '12 at 14:26
0

Found out it was my old version of ViewPagerIndicator that was causing the issue. Updating to the May version fixed it, but I had to make some small changes in my Adapter.

Steven Schoen
  • 4,366
  • 5
  • 34
  • 65