问题
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?
回答1:
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
}
}
来源:https://stackoverflow.com/questions/52108359/targetsdkversion-gradle-strange-value