Import Android AAR library - no class definition

I am using Android Studio. I am writing an Android library called a detector. It works great in the project from which it was created.

compile project(':detector')

I want to import an AAR file that it creates in another project. I do like this:

File > New > New Module > Import .JAR/.AAR Package

Then I add the same line to the new app build.gradle app:

compile project(':detector')

After cleaning and building, I launched the application and received this error:

11-18 06:32:14.151 21283-21283/testing.com.test D/ResourcesManager: For user 0 new overlays fetched Null
11-18 06:32:14.161 21283-21283/testing.com.test W/System: ClassLoader referenced unknown path: /data/app/testing.com.test-1/lib/arm
11-18 06:32:15.131 21283-21283/testing.com.test W/System: ClassLoader referenced unknown path: /data/app/testing.com.test-1/lib/arm
11-18 06:32:15.131 21283-21283/testing.com.test D/ContextRelationManager: ContextRelationManager() : FEATURE_ENABLED=true
11-18 06:32:15.131 21283-21283/testing.com.test D/RelationGraph: garbageCollect()
11-18 06:32:15.301 21283-21283/testing.com.test D/RelationGraph: garbageCollect()
11-18 06:32:15.501 21283-21283/testing.com.test W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.621 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test I/art: Rejecting re-init on previously-failed class java.lang.Class<detector.Manager>
11-18 06:32:15.631 21283-21283/testing.com.test D/AndroidRuntime: Shutting down VM
11-18 06:32:15.631 21283-21283/testing.com.test E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: testing.com.test, PID: 21283
                                                                         java.lang.NoClassDefFoundError: detector.Manager
                                                                             at detector.Detector.<clinit>(Detector.java:39)
                                                                             at testing.com.test.MainActivity.onCreate(MainActivity.java:17)
                                                                             at android.app.Activity.performCreate(Activity.java:6904)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
                                                                             at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:148)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:7325)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I will unzip the AAR and decompile the Classes.jar file to find the Manager file:

Manager.class
Manager$3.class
Manager$2.class
Manager$1.class

Here are the build.gradle libraries

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName '1'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ('org.altbeacon:android-beacon-library:2.8.1')
    compile ('com.google.android.gms:play-services-ads:9.6.1')
    compile 'com.android.support:appcompat-v7:23.4.0'
}

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        flatDir {
            dirs 'libs'
        }
    }
}

In addition, I can deploy the library to jCenter and can successfully launch the library in other projects when linking to the jCenter installation. It is simply a direct import of AAR that causes this problem.

Please report the creation of the AAR Android library and import it into another Android project.

====== ====== UPDATE

- @bwt, , build.gradle, AAR. , ( google-play altbeacon) AAR? AAR .

+4
4

, , ( ), , , aar ?

  • aar , (, aarlibs )

  • ( build.gradle):

    repositories{
        flatDir{
            dirs 'aarlibs'
        }
    }
    
    android {
    ...
    
  • ( build.gradle):

    dependencies {
        compile(name:'aar_file_name', ext:'aar')
    ...
    
+2

, 2 :

  • AAR - , aar.
  • - , aar (1).

(2) aar (1). : " ", "+", , import jar/aar , 1.

, gradle :

configurations.maybeCreate("default")
artifacts.add("default", file('name_of_you_aar_file.aar'))

, , build.gradle, : compile project(':name_of_your_module')

, .

+1

aar pom, , .

, aar, .

maven ( maven).

+1
  • .AAR sdk.
  • . Android Studio, File โ†’ New โ†’ New Module. Import.JAR/.AAR Package. .AAR .
  • File > Project Structure > Modules ( ) > YOUR APP MODULE NAME > ( ) โ†’ '+' โ†’ .

, Android Studio .gradle. , .AAR , build.gradle .

: https://developers.google.com/vr/android/get-started

+1

Source: https://habr.com/ru/post/1660210/


All Articles