Using .aar NoClassDefFoundError But the class exists and is in Dexed

I have several projects that I create to create .aar. Then I import this .aar into Android Studio under / libs. The build.gradle file for this dependency is as follows:

repositories{ flatDir{ dirs 'libs' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.google.android.gms:play-services:7.0.0' compile 'com.android.support:multidex:+' compile(name: 'customApi-debug', ext:'aar') } 

Since the library is quite large, I set multiDexEnabled = true. Android Studio finds the library and autocomplete work. Building works fine too, but running the application gives the following error:

 java.lang.NoClassDefFoundError: com.companyx.android.api.ui.vision.metaio.MetaIoView at com.companyx.android.api.ui.vision.metaio.MetaIoView$$InjectAdapter.<init>(MetaIoView$$InjectAdapter.java:29) 

I uncompressed and disassembled the .aar and dex files, respectively, and checked that the classes he complains about do exist. I tried existing approaches to solving this problem, but none of them worked.

Has anyone else experienced this? Thanks in advance.

+7
android android-studio android-gradle dex aar
source share
2 answers

I ran into the same problem. The fix is, firstly, deploying the AAR file on the local maven (I used the plugin at https://github.com/dcendents/android-maven-gradle-plugin ). Then I referenced the local maven as described in fooobar.com/questions/825034 / .... And in the end, I declared dependencies with a transitive variant, for example:

 dependencies { compile('com.myapp.awesomelib:awesomelib: 0.0.1@aar ') { transitive = true } } 

The error will disappear.

+4
source share

Just fyi, you can use a simpler syntax that is valid too.

  compile 'com.myapp.awesomelib:awesomelib:0.0.1' 

Remember to omit @aar at the end of the library name

0
source share

All Articles