1

in an app I'm working on I have an issue with a Java library which is here - https://github.com/kennydude/Boid-Twitter-API

When I run ant android which builds an Android package it builds fine and Eclipse can read the Jar fine.

But on my device it says that dalvik cannot locate any of the classes and eventually throws a ClassDef Exception.

I have used Jars before, so I'm wondering if it's my ant file that's broken

Joe Simpson
  • 2,481
  • 4
  • 27
  • 42

4 Answers4

1

I would open your app project in eclipse (the one that depends on the Java library that is not found at run-time) and add the jar file the Java library produced to its build path. Then execute

android -s update project -p .

in the same directory as your apps' Manifest.xml file in order do generate ant build files.

After this, you should be able to build your app using ant by doing

ant debug

or

ant release
wojciii
  • 4,095
  • 1
  • 27
  • 37
  • I don't use ant for building the app, only the library. I use Eclipse for the App, so I don't think `android update project` would work – Joe Simpson Jul 29 '12 at 20:19
  • Then adding the jar file to your projects build path should be enough. – wojciii Jul 29 '12 at 20:21
  • I use gson in one of my projects. I just add the gson jar file to the build path and the resulting apk works as expected and gson is being used at run-time. – wojciii Jul 29 '12 at 20:25
  • Oh yeah .. my jar files are in the project's "libs" directory. I symlinked them to another location which is shared by different projects. Maybe the location is wrong? But that should give you build errors and not errors at run-time. – wojciii Jul 29 '12 at 20:27
  • the location is correct, the file is in libs/twitter-android.jar – Joe Simpson Jul 29 '12 at 20:30
  • A few thoughts. Reload project. Restart eclipse. Setup a simple hello world app where you link to your jar file. If it works then compare the .project files with each other. Try to link to another jar file from your app and see if the symbols can be resolved at run-time. I have no more clues. :( – wojciii Jul 29 '12 at 20:55
1

I fixed it by ensuring Ant was compiling to 1.6 of Java which is my target in Eclipse for the application.

Joe Simpson
  • 2,481
  • 4
  • 27
  • 42
-1

Perhaps you're not placing your jar in the libs directory as opposed to lib directory? Here's a similar issue Java (Android) - class not found exception

Community
  • 1
  • 1
Alexander Kulyakhtin
  • 45,879
  • 35
  • 103
  • 155
-2

First of all to build an apk with ant for Android you have to use ant debug or ant release, i don't know what ant android does and why you are using it but this command is not part of the standard approach to ant for Android, that's for sure.

Ant is just a building tools, if a developer provide a building solution in ant, does not mean that his application is for Android.

Under Android everything that is not a native library is converted in a DEX object, which is something similar to bytecode for the Dalvik, there is no jar or other container in your app.

This question may be helpful for you Adding a library/JAR to an Eclipse Android project .

There are a lot of conceptual errors in this topic, you probably want to study the Android platform before using it.

Community
  • 1
  • 1
user827992
  • 1,705
  • 13
  • 23
  • I have studied the Android platform for well over 2 years so I know quite well what I'm doing. I know what Ant does, and how the standard Android Ant setup works. However, I am building a **standard Java** library for use in Android. – Joe Simpson Jul 29 '12 at 20:14
  • @JoeSimpson This is the answer, i can't write something different from the reality, if you are convinced of this explain why it does not works. The Dalvik machine only undestand the DEX bytecode language, you are providing a jar file and your are expecting it to work, you can't be serious. I have also followed many talks at Google I/O and i never heard a single time about the Dalvik reading from a jar, i don't know what you are studying from but it's not Android. – user827992 Jul 29 '12 at 20:19
  • @JoeSimpson I want to help, but you are keeping to go farward in the wrong direction, you have an application that does not works and you are still convinced, have a look at this http://www.youtube.com/watch?v=TkPiXRNee7A if a talk from an engineer from the Android team does not convince you i don't know what can. – user827992 Jul 29 '12 at 20:25
  • The app has switched libraries and was working before. My issue is that the jar file which **does work in Android**. It has been used everywhere, for example https://github.com/talklittle/reddit-is-fun Please help by learning that I can do what I'm after. The Android SDK can compile JAR files into DEX bytecode. Go talk to an Android engineer and they will tell you the same thing. – Joe Simpson Jul 29 '12 at 20:28
  • http://stackoverflow.com/questions/3642928/adding-a-library-jar-to-an-eclipse-android-project – user827992 Jul 29 '12 at 20:29