11

I am creating AAR file using another aar and jar file dependency. I have successfully created the .aar release file.

Then, I have imported my new AAR file into the sample Project. the project is running fine. when going to access that aar and jar classes mean, It's showing NoClassDefFound error.

Note: First I want to know, as of now AAR inside another AAR is possible or not. can anyone help me to come out from this new things issue?

I referred to this link also Create an AAR with multiple AARs/JARs. It's saying transitive= true. But, not understand, where to use that flag. In third party using Application or while creating AAR inside AAR project dependencies.

Thanks Advance.

My Mini Project Gradle File:

Mini Project, which is only converting into .AAR file. then, this file only going to use another NewProject

Mini Project Build.gradle file

/*
This would be enabled for development purpose and to debug and check the same
*/

apply plugin: 'com.android.application'

/*
This would be enabled for exporting as aar file
apply plugin: 'com.android.library'
*/

//apply plugin: 'com.android.library'

android {

    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }
    defaultConfig {

        /*
        This application id would be used for development purpose and to debug and check the same.
        This would be commented when exporting as library
        */
        applicationId 'com.pss.pssplayer'
        minSdkVersion 18
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }

    aaptOptions {
        cruncherEnabled = false
    }

    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
 'proguard-rules.pro'

        }
    }

    productFlavors {
    }
}

dependencies {

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

    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.1.1'

    compile 'com.android.support:support-v4:23.1.1'

    compile files('libs/ksoap2-android-assembly-3.2.0-jar-with-dependencies.jar')

    compile files('libs/secure.jar')

    compile(project(':getSubProject')) {

        transitive = true

    }// this getSubProject also contains one classes jar
}
Community
  • 1
  • 1
harikrishnan
  • 1,985
  • 4
  • 32
  • 63

2 Answers2

8

When you refer to your aar and jar in your dependencies, then you can compile your new aar with references to the first.

But they are not embedded in your aar. Instead, the application using the "big aar" also need a dependency over the two first.

For that, you can deploy all your aar in a repository like maven in telling maven that the "big aar" depends on the two first. (-> pom.xml)

In you application build.gradle file, you can add the dependency only on the "big aar" with transitive=true to tell the system to look at the dependencies of the dependency.

Edit :

You can at least merge jars. look at these answers :

gradle - how do I build a jar with a lib dir with other jars in it?

Can Gradle jar multiple projects into one jar?

Merging aar is more difficult because you have to merge all resources, manifests and so on...

Community
  • 1
  • 1
Bipi
  • 3,429
  • 1
  • 20
  • 22
  • let me try this option yar. i will publish my base aar with jar to maven central repository and refer the MiniProject dependencies. then, i will convert as .AAR and will be use and check with New Project. – harikrishnan Nov 10 '16 at 10:07
  • Hi Bipi, I have vendor AAR and Jar file. anyway, they are not allowing to publish the jcenter. as per rule, they will give only like .aar and .jar only. – harikrishnan Nov 14 '16 at 06:34
  • Merge aar with other aar and jar are not possible unless using tools like android-fat-aar that have limitations. Could you think about setting up a local maven repo that will handle dependency problems for you ? We are using artifactory in our company. – Bipi Nov 14 '16 at 16:45
  • am ready to use Maven repo url.but, client will not give the jar and .aar to maven lib url like. they are giving this .AAR and Jar format only currently. for this reason only, am trying this way, – harikrishnan Nov 15 '16 at 07:44
  • You can still package client's jars and aar to your maven repository manualy – Bipi Nov 15 '16 at 09:53
  • 2
    Its possible to include an aar inside other aar without maven? – Pablo Cegarra Feb 12 '19 at 18:21
  • @PabloCegarra I don't think so. You have to use a repo like maven or you have to merge aar files into one. – Bipi Feb 13 '19 at 10:18
0

Use android-fat-aar gradle plugin, it is super usefull!

Nicola De Fiorenze
  • 1,958
  • 1
  • 17
  • 27
  • The above mentioned fat-aar method only working to Create AAR Library in Android Native using Android Studio Successfully. – harikrishnan Sep 26 '17 at 10:33
  • Hi Nicole, Android aar build is working fine in studio 2.2.2 itself. if we upgrade to android studio 3.0.1, AAR is not properly building. any update on this yar ?. when integrate this AAR to other project, its not working properly. its getting related to AppCombat support 7 related. Target,compile,buildtool is 26 & above are using our project. – harikrishnan Mar 21 '18 at 15:02