我有一个Android库,它生成一个debug.aar和一个release.aar,我需要将release.aar复制到另一个文件夹作为对项目其他部分的引用.
我现在所做的是在这个Android库build.gradle我定义了一个任务:
task copyAARToCommonLibs(type: Copy) {
from('../build/outputs/aar') {
include '*-release.arr'
}
into '../SomeSampleApps/libs'
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试在生成arr之后运行此任务,我假设它是assembleRelease阶段,所以我尝试在此build.gradle中执行此操作
assembleRelease.doLast{
copyAARToCommonLibs
}
Run Code Online (Sandbox Code Playgroud)
我使用构建整个项目
gradle build
Run Code Online (Sandbox Code Playgroud)
但是这项任务在整个过程的最初阶段就开始了.
我也试过这个:
applicationVariants.all { variant ->
variant.assemble.doLast {
copyAARToCommonLibs
}
}
Run Code Online (Sandbox Code Playgroud)
在android {}属性里面(我猜这就是它的名字?)运行gradle build,得到了这个错误:找不到属性'applicationVariants'
然后我遇到了这个片段:
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyAARToCommonLibs }
Run Code Online (Sandbox Code Playgroud)
但似乎这使得任务在编译后运行,我不知道如何修改它以在汇编后运行.
有人可以在我做错的地方纠正我,如何在生成.arr文件后让这个副本任务工作?
示例代码
dependencies {
compile project (':aProject')
compile name: 'somefile'
compile files('libs/something_local.jar')
compile 'com.google.code.gson:gson:2.3.1'
}
Run Code Online (Sandbox Code Playgroud)
我的问题是
compile project和compile name这里有什么区别?
是compile name一样的compile files吗?
什么时候compile直接使用,如第5行代码所示
是什么compile在这里做?它是在编译括号/单引号内的文件吗?我可以使用像'build'之类的东西吗?