Android Studio Create AAR using another AAR file and jar inside
Asked Answered
O

2

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
}
Obeded answered 3/11, 2016 at 15:28 Comment(4)
You have to add transitive=true in dependency which you are including in your main project.Wilterdink
I added in MainProject for transitive=true. But, am getting same error.An particular class showing noclassdeffound error from imported aar.Obeded
Please post code of build.gradle.Wilterdink
my gradle is pasted Vipul Asri. can u check onceObeded
R
0

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

Reserpine answered 10/11, 2016 at 8:7 Comment(2)
The above mentioned fat-aar method only working to Create AAR Library in Android Native using Android Studio Successfully.Obeded
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.Obeded
S
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...

Slipnoose answered 10/11, 2016 at 8:0 Comment(7)
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.Obeded
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.Obeded
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.Slipnoose
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,Obeded
You can still package client's jars and aar to your maven repository manualySlipnoose
Its possible to include an aar inside other aar without maven?Amorino
@PabloCegarra I don't think so. You have to use a repo like maven or you have to merge aar files into one.Slipnoose
R
0

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

Reserpine answered 10/11, 2016 at 8:7 Comment(2)
The above mentioned fat-aar method only working to Create AAR Library in Android Native using Android Studio Successfully.Obeded
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.Obeded

© 2022 - 2024 — McMap. All rights reserved.