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

Talia ·
更新时间:2024-11-14
· 926 次阅读

方式一:

在gradle.properties中写入:

#测试环境 ENV_TEST=test #开发环境 ENV_DEV=dev #生产环境 ENV_ONLINE=online APPLICATION_ID=com.xxx.xxxx COMPILE_SDK_VERSION=26 TARGET_SDK_VERSION=26 MIN_SDK_VERSION=15 SUPPORT_V4_SUPPORT=com.android.support:support-v4:26.1.0 SUPPORT_ANNOTATIONS=com.android.support:support-annotations:26.1.0 SUPPORT_V7_APPCOMPAT=com.android.support:appcompat-v7:26.1.0 SUPPORT_V7_RECYCLERVIEW=com.android.support:recyclerview-v7:26.1.0

使用规则,字符串直接用,整形需在后加 as int

android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { applicationId APPLICATION_ID minSdkVersion MIN_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int versionCode 100 versionName "1.0.0" multiDexEnabled true flavorDimensions "versionCode" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }

方式二:

在根目录下的build.gradle文件下添加 buildscript{ .... } 中的内容:

buildscript { ext.kotlin_version = '1.1.51' ext.rxandroid = '2.0.1' ext.anko_version = '0.8.2' ext.support_version = '26.1.0' ext.target_sdk_version = 26 ext.min_sdk_version = 15 ext.applicationId = 'com.beiyijinfu.rxbusdemo' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

使用规则,字符串需使用“$”,整形直接用

android { compileSdkVersion compile_sdk_version defaultConfig { applicationId "com.xxx.xxxx" minSdkVersion min_sdk_version targetSdkVersion target_sdk_version versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation "com.android.support:appcompat-v7:$support_version" implementation "io.reactivex.rxjava2:rxandroid:$rxandroid" implementation "org.jetbrains.anko:anko-common:$anko_version" implementation "com.android.support:recyclerview-v7:$support_version" }

方式三:

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

ext{ kotlin_version = '1.1.51' rxandroid = '2.0.1' anko_version = '0.8.2' support_version = '26.1.0' target_sdk_version = 26 compile_sdk_version = 26 min_sdk_version = 15 }

使用规则,字符串需使用“$rootProject.”,整形直接用rootProject.。ext可加可不加

android { compileSdkVersion rootProject.compile_sdk_version defaultConfig { applicationId "com.xxx.xxxx" minSdkVersion rootProject.ext.min_sdk_version targetSdkVersion rootProject.ext.target_sdk_version versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$rootProject.ext.kotlin_version" implementation "com.android.support:appcompat-v7:$rootProject.support_version" implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rxandroid" compile "org.jetbrains.anko:anko-common:$rootProject.anko_version" compile "com.android.support:recyclerview-v7:$rootProject.support_version" }

方式四:

在项目根目录下创建.gradle文件,如:config.gradle,config.gradle中文件内容可以自己定义,如下示例:

ext{ kotlin_version = '1.1.51' rxandroid = '2.0.1' anko_version = '0.8.2' support_version = '26.1.0' target_sdk_version = 26 compile_sdk_version = 26 min_sdk_version = 15 }

使用规则,在build.gradle中先引用进来:

apply from :"config.gradle" dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile "com.android.support

总结

以上所述是小编给大家介绍的Android Studio中统一管理版本号引用配置问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!

您可能感兴趣的文章:AndroidStudio Gradle第三依赖统一管理的实现方法AndroidStudio安全管理签名文件keystroe和签名密码(星空武哥)



Android Studio studio 版本 版本号 Android

需要 登录 后方可回复, 如果你还没有账号请 注册新账号