Creating remote GIT branch

You can create a new local branch like this:
git checkout -b <branch_name>

If you want to make it a remote branch, then it can be pushed to remote like this (make sure that you're in this new branch):
git push origin <branch_name>

But sometimes, this newly pushed branch to remote doesn't get updated on remote location. Remote branches could be forced refreshed like this:
git remote update origin --prune 
If you want to delete a local branch:
git branch -d <branch_name>
If you want to delete this branch in remote too, then:
git push origin :<branch_name> 
 

Updating Android SDK tools from commandline

  • View all available downloads for build tools:
android list sdk --all 
  •  Updating packages
 android update sdk --no-ui --all --filter <package_number1, packager_number2, ...>
  •  Updating packages (without alias)
android update sdk -u -a -t <package_number1, packager_number2, ...>

To see the list of AVDs created/available :
android list targets 

SigningConfig for Gradle - Android

Add following code snippet in your build.gradle:

signingConfigs {
   debug {
      storeFile file('<full-path-to-keystore>/.android/debug.keystore')
      storePassword 'android'      keyAlias 'androiddebugkey'      keyPassword 'android'   } 
}
Add More variants for each flavor like release.

PackageManager.getInstalledPackages() vs PackageManger.getInstalledApplications()

PackageManager.getInstalledPackages()
Lists all the packages installed on the device including services, providers etc.

 PackageManger.getInstalledApplications()
Lists only applications installed on the device. Excludes services, providers etc.

Setting up Unit Testing in AndroidStudio - 1.5 with Robolectric

AndroidStudio Version: 1.5 - Preview2
Robolectric: robolectric:3.0-rc2


  • Choose "Unit Tests" in "Build Variants" as "Test Artifact". 
  • Create a Unit Test under "src/test" folder.
  • Run the test !


Configuration details:

build.gradle additions related with unit tests:

dependencies {
    
    testCompile 'junit:junit:4.12'    testCompile('org.robolectric:robolectric:3.0-rc2') {
        exclude group: 'commons-logging', module: 'commons-logging'        exclude group: 'org.apache.httpcomponents', module: 'httpclient'    }
}

Sample Test class:
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, emulateSdk = 21)
public class MyTest {

    @Before    public void setUp() throws Exception {
        // setup    }

    @Test    public void testSomething() throws Exception {
        // test        assert(true);
    }
}




Pro-guard in Android


  • Pro-guard can only be enabled in release builds, which is a good thing. Otherwise you would have to debug through obfuscated code.
  • Pro-guard can shrink, optimize and obfuscate code.
  • Obfuscated stack traces could be decoded using tool "retrace".
  • Enabling pro-guard in gradle based builds: set "minifyEnabled" to true.
  • Default pro-guard settings are available in <sdk>/tools/proguard/
    proguard-android.txt
  • Optimization can be enabled by using <sdk>/tools/proguard/proguard-android-optimize.txt file. But testing have to be thorough because these optimization rules may not be applicable to all versions of dalvik.
  •  Custom pro-guard rules can be added in proguard-rules.pro
  • While building with gradle build system, particular pro-guard rules can be applied to a targeted flavor

Scheduling Repeating Local Notifications using Alarm Manager

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