Willy
Willy

Reputation: 10638

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

I have built my Android library package (AAR) and the result of build is created in the "..\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 generate the release built, that is, "app-release.aar". How can I do this?

Also, is it possible to generate the build with another custom name, for example, "myCustomAppName-release.aar" instead of "app-release.aar"?

Upvotes: 106

Views: 96604

Answers (10)

diidu
diidu

Reputation: 2863

This issue 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.

Upvotes: 17

jiminikiz
jiminikiz

Reputation: 2889

In Android Studio 1.2+, there is a context panel listing all available Gradle tasks.

I found this panel 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 "RUN"

Upvotes: 124

yoAlex5
yoAlex5

Reputation: 34205

Create .aar

You can use the 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

The output is located at:

<project_path>/build/outputs/aar/<module_name>-<build_variant>.aar

Alternatively, you can use the Android Studio UI:

Menu ViewTool WindowsGradle <module_name>TasksBuild or othersassembleRelease

Upvotes: 22

Cong Dan Luong
Cong Dan Luong

Reputation: 1692

From Android Studio v4.x:

  1. Select the Build Variant tab
  2. Choose release mode
  3. Then menu BuildMake 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 library release

Upvotes: 13

Joe
Joe

Reputation: 2243

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

Upvotes: 0

CanCoder
CanCoder

Reputation: 1150

With Android Studio 3.0, it is easier to generate an AAR file. From the Gradle option, check for the option as shown in the picture:

Enter image description here

Upvotes: 13

lukassos
lukassos

Reputation: 379

Part 1: How can we create a release-only *release.aar?

Run in Android Studio terminal (or any terminal in your project folder):

./gradlew assembleRelease

You don’t need signing the configuration for such task.

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

Add to your module gradle.build:

android{
    project.archivesBaseName = "AnotherLibraryName"
}

Upvotes: 8

Veneet Reddy
Veneet Reddy

Reputation: 2907

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

Enter image description here

Upvotes: 14

NickF
NickF

Reputation: 5737

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

Upvotes: 3

codezjx
codezjx

Reputation: 9142

  1. Add the following script to your android{} tag in file 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 your command line.

Upvotes: 7

Related Questions