re: default Gradle Dependencies
None of the prev. answers worked for me.
The key file is
C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root\build.gradle.ftl
The important part is it's in NewAndroidModule, NOT NewAndroidProject
Here's what my file looks like:
<#if !(perModuleRepositories??) || perModuleRepositories>
buildscript {
repositories {
jcenter()
<#if mavenUrl != "mavenCentral">
maven {
url '${mavenUrl}'
}
</#if>
}
dependencies {
classpath 'com.android.tools.build:gradle:${gradlePluginVersion}'
}
}
</#if>
<#if isLibraryProject?? && isLibraryProject>
apply plugin: 'com.android.library'
<#else>
apply plugin: 'com.android.application'
</#if>
<#if !(perModuleRepositories??) || perModuleRepositories>
repositories {
jcenter()
<#if mavenUrl != "mavenCentral">
maven {
url '${mavenUrl}'
}
</#if>
}
</#if>
android {
compileSdkVersion <#if buildApiString?matches("^\\d+$")>${buildApiString}<#else>'${buildApiString}'</#if>
buildToolsVersion "${buildToolsVersion}"
defaultConfig {
<#if isLibraryProject?? && isLibraryProject>
<#else>
applicationId "${packageName}"
</#if>
minSdkVersion <#if minApi?matches("^\\d+$")>${minApi}<#else>'${minApi}'</#if>
targetSdkVersion <#if targetApiString?matches("^\\d+$")>${targetApiString}<#else>'${targetApiString}'</#if>
versionCode 1
versionName "1.0"
}
<#if javaVersion?? && (javaVersion != "1.6" && buildApi lt 21 || javaVersion != "1.7")>
compileOptions {
sourceCompatibility JavaVersion.VERSION_${javaVersion?replace('.','_','i')}
targetCompatibility JavaVersion.VERSION_${javaVersion?replace('.','_','i')}
}
</#if>
<#if enableProGuard>
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
</#if>
}
dependencies {
<#if dependencyList?? >
<#list dependencyList as dependency>
compile '${dependency}'
</#list>
</#if>
compile fileTree(dir: 'libs', include: ['*.jar'])
<#if WearprojectName?has_content && NumberOfEnabledFormFactors?has_content && NumberOfEnabledFormFactors gt 1 && Wearincluded>
wearApp project(':${WearprojectName}')
compile 'com.google.android.gms:play-services:+'
</#if>
<#if unitTestsSupported>
testCompile 'junit:junit:${junitVersion}'
</#if>
//from C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root\build.gradle.ftl
//logback
// compile 'MyAwesomeDependency:1.1.+'
// compile 'MyOtherAwesomeDependency:1.1.+'
// compile 'org.slf4j:slf4j-api:1.7.+'
//end logback
// compile 'com.google.code.gson:gson:2.+'
}
and here's the correct output build.gradle for module app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.ntier.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//from C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root\build.gradle.ftl
//logback
// compile 'MyAwesomeDependency:1.1.+'
// compile 'MyOtherAwesomeDependency:1.1.+'
// compile 'org.slf4j:slf4j-api:1.7.+'
//end logback
// compile 'com.google.code.gson:gson:2.+'
compile 'com.android.support:appcompat-v7:23.4.0'
}
So, finally, after the build.gradle is gen'd I uncomment accordingly.
This took me all day to figger out. I'm pretty displeased w/ the Gradle doc'n and the Android Studio Doc'n. This should have been an easy task w/ quick easy doc'n. As it is, I still don't understand gradle confign very well.
:-{
The directory sequence above is for my installed Android Studio. Your Android Studio may be installed elsewhere but this answer is still relevant.
WARNING: I just tried to update my Android Studio and it balks because it's noticed the change in the file.
So, MAKE SURE YOU BACKUP THIS FILE before you modify it. and then
RESTORE THE FILE prior to updating Android Studio.