所以,我从Github克隆了这个项目,在浏览它的build.gradle时,我发现了这个奇怪的配置,特别是对于targetSdkVersion。现在,在我详细介绍它是什么之前,让我先提一下这个项目有两个模块--app(主要模块)和callrecord(封装呼叫记录功能)
下面是相同文件的build.gradle文件:
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')
}你能看见吗?
我不明白compileSdkVersion project.sdk这句话。这个项目"object“也在其他地方被引用过。
首先,为什么有人要使用这个属性?其次,我如何找出它是什么版本?
发布于 2018-08-31 12:25:48
为什么有人要使用这个属性?
我怎么知道它是什么版本?
它将在gradle.properties或build.gradle中的
中提供

示例
这是一篇关于它的好文章
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

在您的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
}
}https://stackoverflow.com/questions/52108359
复制相似问题