How to create a release android library package (a

2019-01-16 08:03发布

问题:

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".

回答1:

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:

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.



回答3:

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:



回答4:

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.



回答5:

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