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
使用规则,字符串直接用,整形需在后加asint
android{compileSdkVersionCOMPILE_SDK_VERSIONasintdefaultConfig{applicationIdAPPLICATION_IDminSdkVersionMIN_SDK_VERSIONasinttargetSdkVersionTARGET_SDK_VERSIONasintversionCode100versionName"1.0.0"multiDexEnabledtrueflavorDimensions"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=26ext.min_sdk_version=15ext.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:Donotplaceyourapplicationdependencieshere;theybelong//intheindividualmodulebuild.gradlefiles}}
使用规则,字符串需使用“$”,整形直接用
android{compileSdkVersioncompile_sdk_versiondefaultConfig{applicationId"com.xxx.xxxx"minSdkVersionmin_sdk_versiontargetSdkVersiontarget_sdk_versionversionCode1versionName"1.0"testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"}}dependencies{implementationfileTree(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=26compile_sdk_version=26min_sdk_version=15}
使用规则,字符串需使用“$rootProject.”,整形直接用rootProject.。ext可加可不加
android{compileSdkVersionrootProject.compile_sdk_versiondefaultConfig{applicationId"com.xxx.xxxx"minSdkVersionrootProject.ext.min_sdk_versiontargetSdkVersionrootProject.ext.target_sdk_versionversionCode1versionName"1.0"testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"}}dependencies{implementationfileTree(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=26compile_sdk_version=26min_sdk_version=15}
使用规则,在build.gradle中先引用进来:
applyfrom:"config.gradle" dependencies{compilefileTree(include:['*.jar'],dir:'libs')compile"com.android.support
总结
以上所述是小编给大家介绍的AndroidStudio中统一管理版本号引用配置问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!