简体   繁体   中英

Android Project Dependencies

I need help with a project dependency issue in the Android SDK.

I have the following projects: "Sync" (a Java only project) "Agonis" (an Android Library project) "Dragonis" (an Android application project)

Agonis has a project dependency on Sync, and Dragonis has a project dependency on Agonis, like so:

Dragonis->Agonis->Sync

I have correctly used the Properties->Android->Library dialog to add Agonis as an Android Library. I have exported the Sync project in the Agonis build path setup:

http://i.stack.imgur.com/GsQIR.png

In the Dragonis project, I see both Agonis and Sync in the "Android Dependencies" virtual folder:

http://i.stack.imgur.com/EhH8L.png

From here, I would expect everything to just work, but it doesn't.

I can start the app, but as soon as I instantiate a type from the Agonis project (com.mob.agonis.AgonisServer), I get a NoClassDefFoundError. If it matters, the Agonis type I am trying to instantiate extends a type that is in the Sync project (com.mob.sync.Server).

I tried cleaning all the projects, and using Android Tools->Fix Project Properties on both Agonis and Dragonis to no avail.

Am I overlooking something?

Put the jar library in the folder libs and add it to the java built path.
Right click on the file -> Build Path -> Add to Build Path
Hope it helps.

I figured it out.

The Sync Java-only library was compiling to 1.7 Java byte code. Android only supports converting Java 1.6 byte code to DEX.

Scroll to the top of the console, kids.

You can solve this through the command line tool. You could create/update the Dragonis and Agonis android projects - one as an application and other as library. See http://developer.android.com/tools/projects/projects-cmdline.html

You can easily set up the dependency from D -> A using the command line tools as shown in section called referencing a library project. At this stage, a build of D automatically triggers a build of A.

Now modify the build.xml of A - to include a dependency on : build and copy Sync.jar at the pre-compile stage (look inside build.xml to find the placeholder). The build and copy tasks can be done by starting a sub ant process using subant. See http://ant.apache.org/manual/Tasks/subant.html

At this stage all your dependency work properly on command line if you trigger ant build. Now you can also use eclipse by importing the android project Dragonis from source.

From the project properties of "Sync" set the "Java Compiler"-> "JDK Complience" to 1.6. Rebuild and enjoy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM