How to include files in META-INF folder in aar file in Android gradle?

Viewed 70

We would like to include a third party license file and pom file under META-INF folder in the aar file. We have tried the below way and created a folder "META-INF" folder under "resources"

    packagingOptions {
        resources {
            pickFirsts.add("META-INF/test.txt") // Just a test file to see if we can include
            merges.add("META-INF/test.txt")
        }
    }

wanted folder structure

But the folder structure of the aar file is still like this, no file is added under META-INF folder our folder structure

Below are the full content of our build.gradle file

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'org.jetbrains.dokka'
    id 'maven-publish'
}

apply from: '../jacoco.gradle'

android {
    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 29
        testInstrumentationRunner "androidx.est.runner.AndroidJUnitRunner"
        buildConfigField 'String', "VERSION_NAME", '"1.0.0.0"'
        buildConfigField 'int', "VERSION_CODE", '1'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
    packagingOptions {
        resources {
            pickFirsts.add("META-INF/test.txt")
            merges.add("META-INF/test.txt")
        }
    }
}
android.libraryVariants.all { variant ->
    variant.outputs.all { variantOutput -> outputFileName = "file.aar" }
}
dependencies {
...
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            pom {
                ...
            }
        }
    }
}

Could anyone please enlighten how should we achieve this? Thanks in advance!

0 Answers
Related