How to create a release android library package (aar) in Android Studio (not debug)

AndroidAndroid StudioAndroid Library

Android Problem Overview


I have built my android library package (aar) and the result of build is created in "..\app\build\outputs\aar" folder. The file within this folder is called "app-debug.aar" so I guess it has been built in debug mode so I would like to know how to genereate the release built, that is, "app-release.aar". How can I do this? Also, is it possible to genereate the build with another custom name, for example, "myCustomAppName-release.aar" instead of "app-release.aar".

Android Solutions


Solution 1 - Android

In Android Studio 1.2+, there is a complete gradle menu that lists all of the available gradle tasks.

I found this menu on the right side of the IDE with default options enabled.

The gradle menu is on the right side of the IDE by default...

Right click the task you want and click "Run".

Right click the task you want a click

Solution 2 - Android

This issue of can already be handled with the answers like execute

./gradlew assembleRelease

or choose assembleRelease from Android Studio's Gradle menu. However, for completeness, with Android Studio 1.5.1 (and probably also older versions) building release version of a .aar can be accomplished by selecting Build->Build APK in Android Studio. It seems to execute assembleRelease. If your project only contains the library project, it does not ask for any signing information.

Solution 3 - Android

With Android Studio 3.0 is easier to generate aar file. From the Gradle option, chek for the option as shown in the picture enter image description here

Solution 4 - Android

Create .aar

You can use command line

./gradlew <moduleName>:assemble

./gradlew <moduleName>:assemble<build_variant>
//for example
./gradlew <moduleName>:assembleRelease

//or
./gradlew <moduleName>:bundle<build_variant>Aar
//for example
./gradlew <moduleName>:bundleReleaseAar
//output is located
<project_path>/build/outputs/aar/<module_name>-<build_variant>.aar

Alternatively you can use AndroidStudio UI

View -> Tool Windows -> Gradle
<module_name> -> Tasks -> build or others -> assembleRelease

Solution 5 - Android

I faced this issue in AS 2.3.3 and solved it by changing the build variant of the module to release and building it again:

enter image description here

Solution 6 - Android

1.add following script to your android{} tag in build.gradle to generate a release build:

signingConfigs {
    testConfig{
        storeFile file("X:/XXXX/yourkeystore")
        storePassword "yourKeyPassword"
        keyAlias "yourAlias"
        keyPassword "yourAliasPassword"
    }
}

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

2.run command "gradle clean build" in you command line.

Solution 7 - Android

From Android Studio v4.x:

  1. Select Build Variant tab
  2. Choose release mode
  3. Then Menu > Build > Make module...
  4. Click build from the top menu > Rebuild project

Your .aar file will be found in the project file hierarchy on the left, under MyLibrary/Build/outputs (you may need to first, change the view from Android view to Project view, to see these files - using the dropdown at the top left corner)

Build AAR lib release

Solution 8 - Android

Yet another 2 part question where nobody answers the second part...

For the future generations, here are simple answers:

Part 1 How to create release only *release.aar ?

Run in android studio terminal (or any terminal in your project folder).:

./gradlew assembleRelease

You don`t need signing config for such task.

Part 2 How to rename the output library to AnotherLibraryName-release.aar ?

Add to your module gradle.build :

android{
    project.archivesBaseName = "AnotherLibraryName"
}

Solution 9 - Android

Set up your project as an Android library
In build.gradle file: plugin: 'com.android.library'
You can see the output in: build/outputs/aar/[your module].
Also see this link

Solution 10 - Android

for me, simply fixing a layout bug in the library that did not produce compile error (missing androidx plugin) fixed it and <lib>-release.aar appeared alongside the <lib>-debug.aar in build/outputs/aar/ folder.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRodriView Question on Stackoverflow
Solution 1 - AndroidjiminikizView Answer on Stackoverflow
Solution 2 - AndroiddiiduView Answer on Stackoverflow
Solution 3 - AndroidleeCoderView Answer on Stackoverflow
Solution 4 - AndroidyoAlex5View Answer on Stackoverflow
Solution 5 - AndroidVeneet ReddyView Answer on Stackoverflow
Solution 6 - AndroidcodezjxView Answer on Stackoverflow
Solution 7 - AndroidCong Dan LuongView Answer on Stackoverflow
Solution 8 - AndroidlukassosView Answer on Stackoverflow
Solution 9 - AndroidNickFView Answer on Stackoverflow
Solution 10 - AndroidJoeView Answer on Stackoverflow