1

I have a .aar file which I added to the libs folder and inside gradle I have

compile(name:'file-name', ext:'aar')

It compiles fine, but when I run it I get:

System.err: java.lang.NoClassDefFoundError: com.app.foo.MUtil$3

Now this MUtil class is used inside the API method of the .aar library I use inside my app. I could see the MUtil class in the exploded-aar folder and I can even go to that class by ctrl+click on its usage. But still NoClassDefFoundError. Why?

Gradle file

apply plugin: 'com.android.application'
apply plugin: 'maven'
apply plugin: 'com.neenbedankt.android-apt'

repositories {
    mavenCentral()
    maven { url 'https://clojars.org/repo/' }
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }

    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.xxx.xxx"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    productFlavors {
    }

    lintOptions {
        abortOnError false
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:23.0.+'
    compile 'com.android.support:recyclerview-v7:23.0.+'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile('xx.xxx.xxxx:xx-xxx:0.1.2@aar') {
        transitive = true
    }
}

task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
    gradleVersion = '2.5'
}
Housefly
  • 4,324
  • 11
  • 43
  • 70
  • this is probably happening due to not defining the correct proguard rules – thepoosh Jan 14 '16 at 09:40
  • @thepoosh But I don't think Proguard works for debug more over I have `minifyEnabled false` even for release. – Housefly Jan 14 '16 at 09:43
  • Possible duplicate of [Using .aar NoClassDefFoundError But Class Exists and is Dexed](http://stackoverflow.com/questions/29857141/using-aar-noclassdeffounderror-but-class-exists-and-is-dexed) – Jehy Jun 16 '16 at 17:49

1 Answers1

1
System.err: java.lang.NoClassDefFoundError: com.app.foo.MUtil$3

NoClassDefFoundError

is thrown when the definition of class in not available during runtime .

Finally

As per Javadoc NoClassDefFoundError can be thrown during linking or loading of class file. It's denoted by java.lang.NoClassDefFoundError and comes when that particular class is present during compile time but some how not available during runtime.

You can share your build.gradle . Most common error for aar file .

Clean-Rebuild-Restart-Sync & Try again .

Edit

  buildToolsVersion "23.0.1"
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • `Verify that all required Java classes are included in the application’s classpath` How? I added the gradle code – Housefly Jan 14 '16 at 09:27
  • 1
    @Housefly I had this problem when I included a library but it needed some other packages (e.g. it required the `gson` library). I did not know that as it was not written in the docs, but I asked the developers and they told me – Nikola Jan 14 '16 at 09:30
  • @Housefly set up looks like perfect . Can you provide `xx.xxx.xxxx:xx-xxx` ?? Its secret ? – IntelliJ Amiya Jan 14 '16 at 09:34
  • 1
    @IntelliJAmiya Yes, the API is just provided for us and still in alpha stage. – Housefly Jan 14 '16 at 09:39
  • 1
    @Nikola Looks like that is the problem. I just looked at the MUtil class imports are there are things which are missing. So I added them as well to my gradle. But ideally what all dependencies it has, I have to add them to my gradle? – Housefly Jan 14 '16 at 09:40
  • @Housefly You can add this . – IntelliJ Amiya Jan 14 '16 at 09:43