In my project, I need to use external library. That library consists of .class
files. I have added folder with this library to my project using properties -> Java Build Path -> Libraries -> Add class folder. I can compile project without any problem, but when I run it, I get failed resolving xy
and debugger stops on line where I create instance of class from imported files.
I guess the external library I use isnt linked to my .apk file. How can I fix this? I have tried to check this library on "Order and Export" tab assuming that, it will export the library with my application. But it didnt work.
How can I link this library to my project .apk? Do I need to somehow install this library on device first? Do I need to copy this library in application folder?
PS: I'm using Eclipse Juno, android SDK target 10.
Thank you
UPDATE
I have this library copied in libs
folder. External library path is:
my_project/libs/sk/aicit/leg/libraries*.class
I have added ./libs
folder in Libraries settings of project.
I do not have .jar
version of this library, only .class
files.
I have also souce code of this library, but I didnt want to include its classes in my project, it has its own dependencies, I wanted to just "link" it like library. Its an external library I havent written.
UPDATE 2
I have copied all the source files from library to my projects "src/" dir. I have removed Library from Java build path. I can stil compile my project, but when I run it Iget
FATAL EXCEPTION:main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{
com.example/myvideorecord/com.example.myvideorecord.Robot}: java.langNullPointerException
...
What can I do, how to debug this error? :(
steps
- Copy the library file into libs folder
- select jar file -> right click -> Build Path -> Add to Build Path
- clean the project Project-> Clean -> select your project -> ok
Android Studio
For importing a Android library into Android Studio, use the following steps:
1) (Optional) I like having my main Android project contain everything it needs to compile correctly, so I move external libraries into the libs/
directory. Generally, you only need to keep the following directories:
res
src
AndroidManifest.xml
*.iml
(This will typically be the name of the library you're importing.)
2) Go to your Project Properties.
3) Go to Modules.
4) Import a New Module (Command + N and then Import Module).
5) Navigate to the library directory you want to import.
6) Create module from existing sources.
7) Click Next three times to add the necessary files.
8) Click Finish to complete the module additional.
9) Click on your project in the module list and go to the Dependencies tab.
10) Click the +
button at the bottom and click Module Dependency....
11) Make sure your library you're importing is selected and click OK.
12) Click OK in the Project Properties window.
And you should be good to go.
Copy that library file into libs folder
if u have the source code of the library you can import it in eclipse . Right click on your project -> properties->android -> reference-> add and add the library project which u have imported. This will include only .class files of the library in ur project
来源:https://stackoverflow.com/questions/15019936/android-import-library