Add AAR file into build.gradle.kts

gradle-app.jpg

Importing AAR in Kotlin build.gradle.kts

Introduction

This article provides a detailed guide on how to create a new module in a Kotlin project to handle AAR (Android Archive) libraries. It covers the steps to set up the module, delete unnecessary files, configure the Gradle files (setting.gradle.kts and build.gradle.kts) to import the AAR dependencies, and compares two different approaches to module management.

Steps to Create a New Module for AAR Libraries

Step 1:

  • Create a new library module, for example, :lib module in your Kotlin project.

Step 2:

  • ForeIn the newly created :lib module, delete the /src folder. Since we dont need this /src folder or create the source code in this folder.

Step 3:

  • Create a new folder named sdk or whatever folder name you like for the aar SDK file and make it inside the :lib module. Place the AAR files that you want to reference in this folder.

Step 4:

  • Copy the :lib module’s original build.gradle.kts file into this sdk folder and add the following commands:
configurations.maybeCreate("default")
artifacts.add("default", file("sdk-release.aar"))

Step 5:

  • Open the setting.gradle.kts file in your project. Find the line that includes the :lib module, which should look like this:

    include(":lib")

    Modify this line to include the “sdk” subfolder:

    include(":lib:sdk")
  1. In the build.gradle.kts file of the module where you want to use the AAR libraries, add the following dependencies:

    implementation(project(":lib:sdk"))

Alternative Approach

If creating a new module seems cumbersome, you can create a new folder directly in the project’s root directory and configure it in the setting.gradle.kts file.

Add AAR file into build.gradle.kts

gradle-app.jpg

Importing AAR in Kotlin build.gradle.kts

Introduction

This article provides a detailed guide on how to create a new module in a Kotlin project to handle AAR (Android Archive) libraries. It covers the steps to set up the module, delete unnecessary files, configure the Gradle files (setting.gradle.kts and build.gradle.kts) to import the AAR dependencies, and compares two different approaches to module management.

Steps to Create a New Module for AAR Libraries

Step 1:

  • Create a new library module, for example, :lib module in your Kotlin project.

Step 2:

  • ForeIn the newly created :lib module, delete the /src folder. Since we dont need this /src folder or create the source code in this folder.

Step 3:

  • Create a new folder named sdk or whatever folder name you like for the aar SDK file and make it inside the :lib module. Place the AAR files that you want to reference in this folder.

Step 4:

  • Copy the :lib module’s original build.gradle.kts file into this sdk folder and add the following commands:
configurations.maybeCreate("default")
artifacts.add("default", file("sdk-release.aar"))

Step 5:

  • Open the setting.gradle.kts file in your project. Find the line that includes the :lib module, which should look like this:

    include(":lib")

    Modify this line to include the “sdk” subfolder:

    include(":lib:sdk")
  1. In the build.gradle.kts file of the module where you want to use the AAR libraries, add the following dependencies:

    implementation(project(":lib:sdk"))

Alternative Approach

If creating a new module seems cumbersome, you can create a new folder directly in the project’s root directory and configure it in the setting.gradle.kts file.