Skip to content

Instantly share code, notes, and snippets.

@nisrulz
Created April 5, 2015 20:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nisrulz/0114c56675a54f9ca473 to your computer and use it in GitHub Desktop.
Save nisrulz/0114c56675a54f9ca473 to your computer and use it in GitHub Desktop.
Gradle : build.gradle file for a AAR Module Library Project
apply plugin: 'com.android.library'
android {
signingConfigs {
release {
try {
keyAlias KEYSTORE_ALIAS
keyPassword KEY_PASSWORD
storeFile file(KEYSTORE_FILEPATH)
storePassword KEYSTORE_PASSWORD
}
catch (ex) {
throw new InvalidUserDataException("You should define KEYSTORE_ALIAS, KEYSTORE_FILEPATH, KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.")
}
}
}
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
archivesBaseName = "Project Name"
version = android.defaultConfig.versionName
}
buildTypes {
debug {
minifyEnabled false
}
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${archivesBaseName}-${version}-${variant.buildType.name}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
@Ahmed-Adel-Ismail
Copy link

It gives me this error while syncing gradle :
Cannot set the value of read-only property 'outputFile' for object of type com.android.build.gradle.internal.api.LibraryVariantOutputImpl.

@sachinmcajnu
Copy link

It gives me this error while syncing gradle :
Cannot set the value of read-only property 'outputFile' for object of type com.android.build.gradle.internal.api.LibraryVariantOutputImpl.
variant.outputs.each --> replace with variant.outputs.all

@jmhoraze
Copy link

jmhoraze commented Jun 5, 2019

gradle.org has changed syntax (as they always do):
use outputFileName and variant.output.all

@Nandkishor1234
Copy link

Nandkishor1234 commented May 19, 2021

Working code (2021 May)

libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFileName
if (outputFile != null && outputFile.endsWith('.aar')) {
def fileName = "${archivesBaseName}${version}${variant.buildType.name}.aar"
output.outputFileName = fileName
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment