方式一(推荐)

1.在根目录下的build.gradle文件下添加 ext{ …. } 中的内容

buildscript {    repositories {        google()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:3.0.1'        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        google()        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}ext{    //SDK    minSdkVersion = 15      targetSdkVersion = 26    compileSdkVersion = 26    //dependencies    supportLibraryVersion ='26.1.0'    butterknifeVersion = '8.8.1'}

注:在android studio3.0之后,buildToolsVersion去掉了,等号也别忘记了,要不然会报: Gradle DSL method not found: ‘minSdkVersion()’

2.在app目录下build.gradle中使用

apply plugin: 'com.android.application'android {    compileSdkVersion rootProject.ext.compileSdkVersion    defaultConfig {        applicationId "com.asialyf.zhiqu"        minSdkVersion rootProject.ext.minSdkVersion        targetSdkVersion rootProject.ext.targetSdkVersion        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"    implementation 'com.android.support.constraint:constraint-layout:1.0.2'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.1'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'    //Butterknife    implementation "com.jakewharton:butterknife:$rootProject.butterknifeVersion"}

注意:引用的依赖使用的是双引号

方式二

1.在项目根目录下创建.gradle文件,如:config.gradle
2.在根目录下的build.gradle文件中引入创建的配置文件
apply from:”config.gradle”
3.最后config.gradle中文件内容可以自己定义

ext {      // 用于编译的SDK版本      COMPILE_SDK_VERSION = 23      // 用于Gradle编译项目的工具版本      BUILD_TOOLS_VERSION = "24.0.2"      // 最低支持Android版本      MIN_SDK_VERSION = 14      // 目标版本      TARGET_SDK_VERSION = 23      APPCOMPAT_VERSION = '23.2.1'  } 

4.在app目录下的build.gradle中使用

dependencies {      compile fileTree(include: ['*.jar'], dir: 'libs')      compile "com.android.support:cardview-v7:${APPCOMPAT_VERSION}"      compile "com.android.support:appcompat-v7:${APPCOMPAT_VERSION}"      compile "com.android.support:design:${APPCOMPAT_VERSION}"      compile 'com.github.bumptech.glide:glide:3.7.0'  } 

更多相关文章

  1. [Android(安卓)Studio] FloatingActionButton could not be inst
  2. android:app接收adb发送的命令并显示
  3. android bks证书生成方式
  4. Android(安卓)获取屏幕尺寸
  5. Android:解决Failed to load D:\Android-Studio\sdk\build-to
  6. Android(安卓)dp方式的屏幕适配工具使用(Android(安卓)Studio插
  7. 使用 Linux 终端进行算术运算
  8. android 系统中修改系统的版本号

随机推荐

  1. Android 文件的下载
  2. Android部分控件示例汇总
  3. Android Studio中 Error:Could not find
  4. Android Retrofit W/System.err: java.ne
  5. react native android 调试时图片没有显
  6. 使用ANT进行Android打包
  7. TextView使用Paint设置下划线删除线效果
  8. android读取系统相机及相册图片(亲测可用)
  9. Android:Activity(二):Bundle的作用
  10. [置顶] Android(安卓)多点触摸 multi-tou