-
-
Save stepio/824ef073447eb8d8d654f22d73f9f30b to your computer and use it in GitHub Desktop.
gradle: package *.jar into aar
This file contains 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 | |
} | |
} |
@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
Hello. I'm trying to follow your code but dependencies are not saved in .AAR file. Could you help me please?