junit依赖_Android Studio配置统一管理依赖版本号引用 - HaiyuKing

版权声明:本文为HaiyuKing原创文章,转载请注明出处!

前言

本Demo采用的是其中一个方案,其他方案请阅读参考资料《Android Studio中统一管理版本号引用配置》

使用步骤

一、项目组织结构图

ea1dbfe8528083b9fb566c211331ce7d.png

注意事项:

1、  导入类文件后需要change包名以及重新import R文件路径

2、  Values目录下的文件(、、等),如果项目中存在,则复制里面的内容,不要整个覆盖

二、导入步骤

(1)新建项目后查看app/文件,获取版本号(compileSdkVersion、buildToolsVersion、minSdkVersion、targetSdkVersion、support:appcompat、constraint-layout等)

其中,buildToolsVersion的可选值在sdk安装目录下的build-tools中查看(对了,如果使用新建项目,可能在app/文件中看不到buildToolsVersion,那么最后可加可不加,本Demo就不添加了):

784320148cdaffc0ec158bba5374397c.png

新建项目后的app/文件:

apply plugin: ''

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId ""
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName ""
        testInstrumentationRunner ""
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(''), ''
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation ''implementation ''
    testImplementation 'junit:junit:'
    androidTestImplementation 'com.android.support.test:runner:.2'
    androidTestImplementation ''

}
(2)在项目的文件中添加以下代码【根据实际情况扩充,写法类似】
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url ''
            name 'Google'
        }
    }
    dependencies {
        classpath ''

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module  files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//Android Studio统一管理依赖版本号引用配置
ext {
    //修改compileSdkVersion并不会影响我们的我们生成的app在手机先的行为。最理想的情况就是把compileSdkVersion设置到最高。
    globalCompileSdkVersion = 27
    //构建工具的版本号是多少,规则是可以用高的构建工具来构建低版本Sdk的工程。使用build-tools目录中的最大版本号即可
    globalBuildToolsVersion = ""
    //targetSdkVersion的设置主要是当系统版本高于设置的target的时候。然后targetSdkVersion最好和compileSdkVersion一样。
    globalTargetSdkVersion = 27
    //这个就是程序运行的最低的要求的Sdk版本号,在低于这个版本号的手机设备上无法安装。
    globalMinSdkVersion = 16

    supportLibraryVersion = ""

    /*=================================常用的引用============================================*/
    //supportLibVersion 的头数字是和targetSdkVersion 版本一样的。
    androidDependencies = [
            appcompat_v7 : ":${supportLibraryVersion}",
            design        : ":${supportLibraryVersion}",
            support_v4    : ":${supportLibraryVersion}",
            recyclerView : ":${supportLibraryVersion}",
    ]

    /*=================================module中公共用到的引用============================================*/
    globalDependencies = [
            //constraintLayout引用
            constraintLayout : "",
            //glide的引用
            glide : "",
    ]
}
(3)修改app/
apply plugin: ''

android {
    compileSdkVersion rootProject.ext.globalCompileSdkVersion
    defaultConfig {
        applicationId ""
        minSdkVersion rootProject.ext.globalMinSdkVersion
        targetSdkVersion rootProject.ext.globalTargetSdkVersion
        versionCode 1
        versionName ""
        testInstrumentationRunner ""
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(''), ''
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation androidDependencies.appcompat_v7
    implementation globalDependencies.constraintLayout
    testImplementation 'junit:junit:'
    androidTestImplementation 'com.android.support.test:runner:.2'
    androidTestImplementation ''

}
 (4)参考app/的修改方法修改其他module中的文件

混淆配置

参考资料

Android Studio中统一管理版本号引用配置

如何查看buildToolsVersion的版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值