Search code examples
androidgradleaar

AAR artifact does not have build variant suffix


This is a weird one and I've been banging my head for a day because it's not the default behavior.

I have an AAR project and module. It's a simplified copy and paste of another project. By default, Android Studio will output the AAR file with the filename module-build_variant.aar

However, when I build this one, it's module.aar. Weird.

For the record, I've tried googling the problem, building from the command line, poring over the build.gradle files. Nada.

I'd like this project to build like the others and have properly named AAR files.

Project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    apply from: '../sharedConf/versions.gradle'
    addRepos(repositories)
    dependencies {
        classpath deps.android_gradle_plugin
        classpath deps.kotlin_plugin
    }
}

allprojects {
    addRepos(repositories)
}

task clean(type: Delete) {
    delete rootProject.buildDir

module build.gradle

// Import shared gradle settings
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {

    // Every shared preference among the Android projects
    def versionPropsFile = file('../../sharedConf/versions.gradle')
    if (!versionPropsFile.canRead()) {
        throw new GradleException('versions.gradle doesnt exist')
    }


    compileSdkVersion build_versions.target_sdk
    buildToolsVersion build_versions.build_tools

    // The version of the product. Generated by the build.py script
    String version = build_versions.version_name
    if (project.hasProperty("ms_version")) {
        version = "$ms_version"
    }


    defaultConfig {
        minSdkVersion build_versions.min_sdk
        targetSdkVersion build_versions.target_sdk

        versionName version.trim()
        versionCode build_versions.version_code
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    lintOptions {
        abortOnError true
    }

    signingConfigs {
        release {
            <SNIP>
        }
    }

    sourceSets {
        main.java.srcDirs += '../../***/***/src/main/java'
        main.java.srcDirs += '../../Infra/infra/src/main/java'
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    implementation deps.kotlin_stdlib

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
    implementation 'androidx.preference:preference:1.1.0-alpha04'
    implementation 'com.google.android.material:material:1.1.0-alpha04'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    // OK_HTTP_3
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.8.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
}

versions.gradle

def versions = [:]
versions.android_gradle_plugin = "3.3.2"
versions.kotlin = "1.3.21"

def build_versions = [:]
build_versions.version_name = "7.0"
build_versions.version_code = 7

build_versions.min_sdk = 16
build_versions.target_sdk = 29
build_versions.build_tools = "29.0.2"
ext.build_versions = build_versions

def deps = [:]
deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin"
deps.kotlin_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
deps.kotlin_stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin"
ext.deps = deps

def addRepos(RepositoryHandler handler) {
    handler.google()
    handler.jcenter()
    handler.mavenCentral()
    handler.flatDir {
        dirs 'libs'
    }
}
ext.addRepos = this.&addRepos

If I had to guess, there's some scenario where AS will build a single AAR. Perhaps it's merging the build variant (tried Debug minified=false) or something like that.


Solution

  • The cause was an incorrect version in gradle-wrapper.properties.

    It was 5.4.1 in this project. When reverted to 4.10.1, it generated correctly.

    Note that I use incorrect here in the loosest, most inaccurate way. I did not get an error or notice. The functionality simply changed. You would expect a mismatch of gradle and gradle plugin to break the build.