[转载]How to set name of AAR output from Gradle

As mentioned in comments below and another answer, the original answer here doesn’t work with Gradle 3+. Per the docs, something like the following should work:

Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:

// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
    variant.outputs.all {
          outputFileName = "${variant.name}-${variant.versionName}.apk"
    }
}

OLD ANSWER:

I am unable to get archivesBaseName & version to work for me w/ Android Studio 0.8.13 / Gradle 2.1. While I can set archivesBaseName and version in my defaultConfig, it doesn’t seem to affect the output name. In the end, adding the following libraryVariants block to my android {} scope finally worked for me:

libraryVariants.all { variant ->
    variant.outputs.all { output ->
        if (outputFile != null && outputFileName.endsWith('.aar')) {
            outputFileName = "${archivesBaseName}-v${versionName}.aar"
        }
    }
}

https://stackoverflow.com/questions/24728591/how-to-set-name-of-aar-output-from-gradle

[转载]Android Gradle 引用本地 AAR 的几种方式

  • 1. 把 AAR 放入 libs
  • 2. 在 build.gradle 添加 repositories{flatDir{dirs ‘libs’}}
  • 3. 在 build.gradle 添加 dependencies{compile(name:’nameOfYourAARFile’, ext:’aar’)}

其中当某个本地 aar/jar 需要在多个 module 进行依赖时,按照官方本身做法

Handling transitive dependencies for local artifacts (jars and aar)
If you have a local jar or aar library that you want to use in more than one project, you cannot just reference it directly as a local dependency. This is because the android plugin will complain if it finds the same jar file twice when dexing the project and all its dependencies. (Note that right now you can't actually use a local aar file even if you only reference it once).

One way to fix this is to deploy the artifact in a repository. While it's possible, it might not be convenient due to the overhead of managing such a repository.

Another option is to create a new Gradle sub-project, and to make this project's published artifact be the jar or aar file that you want to reuse. Then you can simply have other Gradle sub-projects depend on this new sub-project.

In this new sub-project, simply create a build.gradle with the following:

configurations.create("default")
artifacts.add("default", file('somelib.jar'))

经过实际测试,创建一个放有依赖库的 Module,里面包含所要的依赖库,和 build.gradele 文件

例如:当前 Module 名称为:ShareLibs
configurations.create("default")
artifacts.add("default", file('libs/somelib.jar'))

然后把此 Module 添加到根目录的 settings.gradle 中 'sharelibs'

其他各个 Module 都可以使用
implementation project(':sharelibs')

转自:http://www.cnblogs.com/AsionTang/p/5974254.html