Search code examples
javaandroidjarnoclassdeffounderroraar

ClassDefNotFoundError with local aar


I know it seems that this question was already asked, but they are slightly different, and I could not find a solution for my problem.

I have an Android app which depends on several aar libs which in turn are dependent on (pure java) jars. While developing in Android Studio, I include all aars and jars as a dependency from my companies local nexus. This works as intended.

however, for deployment we have local aar files which already include their jar dependencies inside their libs folder. Inside the deployed build.gradle we have the following entries defined to include them:

repositories {
    jcenter()
    flatDir {
        dirs '../../libs'
    }

     maven {
        url "https://maven.google.com"
    }
}

dependencies {

    compile 'com.android.support:appcompat-v7:26.1.0'
    compile ":NameOfAarFile:1.0.0@aar"
    compile ":NameOfAnotherAar:1.0.0@aar"

    compile fileTree(include: ['*.jar'], dir: 'libs')
}

If I open the project in android studio, gradle does its checks and lets me build it. It opens, but as soon as you're trying to use functionality originated in a jar which was in an aar I get the NoClassDefFoundError.

So I de-compiled the apk from outputs, run them through dex2jar and looked at the classes with jd-gui just to find out, that they are at their expected place.

Now I'm really wondering were the NoClassDefFoundError is coming from, or - even more important - how to get rid of it?

The official documentation mentions:

A library module can include a JAR library

You can develop a library module that itself includes a JAR library; however you need to manually edit the dependent app modules's build path and add a path to the JAR file.

I really want to leave the jars included inside the aar, if possible.

If necessary, I will provide more info.


Solution

  • I found out what happened. It works if you disable InstantRun in Android Studio.