gradle - Android

1. 编译android library

apply plugin: 'com.android.library'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }  

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }  
    }  

    lintOptions {
        abortOnError false
    }  
}

2. 编译android apk

apply plugin: 'android'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }  
        release {
            signingConfig signingConfigs.release
        }  
    }  

    lintOptions {
        abortOnError false
    }   

}

3. 配置apk的key

android {
  signingConfigs {
    release {
      storeFile file("/home/y/.android/platform.jks")
      storePassword "android"
      keyAlias "androiddebugkey"
      keyPassword "android"
    }
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }
}

4. 配置instrumentation apk

4.1 gradle配置

repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    //for pure testing apk
    compile 'com.android.support.test:runner:0.4'
    androidTestCompile 'com.android.support.test:runner:0.4'
    // Set this dependency to use JUnit 4 rules
    androidTestCompile 'com.android.support.test:rules:0.4'
    // Set this dependency to build and run Espresso tests
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    // Set this dependency to build and run UI Automator tests
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}

4.2 AndroidManifest.xml配置

引入TestRunner

<application>
    <uses-library android:name="android.test.runner"/>
</application>

声明一个instrumentation

<instrumentation android:name="android.test.InstrumentationTestRunner"
                 android:targetPackage="org.cfig.instruments"
                 android:label="Android Self Tests"/>