Skip to content

Instantly share code, notes, and snippets.

@stepio
Forked from qrtt1/aar-deps.gradle
Last active August 8, 2023 07:47
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stepio/824ef073447eb8d8d654f22d73f9f30b to your computer and use it in GitHub Desktop.
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

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

@SomnathS09
Copy link

@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