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".
-
https://developer.android.com/tools/building/building-studio.html#buildRelease – gilchris Apr 20 '15 at 10:21
-
2Have you found a solution for this problem? I have the same issue and can not find any help with it. – Belurd Jun 08 '15 at 06: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".
- 2,720
- 1
- 25
- 28
-
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. – Mick Jul 09 '15 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? – Mick Jul 09 '15 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 :) – jiminikiz Jul 10 '15 at 19:49
-
just one question,when you export aar files in release mode,will it itncludes latest proguard properties with it ? – abh22ishek Nov 27 '15 at 10:30
-
i want to export an aar file ,with having a code obfuscation which is provided by proguard ? – abh22ishek Nov 27 '15 at 10:31
-
1Yes, if you run the `assemble` task, it will apply whatever progaurd rules you have defined in your project. – jiminikiz Dec 01 '15 at 16:49
-
-
@K.R.SaravanaKumar are you sure that you have the proper `gradle` configuration file within your library? – jiminikiz Nov 26 '18 at 04:07
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.
- 2,683
- 16
- 30
With Android Studio 3.0 is easier to generate aar file. From the Gradle option, chek for the option as shown in the picture
- 949
- 11
- 19
-
In my project i am not able to see assemble release option. – Gyan Swaroop Awasthi Sep 01 '20 at 07:38
-
2when i import my release .aar lib in a project it rise an error like "AAPT: error: attribute ... not found" @leeCoder – Shomu Sep 06 '20 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
- 21,739
- 5
- 148
- 151
-
what is the difference between `./gradlew
:assemble – rupesh May 26 '20 at 10:27` and `./gradlew :bundle Aar` ?
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:
- 2,419
- 1
- 21
- 37
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.
- 8,822
- 5
- 44
- 54
-
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? – Rodri Dec 25 '14 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') } – codezjx Dec 25 '14 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. – Rodri Dec 25 '14 at 11:11
-
Sorry to tell you: Gradle build does not support local aar dependencies, you can visit: https://code.google.com/p/android/issues/detail?id=55863 – codezjx Dec 25 '14 at 11:27
-
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. – Rodri Dec 25 '14 at 11:34
-
Also how can I force a custom name instead of the preceding "app" in the "app-debug.aar" and "app-release.aar" files? I would like to be able to change "app" prefix by a desired one, that is fore example, "myCustomName-debug.aar" and "myCustomName-release.aar" – Rodri Dec 25 '14 at 11:45
-
Bill, this is not totaly true that Gradle does not support local aar dependencies, please, read at the end of your posted URL. There is a workaround to do it. Also described here: http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project – Rodri Dec 25 '14 at 12:12
-
To set custom name for aar output file I have finally done this (instead of using applicationVariants use libraryVariants instead): http://stackoverflow.com/questions/27114073/could-not-find-property-outputfile-on-com-android-build-gradle-internal-api-ap – Rodri Dec 25 '14 at 13:04
-
Did you solve on generating the release.aar file? I have the same problem and cannot solve it... – Massimo Feb 20 '15 at 10:28
-
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. – CodyMace May 13 '15 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)
- 3,017
- 2
- 23
- 24
- 1,327
- 14
- 14
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"
}
- 361
- 5
- 12
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.
- 2,204
- 1
- 19
- 29