How to create a release android library package (aar) in Android Studio (not debug)
AndroidAndroid StudioAndroid LibraryAndroid 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.
Right click the task you want and click "Run".
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
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:
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:
- Select Build Variant tab
- Choose release mode
- Then Menu > Build > Make module...
- 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)
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.