Android AAR NoClassDefFoundError

I am trying to open the original library that I created, but facing problems with the generated AAR and NoClassDefFoundError

when I try to use the library under Gradle the embedded APK. Notably, if I convert AAR to an older, unofficial and now outdated format apklib

(and use it in the APK) android-maven-plugin

, the library works without issue.

With this evidence, I can probably see an android - gradle shortage. From everyone's attempts to document the roots , including relying on local repositioning of maven including AAR, and importing AAR using Studio's module import mechanism, the error remains.

Deeper investigation indicates that not all library classes are affected by the issue noted below. In particular, there are problems with those classes that themselves rely on Google Play Services or the Android Support Library. A similar issue (probably exactly the same, in fact) was noted here back in February.

The exception I see is below;

04-21 00:02:25.863  21336-21336/com.oceanlife E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.oceanlife, PID: 21336
    java.lang.NoClassDefFoundError: com.brantapps.polaris.google.GoogleMapWrapper
            at com.brantapps.polaris.PolarisModule.provideMappable(PolarisModule.java:46)
            at com.brantapps.polaris.PolarisModule$$ModuleAdapter$ProvideMappableProvidesAdapter.get(PolarisModule$$ModuleAdapter.java:57)
            at com.brantapps.polaris.PolarisModule$$ModuleAdapter$ProvideMappableProvidesAdapter.get(PolarisModule$$ModuleAdapter.java:41)
            at com.oceanlife.fragment.addspot.AddSpotMapFragment.onCreate(AddSpotMapFragment.java:171)
            at android.support.v4.app.Fragment.performCreate(Fragment.java:1763)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
            at android.app.Activity.performStart(Activity.java:5949)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

      

The project config can be viewed in the GitHub repo here , but there are build dependencies here which I have for clarity;

dependencies {
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.google.guava:guava:18.0'
    compile 'com.squareup.dagger:dagger:1.2.1'

    googleCompile 'com.google.android.gms:play-services:7.0.0'

    kindleCompile 'org.osmdroid:osmdroid-android:4.1'
    kindleCompile 'org.osmdroid:osmbonuspack:4.4'
    kindleCompile 'org.slf4j:slf4j-android:1.7.7'

    provided 'com.squareup.dagger:dagger-compiler:1.2.+'
}

      

Any ideas / workarounds for this issue are kindly accepted.

+3


source to share


1 answer


I found that if I repeat the dependencies calling NoDefFoundError

(as described in the linked SO) in the main application, the problem goes away ...

It seems like AAR libraries are built without dependencies in Google Play and Support Library. I trust that I can build it correctly and force the dependencies to be resolved by creating the appropriate one pom.xml

, which is next to the AAR in my local maven repository.

For reference, here's my project config;

Android Studio:



--App
  -- build.gradle (repeat dependencies of Polaris)
--Polaris
  -- build.gradle (Google Play and Support dependencies)
--ApiClient
  -- build.gradle (just another module)

      

Local Maven:

--.m2
  -- com
    -- brantapps
      -- polaris-google
        -- 1.0.0
          -- polaris-google-1.0.0.aar
          -- polaris-google-1.0.0.pom (need to build one of these maybe!)

      

0


source







All Articles