Android Studio: How to Generate Signed APK Using Gradle

Android Studio: how to generate signed APK using Gradle?

There are three ways to generate your build as per the buildType. (In your case, it's release but it can be named anything you want.)

  1. Go to Gradle Task in right panel of Android Studio and search for assembleRelease or assemble(#your_defined_buildtype) under Module Tasks

  2. Go to Build Variant in Left Panel and select the build from drop down

  3. Go to project root directory in File Explore and open cmd/terminal and run:

    Linux: ./gradlew assembleRelease or assemble(#your_defined_buildtype)

    Windows: gradlew assembleRelease or assemble(#your_defined_buildtype)

If you want to do a release build (only), you can use Build > Generate Signed apk. For other build types, only the above three options are available.

You can find the generated APK in your module/build directory having the build type name in it.

How to create a release signed apk file using Gradle?

Easier way than previous answers:

Put this into ~/.gradle/gradle.properties

RELEASE_STORE_FILE={path to your keystore}
RELEASE_STORE_PASSWORD=*****
RELEASE_KEY_ALIAS=*****
RELEASE_KEY_PASSWORD=*****

Modify your app/build.gradle, and add this inside the android { code block:

...    
signingConfigs {

release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD

// Optional, specify signing versions used
v1SigningEnabled true
v2SigningEnabled true
}
}

buildTypes {
release {
signingConfig signingConfigs.release
}
}
....

Then you can run gradle assembleRelease


Also see the reference for the signingConfigs Gradle DSL

Android studio - Generate signed APKs broke

After a few days of struggle, I ended up switching to Bundle. It achieves the same purpose for me and it actually works so... That's my solution here.

Gradle error when generating signed APK in Android Studio

If you are not actively linting a project, it might be easier just to disable it.

android {
...
lintOptions {
checkReleaseBuilds false
}

}

That code should prevent that particular gradle task for running.

Generate Signed APK in Android Studio

In left bottom corner of Android Studio, select the Build Variances, then you can change the build mode to "release". When building in release mode, I think the "Generate Signed APK" wizard works. So just ignore the build.gradle configuration!



Related Topics



Leave a reply



Submit