Building an android library project with jar depen

2020-07-14 09:09发布

问题:

I have been struggling with a problem for a few days now and I am at a loss for how to fix this. I am working with an Android Library project that is being compiled using the Android tool as provided by the android sdk. Inside the project, I follow the standard structure of an an android project (where my jar files are found inside the libs directory of the project:

I am finding that when I compile the project using Ant doing:

<target name="compile-payment-lib" depends="prepare,init-profile">
    <delete file="../payment-lib/project.properties"/>
    <exec executable="${android.tool}" dir="../payment-lib" failonerror="true">
        <arg value="update"/>
        <arg value="lib-project"/>
        <arg value="-p"/>
        <arg value="${basedir}/../payment-lib"/>
        <arg value="-t"/>
        <arg value="${android.target.version}"/>
    </exec>
    <echo file="../payment-lib/project.properties" message="android.library=true" append="true"/>
    <ant dir="../payment-lib" target="release"/>
</target>

It is not including the jar files, and because of this it is losing references at runtime when we try to gather these classes and use them. I am compiling using the latest version of the android tools rev20.

Some things that I've tried to resolve these references:

  1. Unjaring the Jar files and throwing the files into the bin directory and then adding those files to our master jar file
  2. Tried compiling the jars into the classes.dex (Don't know how to make use of this file at build time)
  3. Tried modifying the class path of the project to include the libs's jar files

If anyone has any idea of what I could be doing wrong, please let me know.

One thing I should mention is that this is a particular project is used with another project that is the actual application project. This project in particular is a library project with jar dependencies.

Another thing is this is a Adobe Air application with some native extensions in android. So to complete our task, we have created an ANE with a master jar file that contains all our references using an ant task like this:

<target name="master-jar" depends="prepare">
    <delete dir="target/uber-jar" />
    <mkdir dir="target/uber-jar"/>

    <antcall target="expand-3rdparty-jars" />

    <jar destfile="${basedir}/target/master.jar">
        <fileset dir="../game/gamelobby/bin/classes" includes="**/*"/>
        <fileset dir="../payment-lib/bin/classes" includes="**/*" excludes="**/R*.class" />
        <fileset dir="../crosscell_ad_lib/bin/classes" includes="**/*" excludes="**/R*.class" />
        <fileset dir="src" includes="config/**/*"/>
        <fileset dir="${basedir}/target/uber-jar" includes="**/*"/>
    </jar>
</target>