Create an Android Jar library for distribution

后端 未结 11 1227
眼角桃花
眼角桃花 2020-11-27 09:21

I know of Android Library projects, which allow you to create a shared-source project that can be pulled into Android Applications as needed. However, that requires that sou

相关标签:
11条回答
  • 2020-11-27 10:00

    Android doesn't provide a special kind of Android-JAR. But what you can do is adding a build.xml to your project and build the JAR with ant.

    My build.xml looks like this:

    <project name="MyAndroidLib" default="dist" basedir=".">
      <description>
    This is my Android lib
      </description>
      <!-- set global properties for this build -->
      <property name="src" location="src" />
      <property name="bin" location="bin" />
    
      <target name="jar">
        <jar destfile="MyAndroidLib.jar" basedir="bin/classes/">
          <!-- replace 'com' by what ever you are using -->
          <!-- as first part of the package name -->
          <!-- e.g. de, org, ... -->
          <!-- the ** is important to include the directory recursively -->
          <include name="com/**" />
        </jar>
      </target>
    </project>
    

    Build the JAR by running ant jar in your projects main folder.

    0 讨论(0)
  • 2020-11-27 10:00

    .jar is just a .zip file which contains .class file (you can try change extension of any .jar file to .zip then see the result). Easily, you can create any .jar library for any purpose by zipping .class file.

    0 讨论(0)
  • 2020-11-27 10:02

    just go to properties of the project of which you want to make jar.Click on Android tab. and tick in the Is library. now you can see .jar file in the bin folder.use it where you want to use.

    0 讨论(0)
  • 2020-11-27 10:03

    Steps :

    1) Open file project.properties

    2) Add value android.library=true

    3) Save file

    4) From eclipse menu for project, select build automatically then select clean

    Result : Brand new jar is created under bin.

    0 讨论(0)
  • 2020-11-27 10:05

    If you create a Android Library project without having any resources, the ADT (first noticed in r16) will create a .jar with the same name as the project in the 'bin' folder.

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