How to add external jar libraries to an android project from the command line

后端 未结 9 1589
猫巷女王i
猫巷女王i 2020-11-28 08:23

I\'m trying to build an Android project that has some dependencies. The jar files are in the lib/ directory. I can build the project by adding those jar file to my classpa

相关标签:
9条回答
  • 2020-11-28 09:18

    At compiling do this:

    javac -encoding ascii -target 1.5 -d bin/classes \
    -bootclasspath $SDKDIR/android.jar src/some/project/* -classpath=libs/*.jar
    

    And, when you are generating the bytecode for Dalvik:

    dx --dex --output=bin/classes.dex bin/classes libs/*.jar
    

    Also, when you are packaging the APK file:

    apkbuilder bin/something.apk -z bin/projectname.ap_ \
    -f bin/classes.dex -rf src -rj libs
    

    I'm assuming you are using Linux... on Windows will be almost the same.

    0 讨论(0)
  • 2020-11-28 09:22

    If you store your libraries in ${basedir}/libs the ant script will be able to find them.

    I looked at the current ant script ( ${sdk.dir}/tools/ant/build.xml ) and it defines jar.libs.dir to "libs".

    FYI, the ant script is well documentated so it's easily to trace through.

    If you move libs around be sure to edit your .classpath files to prevent eclipse users from suffering needlessly.

    0 讨论(0)
  • 2020-11-28 09:24
    external.libs.dir=lib
    

    after 2 hours of searching for this answer, this worked for me. The jar file in my libs directory finally compiles AND is bundled with the APK.

    0 讨论(0)
提交回复
热议问题