1 <#-- 2 Copyright 2013 The Android Open Source Project 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 --> 16 buildscript { 17 repositories { 18 mavenCentral() 19 } 20 21 dependencies { 22 classpath 'com.android.tools.build:gradle:1.0.0' 23 } 24 } 25 26 apply plugin: 'com.android.application' 27 28 <#if sample.repository?has_content> 29 repositories { 30 <#list sample.repository as rep> 31 ${rep} 32 </#list> 33 } 34 </#if> 35 36 dependencies { 37 38 <#if !sample.auto_add_support_lib?has_content || sample.auto_add_support_lib == "true"> 39 <#if sample.minSdk?matches(r'^\d+$') && sample.minSdk?number < 7> 40 compile "com.android.support:support-v4:21.0.2" 41 <#elseif sample.minSdk?matches(r'^\d+$') && sample.minSdk?number < 13> 42 compile "com.android.support:support-v4:21.0.2" 43 compile "com.android.support:gridlayout-v7:21.0.2" 44 compile "com.android.support:cardview-v7:21.0.2" 45 <#else> 46 compile "com.android.support:support-v4:21.0.2" 47 compile "com.android.support:support-v13:21.0.2" 48 compile "com.android.support:cardview-v7:21.0.2" 49 </#if> 50 </#if> 51 52 <#list sample.dependency as dep> 53 compile "${dep}" 54 </#list> 55 <#list sample.dependency_external as dep> 56 compile files(${dep}) 57 </#list> 58 } 59 60 // The sample build uses multiple directories to 61 // keep boilerplate and common code separate from 62 // the main sample code. 63 List<String> dirs = [ 64 'main', // main sample code; look here for the interesting stuff. 65 'common', // components that are reused by multiple samples 66 'template'] // boilerplate code that is generated by the sample template process 67 68 android { 69 <#-- Note that target SDK is hardcoded in this template. We expect all samples 70 to always use the most current SDK as their target. --> 71 compileSdkVersion ${compile_sdk} 72 buildToolsVersion ${build_tools_version} 73 74 defaultConfig { 75 minSdkVersion ${min_sdk} 76 targetSdkVersion ${compile_sdk} 77 } 78 79 compileOptions { 80 sourceCompatibility JavaVersion.VERSION_1_7 81 targetCompatibility JavaVersion.VERSION_1_7 82 } 83 84 sourceSets { 85 main { 86 dirs.each { dir -> 87 <#noparse> 88 java.srcDirs "src/${dir}/java" 89 res.srcDirs "src/${dir}/res" 90 </#noparse> 91 } 92 } 93 androidTest.setRoot('tests') 94 androidTest.java.srcDirs = ['tests/src'] 95 96 <#if sample.defaultConfig?has_content> 97 defaultConfig { 98 ${sample.defaultConfig} 99 } 100 <#else> 101 </#if> 102 } 103 104 <#if sample.aapt?has_content> 105 aaptOptions { 106 <#list sample.aapt.noCompress as noCompress> 107 noCompress "${noCompress}" 108 </#list> 109 } 110 </#if> 111 } 112 // BEGIN_EXCLUDE 113 // Tasks below this line will be hidden from release output 114 115 task preflight (dependsOn: parent.preflight) { 116 project.afterEvaluate { 117 // Inject a preflight task into each variant so we have a place to hook tasks 118 // that need to run before any of the android build tasks. 119 // 120 android.applicationVariants.each { variant -> 121 <#noparse> 122 tasks.getByPath("prepare${variant.name.capitalize()}Dependencies").dependsOn preflight 123 </#noparse> 124 } 125 } 126 } 127 128 // END_EXCLUDE 129