Tips:
以下例子为我的Android Studio环境配置,可以通过Create New Project查看你机器上的配置
1、项目名称project-name;
2、project-name/.idea/gradle.xml
<GradleProjectSettings>节点中新增/修改gradleHome value为本地已有的gradle版本,例如我的是gradle-2.14.1
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
3、project-name/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
4、project-name/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
def isReleaseBuild() {
return version.contains("SNAPSHOT") == false
}
allprojects {
version = VERSION_NAME
group = GROUP
repositories {
jcenter()
}
}
apply plugin: 'android-reporting'
5、project-name/对应module/build.gradle
修改compileSdkVersion和 buildToolsVersion为本地已有版本
Tips:如果有依赖support-v4、support-v7等时,修改此处可能会存在问题
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
6、加速gradle
在project-name/gradle.properties下添加
org.gradle.parallel=true
org.gradle.daemon=true
