-
-
Save n-belokopytov/d44949590748b096c1a497008b761d04 to your computer and use it in GitHub Desktop.
| apply plugin: 'com.android.application' | |
| android.applicationVariants.all { variant -> | |
| task "copyDependencies${variant.name.capitalize()}"() { | |
| outputs.upToDateWhen { false } | |
| doLast { | |
| println "Executing copyDependencies${variant.name.capitalize()}" | |
| variant.getCompileClasspath().each { fileDependency -> | |
| def sourcePath = fileDependency.absolutePath | |
| def destinationPath = project.projectDir.path + "/build/dependencies/${variant.name}/" | |
| println "Copying dependency:" | |
| println sourcePath | |
| //The monstrous regex that gets the name of the lib from it’s exploded .aar path | |
| def dependencyName | |
| if (sourcePath.contains("classes.jar")) { | |
| def dependencyNameRegexResult = (sourcePath =~ /.*\/(.*)\.aar\/.*\/jars\/classes\.jar/) | |
| if (dependencyNameRegexResult.size() > 0) { | |
| dependencyName = dependencyNameRegexResult[0][1] | |
| println "Exploded AAR found : ${dependencyName}" | |
| } | |
| } | |
| copy { | |
| from sourcePath | |
| into destinationPath | |
| rename {String filename -> | |
| if (filename.contains("classes.jar") && dependencyName != null) { | |
| dependencyName = "${dependencyName}.jar" | |
| println "Renaming dependency file to : ${dependencyName}" | |
| return dependencyName | |
| } | |
| return filename | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
I use this code to copy dependencies. Execute gradlew copyDepsRelease or gradlew copyDepsDebug.
android.applicationVariants.all { variant ->
task "copyDeps${variant.name.capitalize()}"() {
outputs.upToDateWhen { false }
doLast {
mkdir 'depsLibs'
variant.getCompileConfiguration().getResolvedConfiguration().getResolvedArtifacts().each{ artifact ->
def id = artifact.moduleVersion.id
def targetName = "${id.group}${id.name}${id.version}.${artifact.type}"
copy{
from artifact.file
into 'depsLibs'
rename('(.*)',targetName)
}
}
}
}
}
if you just want to list all dependencies with their versions for a configuration
https://gist.github.com/kibotu/a4b248e5ca8b702ef5884c3ab9693f8f
thanks for your script. but i wonder how to get the dependencies in my custom AS plugin. Is there any gradle APIs for Idea Plugin developing? i have googled a lot but got nothing i want. Hope you can help me.
@git4pl sorry, can't help you bud. Maybe you could look for a Slack community of JetBrains or Gradle - there should be people who can help you. I also couldn't find any documentation on the implemented methods of AS Gradle Plugin.
may i ask, how can i get the proguard.txt file in each depended aar file. i find out that the files copied is all *.jar but not *.aar