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

后端 未结 9 1588
猫巷女王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 08:58

    Answering my own question:

    I created a file "build.properties" and added the line

    external.libs.dir=lib
    

    It was a lucky guess, really.

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

    put jars in ${YOUR_PROJECT}/libs directory

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

    Just for future reference: Right now there is a bug in the SDK which prevents of using jar.libs.dir: http://code.google.com/p/android/issues/detail?id=33194

    A simple solution to use jar.libs.dir again (while waiting for the bug to get fixed), is to add this target in the build.xml file:

    <target name="-pre-compile">
        <path id="project.all.jars.path">
            <path path="${toString:project.all.jars.path}"/>
            <fileset dir="${jar.libs.dir}">
                <include name="*.jar"/>
            </fileset>
        </path>
    </target>
    
    0 讨论(0)
  • 2020-11-28 09:08

    Jay K's answer was right at the time of writing, but now the SDK has changed, and here is the new way to do it:

    Add the following line to ant.properties:

    jar.libs.dir=lib
    

    Tested, works where external.libs.dir does not work.
    That changed in December 2010 and then again in October 2011.

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

    The example above dosen't quite work right. You cannot overwrite the project.all.jars.path inline. Following is a working example :

    <target name="-pre-compile">
    <!-- HACK to add the android-support-v4.jar to the classpath directly from the SDK -->
    
        <echo>ORIGINAL jars.path : ${toString:project.all.jars.path}</echo>
        <path id="project.all.jars.path.hacked">
                <path path="${toString:project.all.jars.path}"/>
                <path path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
        </path>
    
        <path id="project.all.jars.path">
                <path path="${toString:project.all.jars.path.hacked}"/>
        </path>
        <echo>HACKED jars.path : ${toString:project.all.jars.path}</echo>
    
    </target>
    
    0 讨论(0)
  • 2020-11-28 09:13

    The jar.libs.dir property is a single directory. It's not like a CLASSPATH which is a colon/semicolon separated list. The way to have multiple directories in your jar.libs.dir is to not set it directly; let it default to libs and go to libs and create the required soft links to .jar files you need.

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