Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gradle: package *.jar into aar
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
includeJars // define new configuration
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services:12.0.1'
includeJars(name:'third_party_legacy_do_not_touch', ext:'jar') // the needed JAR(s) is/are here
testImplementation 'junit:junit:4.12'
}
// Main "magic" script to do the job
project.afterEvaluate {
def isAndroidLibraryProject = project.plugins.hasPlugin('com.android.library')
if(isAndroidLibraryProject) {
task copyDeps(type:Copy) {
from configurations.includeJars {
include '**/*.jar'
}
into "./build/intermediates/packaged-classes/release/libs" // this folder gets packaged inside the AAR
}
mergeReleaseJniLibFolders.dependsOn copyDeps // only this stage worked for me - neither earlier, nor later
task copyDebugDeps(type:Copy) {
from configurations.includeJars {
include '**/*.jar'
}
into "./build/intermediates/packaged-classes/debug/libs"
}
mergeDebugJniLibFolders.dependsOn copyDebugDeps
}
}
@enriqueajin
Copy link

enriqueajin commented Aug 23, 2021

Hello. I'm trying to follow your code but dependencies are not saved in .AAR file. Could you help me please?

@SomnathS09
Copy link

SomnathS09 commented Apr 9, 2022

@enriqueajin you can try this gradle plugin : https://github.com/kezong/fat-aar-android
It works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment