1

I'm trying to do some simple FTP stuff in Android. After researching a little bit, I decided to go with the apache-commons-net. Here are the steps I took to get it working under Eclipse.

  1. Downloaded the package from here and unpacked it locally.
  2. In Eclipse, to add this new library, I go to (Window >) Preferences > Java > Build Path > User Libraries, click New, name it apache-commons-net, then Add JARs... to it by picking the .jar files that came in the download.
  3. For each .jar, I add in the Source attachment as described here.
  4. Once this is done, I right-click my project and choose Properties > Java Build Path > Libraries, click Add Library... > User Library > (Next >) choose apache-commons-net > Finish. The library then shows up alongside Android 2.2 in the Libraries tab.

I start programming, and code completion works fine for the classes/methods/etc. from this library. Import statements are included, etc. Everything seems to work as it should. The problem is, when I run the app, it force closes and my LogCat in Eclipse shows the following error:

Could not find class 'org.apache.commons.net.ftp.FTPClient', referenced from method <...>
...
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.net.ftp.FTPClient

It seems like I've set everything up correctly, so why is the execution complaining that it can't find the class???

Any ideas or help is greatly appreciated.

  • Ian
istrasci
  • 1,281
  • 1
  • 16
  • 38

1 Answers1

6

You need to copy the jar(s) to the libs directory in the project. The ADK picks the libraries from that folder and convert them into classes optimized for Dalvik.

Edit

There might be some more information in this question: Importing external .jar file to Android project

Community
  • 1
  • 1
Augusto
  • 26,525
  • 5
  • 52
  • 82
  • Umm, my project doesn't have a `libs` directory. Should this have been created when I generated the project??? What level should it be at? – istrasci Aug 07 '11 at 22:29
  • Create the `libs` directory at the topmost directory of the project (the same where you have the src and res directories). – Augusto Aug 08 '11 at 11:02