How to set up gradle and android studio to do release build?
in the latest version of android studio, you can just do:
./gradlew assembleRelease
or aR
for short. This will produce an unsigned release apk. Building a signed apk can be done similarly or you can use Build -> Generate Signed Apk in Android Studio.
See the docs here
Here is my build.gradle for reference:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
}
}
How to set my gradle for final release apk
On the lower left of the Studio window there's a docked view called "Build Variants".
Open it and choose the release variant.
ps. you are adding compile 'com.google.android.gms:play-services:+' twice.
Android Studio gradle takes too long to build
Found the reason!! If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build, probably its trying to reach the proxy server and waiting for a timeout. When I removed the proxy server setting its working fine.
Removing proxy: File > Settings > Appearance & Behavior > System settings > HTTP Proxy
How to execute Android Tests with gradle before each release build?
Finally I managed to do that. I have added the following configuration to my build.gradle file in my android studio project:
// execute android tests before realising a new apk
tasks.whenTaskAdded { task ->
if (task.name == 'assembleRelease')
task.dependsOn('connectedAndroidTest')
}
android {
signingConfigs {
release {
keyAlias 'key'
keyPassword 'password'
storeFile file('/path/to/release_keystore.jks')
storePassword 'password'
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
After doing that I'm able to run all android tests when building a release apk. If the tests are failing no apk is built.
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 release build generated in Android Studio 3.0 unable to install
Before making the build, check if you have instant run enabled or not.
It is enabled by default and can be found under
File -> Settings -> Build,Execution,Deployment -> Instant Run
Disable it and then try rebuilding the apk.
Check comments and answers here
Now, if you are building a release apk and you have selected Signature Version V2(Full APK Signature), in the generate signed apk dialog, app might not install after the build is made.
You need to re-generate a signed apk with both the signature versions enabled i.e V1 & V2. You will get this option under Build -> Generate Signed APK.
Combining this with the disable instant run thing, your apk should install smoothly.
Android Studio: run/debug release version of app
There's a window called 'Build Variants' where you can choose, which version you want to be installed on your emulator/device.
You also have to add debuggable true
to your release build to be able to debug it.
Related Topics
How to Apply Custom CSS to Android Webview When Url Is from Internet Server
How Do Popular Apps Authenticate User Requests from Their Mobile App to Their Server
Android - Choose File Button in Webview
Android: Save File Permanently (Even After Clear Data/Uninstall)
Is There a Faster Way to Decode HTML Characters to a String Than HTML.Fromhtml()
Insufficent_Storage_Memory Message While Install 50 Mb APK in Emulator
How to Get Preview in Composable Functions That Depend on a View Model
How to Get Raw Preview Data from Camera Object at Least 15 Frames Per Second in Android
Running Google Map Application on Android Emulator
Change Chip Widget Style Programmatically Not Working - Android
How to Load The Listview "Smoothly" in Android
How to Create Android Project with Gradle from Command Line
How to Make Facebook's App New Menu on Android
Read All Sms from a Particular Sender
How to Handle Empty Response Body with Retrofit 2
Extract Notification Text from Parcelable, Contentview or Contentintent
Android: Keyboard Overlaps with the Edittext (With Printscreens)