Skip to content

Instantly share code, notes, and snippets.

@abkoradiya
Forked from stepio/build.gradle
Created April 1, 2020 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abkoradiya/4b09938bf2e47ee0fae9e143bcc3b6fd to your computer and use it in GitHub Desktop.
Save abkoradiya/4b09938bf2e47ee0fae9e143bcc3b6fd 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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment