1

I have the following project structure:

MyApp (an Android Application Project)
-- includes MyLibrary

MyLibrary (an Android Library Project)
--libs
----- core.jar*

The problem is that core.jar is not built into the final APK of MyApp, so i get NoClassDefFoundErrors, and my app crashes. The core.jar is set to be exported in MyLibrary, and it is displayed in MyApp's Android Private Libraries section, but it does not included in the APK. I'm using the latest Eclipse Kepler, and the latest ADT. What am i doing wrong?

supersam654
  • 3,126
  • 33
  • 34
WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
  • 1
    Have you seen http://stackoverflow.com/questions/16596969/libraries-do-not-get-added-to-apk-anymore-after-upgrade-to-adt-22? – shanet Aug 08 '13 at 17:12
  • No, but `Android Private Libraries` is checked on that tab in my project. – WonderCsabo Aug 08 '13 at 17:19
  • I read all the answers, but none of them helped. I updated to Build Tools 18, checked and rechecked the Android Private Libraries export, cleaned every project. :( – WonderCsabo Aug 08 '13 at 17:42
  • 2
    I wonder if there's a another problem here because the JAR wrapped into classes.dex in the final APK. You won't see the JAR by itself in the APK. You could try extracting the classes.dex file to ensure the proper classes are in there and in the right location. (or at least that's how it is in my library project) – shanet Aug 08 '13 at 17:56
  • I decompiled the whole APK with Virtous Ten Studio, and i do not see the classes there... Every other referenced class is there, but the ones from core.jar are not. – WonderCsabo Aug 08 '13 at 18:10
  • @shanet how did you *know* that the JAR was wrapped into classes.dex in the final APK? – n611x007 Aug 11 '14 at 13:42

2 Answers2

1

Is "MyLibrary" checked on "Order and Export" Tab under "Java Build Path" Properties options of your project?

I believe it maybe only it.

  • Hmm, `MyLibrary` is not displayed on that tab. Only `src`, `gen`, `Android Dependencies` and `Android Private Libraries`. – WonderCsabo Aug 08 '13 at 17:14
1

I found the error at last. It was a problem with core.jar. I built it with an ant script, and it seems the script was bad. This is the bad script. And this is the good script. I wonder which preference was wrong in the bad. So it was not the Android builder problem at all.


bad script:

<?xml version="1.0" encoding="utf-8" ?>
<project name="project" default="jar" basedir=".">

    <target name="compile" description="Compile source">
        <mkdir dir="bin" />
        <javac srcdir="src" includes="**" destdir="bin"/>
        <copy todir="bin">
            <fileset dir="src" />
        </copy>
    </target>

    <target name="jar" description="Package into JAR" depends="compile">
        <jar destfile="project.jar" basedir="bin" compress="true" />
    </target>
</project>

good script:

<project name="core" basedir="." default="dist" >

    <property name="dist.dir" value="dist" />
    <property name="src.dir" value="src" />
    <property name="build.dir" value="bin" />

    <target name="dist" depends="clean, package" />
    <target name="clean" >
        <delete dir="${build.dir}" />
    </target>
    <target name="init" >
        <mkdir dir="${build.dir}" />
    </target>
    <target name="compile" >
        <javac debug="off" destdir="${build.dir}" source="1.6" srcdir="${src.dir}" target="1.6" />
    </target>
    <target name="package" depends="init, compile" >
        <jar basedir="${build.dir}" destfile="${dist.dir}/core.jar" />
    </target>

</project>
n611x007
  • 8,952
  • 8
  • 59
  • 102
WonderCsabo
  • 11,947
  • 13
  • 63
  • 105