SoFunction
Updated on 2025-04-10

Unified management of version number reference configuration issues in Android Studio

Method 1:

Write in:

#Test environmentENV_TEST=test
#Development EnvironmentENV_DEV=dev
#Production EnvironmentENV_ONLINE=online
APPLICATION_ID=
COMPILE_SDK_VERSION=26
TARGET_SDK_VERSION=26
MIN_SDK_VERSION=15
SUPPORT_V4_SUPPORT=:support-v4:26.1.0
SUPPORT_ANNOTATIONS=:support-annotations:26.1.0
SUPPORT_V7_APPCOMPAT=:appcompat-v7:26.1.0
SUPPORT_V7_RECYCLERVIEW=:recyclerview-v7:26.1.0

Use rules, use strings directly, and plastic surgery needs to be added as int afterwards

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 "" }

Method 2:

Add the contents in buildscript{ .... } under the file in the root directory:

buildscript { ext.kotlin_version = '1.1.51'  = '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  = '' repositories { google() jcenter() } dependencies { classpath ':gradle:3.0.0' classpath ":kotlin-gradle-plugin:$kotlin_version" classpath ":kotlin-android-extensions:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module  files } }

Use rules, strings need to be used with "$", and use them directly with plastic surgery

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

Method 3:

Add the contents in ext{ .... } under the file in the root directory:

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 }

Using rules, strings need to use "$rootProject." and plastic surgery directly use rootProject. Ext can be added or not

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

Method 4:

Create a .gradle file in the project root directory, such as: The contents of the file can be defined by yourself, as shown in the following example:

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 }

Use the rules, first quote it in:

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

Summarize

The above is the unified management version number reference configuration problem in Android Studio introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!