您好,登录后才能下订单哦!
小编给大家分享一下Android Studio中如何解决统一管理版本号引用配置问题,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
方式一:
在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中如何解决统一管理版本号引用配置问题”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。