Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Ahmed-Adel-Ismail Ahmed-Adel-Ismail commented Aug 7, 2018

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

This comment has been minimized.

Copy link

@sachinmcajnu sachinmcajnu commented Jan 4, 2019

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

This comment has been minimized.

Copy link

@jmhoraze jmhoraze commented Jun 5, 2019

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

@Nandkishor1234

This comment has been minimized.

Copy link

@Nandkishor1234 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