Including other Eclipse Projects in an Android application project
Asked Answered
T

3

7

I have a library-only Android eclipse project (no main class, only library classes) that I want to include in my main Android Application project.

I went to the Build Path and added the library project to the "Required projects on the build path" on the Projects tab, and checked it on the "Order and Export" tab.

However, when the application is run, it emits VerifyError exception, because the class from the library project didn't happen to be packaged together in the apk.

Any solution to this?

Towage answered 12/1, 2010 at 6:20 Comment(0)
P
6

Android projects don't get packaged in, unfortunately. If your library project only has classes, not resources, then you can make it a normal Java project. Java projects that an Android project depends on do get packaged in.

If the library project uses Android specific classes, then when you make it a Java project you also have to add android.jar to the build path. This will be "platforms/android-1.6/android.jar" inside your SDK directory if you have the 1.6 platform installed, for example.

Patina answered 12/1, 2010 at 8:15 Comment(1)
You are correct. If I make the library project a Java project (as opposed to Android project), the classes get packaged in. Thanks!Almire
N
3

If the library is a regular Java project, the easiest way to include it in an Android project is using a linked source folder. In the application project, go to Configure Build Path | Source | Link Source... Name the folder something like library-src and point to the src folder of the library project.

Nonu answered 4/6, 2012 at 19:26 Comment(1)
It works! I have changed the name from "src" to "sth-src" and it works.Omalley
L
1

I had a similar problem (with the VerifyError exception on loading onto a device) using Eclipse Version: 3.6.2. I had created an android Library project with some common classes for sharing, that depended on the android SDK classes. Instead of making the andrloid library project a 'normal' java project I added the library project as a library reference in the projects properties Android tab for the projects that were using the library. This resolved the missing class exception.

Laflamme answered 4/8, 2011 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.