def appId = "com.example.tests" def appVersionName = "1.0" def appVersionCode = 2 android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId appId minSdkVersion 15 targetSdkVersion 23 versionCode appVersionCode versionName appVersionName multiDexEnabled = true // Avoid Bug with java 1.7 testInstrumentationRunner "com.example.tests.PreparerTestRunner" //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testBuildType "mock" } } dependencies { androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') { // this library uses the newest app compat v22 but the espresso contrib still v21. // you have to specifically exclude the older versions of the contrib library or // there will be some conflicts exclude group: 'com.android.support', module: 'appcompat' exclude group: 'com.android.support', module: 'support-v4' exclude module: 'recyclerview-v7' } androidTestCompile 'junit:junit:4.12' androidTestCompile 'com.squareup.retrofit:retrofit-mock:1.9.0' androidTestCompile 'com.squareup.assertj:assertj-android:1.1.0' androidTestCompile 'com.squareup.spoon:spoon-client:1.2.0' } // Grant animation permissions to avoid test failure because of ui sync. task grantAnimationPermissions(type: Exec, dependsOn: 'installMock') { group = 'test' description = 'Grant permissions for testing.' def absolutePath = file('..') // Get project absolute path commandLine "$absolutePath/set_animation_permissions.sh $appId".split(" ") } // Source: http://stackoverflow.com/q/29908110/112705 afterEvaluate { // When launching individual tests from Android Studio, it seems that only the assemble tasks // get called directly, not the install* versions tasks.each { task -> if (task.name.startsWith('assembleMockAndroidTest')) { task.dependsOn grantAnimationPermissions } } }