Skip to content

Commit 61d47c6

Browse files
committed
优化当前项目的 Gradle 配置
1 parent 68d1fde commit 61d47c6

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

app/build.gradle

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
apply plugin: 'com.android.application'
2+
apply from : '../common.gradle'
23

34
android {
4-
compileSdkVersion 33
55

66
defaultConfig {
77
applicationId "com.hjq.device.compat.demo"
8-
minSdkVersion 16
9-
targetSdkVersion 33
10-
versionCode 10
11-
versionName "1.0"
8+
minSdk 16
129
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1310
}
1411

15-
// 支持 JDK 1.8
16-
compileOptions {
17-
targetCompatibility JavaVersion.VERSION_1_8
18-
sourceCompatibility JavaVersion.VERSION_1_8
19-
}
20-
2112
// Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
2213
signingConfigs {
2314
config {

common.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// 通用配置
2+
android {
3+
4+
// 编译源码版本
5+
compileSdk 34
6+
defaultConfig {
7+
// 最低安装版本
8+
minSdk 14
9+
// Android 版本适配指南:https://github.com/getActivity/AndroidVersionAdapter
10+
targetSdk 34
11+
versionCode 10
12+
versionName "1.0"
13+
}
14+
15+
// 支持 Java JDK 8
16+
compileOptions {
17+
targetCompatibility JavaVersion.VERSION_1_8
18+
sourceCompatibility JavaVersion.VERSION_1_8
19+
}
20+
21+
// 读取 local.properties 文件配置
22+
def properties = new Properties()
23+
def localPropertiesFile = rootProject.file("local.properties")
24+
if (localPropertiesFile.exists()) {
25+
localPropertiesFile.withInputStream { inputStream ->
26+
properties.load(inputStream)
27+
}
28+
}
29+
30+
String buildDirPath = properties.getProperty("build.dir")
31+
if (buildDirPath != null && buildDirPath != "") {
32+
// 将构建文件统一输出到指定的目录下
33+
setBuildDir(new File(buildDirPath, rootProject.name + "/build/${path.replaceAll(':', '/')}"))
34+
} else {
35+
// 将构建文件统一输出到项目根目录下的 build 文件夹
36+
setBuildDir(new File(rootDir, "build/${path.replaceAll(':', '/')}"))
37+
}
38+
}

library/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
apply plugin: 'com.android.library'
2+
apply from : '../common.gradle'
23

34
android {
4-
compileSdkVersion 26
55

66
resourcePrefix "demo_"
77

88
defaultConfig {
9-
minSdkVersion 14
10-
versionCode 10
11-
versionName "1.0"
9+
minSdk 14
1210
}
1311

1412
android.libraryVariants.configureEach { variant ->

0 commit comments

Comments
 (0)