How to setup Signing configuration in Android Studio/Gradle

Add following to your build.gradle :



android {

defaultConfig {}
signingConfigs {

   release {
      storeFile file("<path-to-signing-keys>/signingKeys.jks")
      storePassword "your store password"      keyAlias "your chosen alias"      keyPassword "password"
   }
}
You can also publish to playtore by adding following configuration to your build.gradle:
play {
    serviceAccountEmail = 'serviceAccount@gmail.com'    pk12File = file('key.p12')
    track = 'alpha'}

Automatic publishing apk to Google Play Store Developer Console using Jenkins


  1. Jenkins plugins:
    1. Google Play Publishing plugins (only works on Jenkins version > 1.6.09)
  2. Jenkins Build job
    1. Separate build job for each flavor of apk
    2. Create Free style build job in jenkins as described here.
  3. Configure Service Account on Google Play Store as shown here.

Android Testing using ATSL (Android Testing Support Library)


Running instrumented unit tests
Instrumented unit tests are important when a functionality can't be tested using mock objects.

Tools used
AndroidJunitRunner is used to run such tests.

Configuring build.gradle
defaultConfig {
applicationId "appId" minSdkVersion 17 targetSdkVersion 23 versionCode 1
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}
Dependencies
dependencies {
compile 'com.android.support:support-annotations:23.0.1' compile 'com.android.support:appcompat-v7:23.0.1'

androidTestCompile 'junit:junit:4.12' androidTestCompile 'com.android.support:support-annotations:23.0.1' androidTestCompile 'com.android.support.test:runner:0.4.1' androidTestCompile 'com.android.support.test:rules:0.4.1'
}
Running Instrument tests:
gradlew connectedAndroidTest


Useful links:

How to access build version from build.gradle from Java class

Its available in BuildConfig.java.

So simply access version name like this:
BuildConfig.VERSION_NAME

And Version code could be accessed like this:
BuildConfig.VERSION_CODE 

How to publish artifacts (Android Library in "aar" format) to Maven repo from Android Studio gradle

This post shows build.gradle configuration to be able to push artifacts to local Maven repo. I've taken Android library in its "aar" format as artifact for example.

First add "maven-publish" plugin to enable publishing artifacts from build.gradle:
apply plugin: 'maven-publish'
Don't forget to add local maven repo:
repositories {
    mavenLocal()
}
Add publishing block now:
publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId <GROUP_ID>
            artifactId <ARTIFACT_ID>
            version <currentVersion>

            artifacts = ["${buildDir}/outputs/aar/<your_android_library>.aar"]
        }
    }
}

How to create annotated Git tags

Annotated Git tags keep the information of related with tag and permanent in nature. It can be created using this command:
git tag -a <tagname>
An already existing tag can be modified using flag "-f" like this:
git tag -a -f <existing_tag_name>
A specific tag can be pushed to remote like this:
git push origin <tagname> 
Deleting tags:

  • Deleting remote tag:
git push origin :<tagname> OR git push --delete origin <tagname>
  • Deleting local tag
git tag -d <tagname>

General guidelines: 
  •  git push where-to-push source-refs:destination-refs
  • git push <remote> <local-branch>:<remote-branch>
  • git push origin refs/head/master:refs/heads/master
  • git push origin master:master



Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .