Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android library: resources are merged, code is not

I'm trying to set up an Android application with an Android library project dependence in Eclipse. I've set up a project called AnTest and a library project called AnLib. I've provided a reference to AnLib in the project properties of AnTest. Now I'm trying to refer to some library code (a static public method) from AnTest. Eclipse throws "com.anlib.Hello cannot be resolved to a type".

And it's not that the reference is dangling - I can see the resources properly merged. But from within AnTest, the only class in package com.anlib is "R".

Please, what am I doing wrong? Some very basic step must be missing...

EDIT: I've added AnLib to the Java build path/Projects in AnTest project properties. Now it compiles, but running throws a NoClassDefFoundError exception...

like image 837
Seva Alekseyev Avatar asked Jun 18 '10 21:06

Seva Alekseyev


1 Answers

After carefully looking at the sample projects (TicTacToe), I've noticed a little something under classpath. It's a linked folder to the library sources. Project properties of the app, Java build path, under "Source" click "Link source", provide a path to the library\src.

There's no magic after all.

EDIT: the NDK (JNI-based, native) libraries are not picked up by default, either. Gotta establish a linked folder called "libs" to the respective libs in the library project.

EDIT2: the behavior of native libraries seems to depend on the version of ADT and/or Eclipse. Also assets are not merged, but this latter bit is actually documented.

EDIT3: under the latest Android tools, libraries are not implemented as linked sources anymore. Please disregard this answer; it was true and relevant at the time, but now it's not.

like image 92
Seva Alekseyev Avatar answered Nov 07 '22 04:11

Seva Alekseyev