targetSdkVersion gradle 奇怪的值 [英] targetSdkVersion gradle strange value
问题描述
所以,我从 Github 克隆了这个项目,在浏览它的 build.gradle
时,我发现了这个奇怪的配置,特别是对于 targetSdkVersion
.现在,在我详细介绍它是什么之前,让我提一下该项目有两个模块 - app
(主要模块)和 callrecord
(封装通话录音功能)
这是相同的 build.gradle
文件:
应用插件:'com.android.application'安卓 {compileSdkVersion project.sdk默认配置{applicationId "com.aykuttasil.callrecorder"minSdkVersion project.minSdktargetSdkVersion project.sdk版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}依赖{编译文件树(包括:['*.jar'],目录:'libs')androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {排除组:'com.android.support',模块:'support-annotations'})编译com.android.support:appcompat-v7:$supportVersion"testCompile 'junit:junit:4.12'编译项目(':callrecord')}
你能看到吗?
我不明白 compileSdkVersion project.sdk
这一行.这个项目对象"也在其他几个地方被引用.
首先,为什么会有人使用这个属性?其次,我如何知道它是什么版本?
为什么会有人使用这个属性?
- 使用此属性的主要目的是在一个地方配置 Android 项目模块的所有变量
- 所以在一个地方改变它会影响整个项目
我如何知道它是什么版本?
- 它将在
gradle.properties
或build.gradle
文件中提供
查看
样本
这是关于它的好文章
<块引用>然后在您的 Build.Gradle
android {compileSdkVersion project.myTargetSdkVersion.toInteger()默认配置{applicationIdcom.example.nilesh.myapplication"minSdkVersion project.myMinSdkVersion.toInteger()targetSdkVersion project.myTargetSdkVersion.toInteger()版本代码 1版本名称1.0"testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}编译选项{目标兼容性 1.8源兼容性 1.8}}
So, I cloned this project from Github and while going through its build.gradle
, I found this strange configuration, particularly for targetSdkVersion
. Now, before I jump into the details of what it is, let me mention that the project has two modules - app
(the main one) and callrecord
(encapsualting the call recording functionality)
Here is the build.gradle
file for the same:
apply plugin: 'com.android.application'
android {
compileSdkVersion project.sdk
defaultConfig {
applicationId "com.aykuttasil.callrecorder"
minSdkVersion project.minSdk
targetSdkVersion project.sdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$supportVersion"
testCompile 'junit:junit:4.12'
compile project(':callrecord')
}
Can you see it?
I don't understand the line compileSdkVersion project.sdk
. This project "object" has been referenced at several other places too.
First, why would someone use this property? Second, how do I find out what version it is?
why would someone use this property?
- The main purpose behind to use this property To Configure all variables for Android project modules in one place
- so changing it in one place will effect in whole project
how do I find out what version it is?
- it will be available in
gradle.properties
orbuild.gradle
in file
have a look in Build.Gradle file of CallRecorder
of that project
SAMPLE
Here is the good article on it Configure variables for all Android project modules in one place
gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX = true
android.enableJetifier = false
#gradle.properties
myTargetSdkVersion=27
myCompileSdkVersion=27
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
than use in your
Build.Gradle
android {
compileSdkVersion project.myTargetSdkVersion.toInteger()
defaultConfig {
applicationId "com.example.nilesh.myapplication"
minSdkVersion project.myMinSdkVersion.toInteger()
targetSdkVersion project.myTargetSdkVersion.toInteger()
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
这篇关于targetSdkVersion gradle 奇怪的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!