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".
-
developer.android.com/tools/building/…– gilchrisApr 20, 2015 at 10:21
-
2Have you found a solution for this problem? I have the same issue and can not find any help with it.– BelurdJun 8, 2015 at 6:32
10 Answers
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".
-
1This works for me, but I noticed that the build from the standard 'build' menu also started working once I had run the cmd line grade commands suggested by user1624552 in comments for another answer here. It would be useful if someone who has not run the command line grade can confirm this side gradle menu approach works also as I noticed the command line downloaded what looked like a new version of gradle in my case before it ran and I wonder if that also is a required step.– MickJul 9, 2015 at 16:29
-
1BTW, well done finding this!!! If anyone from Google is looking at this it would be nice to know if there are any plans to link/rationalise/explain the top Build menu, this 'new' Gradle side menu, and the Build Variants view etc?– MickJul 9, 2015 at 16:32
-
Yeah, definitely. I too ran gradle from the commandline as the others answers had suggested until I found that menu. I am not sure that running it from the commandline is required first before using the side menu... What is interesting too is that whatever task you run from the side gradle menu becomes the default action "Run" action. So, in other words, the green arrow icon and the Run menu point to the last run gradle task. Useful :) Jul 10, 2015 at 19:49
-
just one question,when you export aar files in release mode,will it itncludes latest proguard properties with it ? Nov 27, 2015 at 10:30
-
1Yes, if you run the
assemble
task, it will apply whatever progaurd rules you have defined in your project. Dec 1, 2015 at 16:49
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.
With Android Studio 3.0 is easier to generate aar file. From the Gradle option, chek for the option as shown in the picture
-
In my project i am not able to see assemble release option. Sep 1, 2020 at 7:38
-
2when i import my release .aar lib in a project it rise an error like "AAPT: error: attribute ... not found" @leeCoder– ShomuSep 6, 2020 at 11:39
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
-
what is the difference between
./gradlew <moduleName>:assemble<build_variant>
and./gradlew <moduleName>:bundle<build_variant>Aar
?– rupeshMay 26, 2020 at 10:27
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:
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.
-
Sorry, I am newbie in Android development. Is it strictly necessary to sign an android library package (aar) to get its release output? How can I generate my own key store?– RodriDec 25, 2014 at 10:52
-
In my library project, \build\outputs\aar is already generate: XX-debug.aar, XX-release.aar. And Why you nedd a .arr file? If you want to use a library, just add following script in you build.gradle: dependencies { compile project(':YourLibraryProject') }– codezjxDec 25, 2014 at 11:07
-
1I want to use this library within my android apps in future. This is a library and I want to obtain its release output but I do not understand why but I am obtaining only XX-debug.aar and not XX-release.aar in my library's "\app\build\outputs\aar" folder.– RodriDec 25, 2014 at 11:11
-
5From a terminal windows, once in project folder, I have executed the following commands: "./gradlew clean" and "./gradlew aR" and now "XX-release.aar" is generated into "..\app\build\outputs\aar" folder. How can I do the same from Android Studio? that is, to tell Android Studio to assemble the Release as well.– RodriDec 25, 2014 at 11:34
-
1Normally all you need to do is build the project in android studio but I have this same issue in a couple of apps. So doing it in the terminal is the only solution.– CodyMaceMay 13, 2015 at 19:32
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)
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"
}
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
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.