-
-
Save arindamxd/a43fd6363c3f8ae26661911fde2cdb65 to your computer and use it in GitHub Desktop.
gradle: package *.jar into aar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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