How can I use external JARs in an Android project?

前端 未结 12 1467
甜味超标
甜味超标 2020-11-21 11:40

I have created an Android project and added an external JAR (hessian-4.0.1.jar) to my project. I then added the JAR to the build path and checked it off in Order and Export.

12条回答
  •  甜味超标
    2020-11-21 11:45

    Copying the .jar file into the Android project's folder isn't always possible.
    Especially if it's an output of another project in your workspace, and it keeps getting updated.

    To solve this you'll have to add the jar as a linked file to your project, instead of importing it (which will copy it locally).

    In the UI choose:

    Project -> Import -> File System -> yourjar.jar -> (Options area) Advanced -> Create link in workspace.

    The link is save in the .project file:

    
        
            yourjar.jar
            1
            PARENT-5-PROJECT_LOC/bin/android_ndk10d_armeabi-v7a/yourjar.jar
        
    
    

    PARENT-5-PROJECT_LOC means relative to the project file, 5 directories up (../../../../../).

    Then add it to the libraries:
    Project -> Properties -> Java Build Path -> Libraries -> Add Jar -> yourjar.jar

    In the same window choose the Order and Export tab and mark your jar so it will be added to the apk.

提交回复
热议问题