Skip to content

Commit 2b0c530

Browse files
committed
升级 Gradle 版本到 8.9-bin
升级 AGP 插件版本到 8.4.2 将 Demo 工程的 compileSdk 和 targetSdk 升级到 36
1 parent dc7284e commit 2b0c530

File tree

7 files changed

+112
-116
lines changed

7 files changed

+112
-116
lines changed

app/build.gradle

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

34
android {
4-
compileSdkVersion 34
5+
namespace 'com.hjq.toast.demo'
56

67
defaultConfig {
78
applicationId "com.hjq.toast.demo"
8-
minSdkVersion 17
9-
targetSdkVersion 34
10-
versionCode 1302
11-
versionName "13.2"
9+
minSdk 17
1210
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1311
}
1412

15-
// 使用 JDK 1.8
16-
compileOptions {
17-
targetCompatibility JavaVersion.VERSION_1_8
18-
sourceCompatibility JavaVersion.VERSION_1_8
19-
}
20-
2113
// Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
2214
signingConfigs {
2315
config {

app/src/main/java/com/hjq/toast/demo/MainActivity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.hjq.toast.demo;
22

33
import android.content.Intent;
4+
import android.graphics.Insets;
45
import android.net.Uri;
56
import android.os.Build;
67
import android.os.Bundle;
78
import android.util.TypedValue;
89
import android.view.Gravity;
910
import android.view.View;
11+
import android.view.View.OnApplyWindowInsetsListener;
12+
import android.view.WindowInsets;
13+
import androidx.annotation.NonNull;
1014
import androidx.appcompat.app.AppCompatActivity;
1115
import com.google.android.material.snackbar.Snackbar;
1216
import com.hjq.bar.OnTitleBarListener;
@@ -43,6 +47,21 @@ public void onTitleClick(TitleBar titleBar) {
4347
startActivity(intent);
4448
}
4549
});
50+
51+
// 适配 Android 15 EdgeToEdge 特性
52+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
53+
titleBar.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
54+
55+
@NonNull
56+
@Override
57+
public WindowInsets onApplyWindowInsets(@NonNull View v, @NonNull WindowInsets insets) {
58+
Insets systemBars = insets.getInsets(WindowInsets.Type.systemBars());
59+
// v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
60+
v.setPadding(0, systemBars.top, 0, 0);
61+
return insets;
62+
}
63+
});
64+
}
4665
}
4766

4867
public void showToast(View v) {

build.gradle

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,6 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
3-
buildscript {
4-
repositories {
5-
// 阿里云云效仓库:https://maven.aliyun.com/mvn/guide
6-
maven { url 'https://maven.aliyun.com/repository/public' }
7-
maven { url 'https://maven.aliyun.com/repository/google' }
8-
// 华为开源镜像:https://mirrors.huaweicloud.com/
9-
maven { url 'https://repo.huaweicloud.com/repository/maven/' }
10-
// JitPack 远程仓库:https://jitpack.io
11-
maven { url 'https://jitpack.io' }
12-
mavenCentral()
13-
google()
14-
// noinspection JcenterRepositoryObsolete
15-
jcenter()
16-
}
17-
dependencies {
18-
classpath 'com.android.tools.build:gradle:4.1.2'
19-
}
20-
}
21-
22-
allprojects {
23-
repositories {
24-
maven { url 'https://maven.aliyun.com/repository/public' }
25-
maven { url 'https://maven.aliyun.com/repository/google' }
26-
maven { url 'https://repo.huaweicloud.com/repository/maven/' }
27-
maven { url 'https://jitpack.io' }
28-
mavenCentral()
29-
google()
30-
// noinspection JcenterRepositoryObsolete
31-
jcenter()
32-
}
33-
34-
// 读取 local.properties 文件配置
35-
def properties = new Properties()
36-
def localPropertiesFile = rootProject.file("local.properties")
37-
if (localPropertiesFile.exists()) {
38-
localPropertiesFile.withInputStream { inputStream ->
39-
properties.load(inputStream)
40-
}
41-
}
42-
43-
String buildDirPath = properties.getProperty("build.dir")
44-
if (buildDirPath != null && buildDirPath != "") {
45-
// 将构建文件统一输出到指定的目录下
46-
setBuildDir(new File(buildDirPath, rootProject.name + "/build/${path.replaceAll(':', '/')}"))
47-
} else {
48-
// 将构建文件统一输出到项目根目录下的 build 文件夹
49-
setBuildDir(new File(rootDir, "build/${path.replaceAll(':', '/')}"))
50-
}
1+
plugins {
2+
id 'com.android.application' version '8.4.2' apply false
3+
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
514
}
525

536
tasks.register('clean', Delete) {

common.gradle

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

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ zipStoreBase = GRADLE_USER_HOME
22
zipStorePath = wrapper/dists
33
distributionBase = GRADLE_USER_HOME
44
distributionPath = wrapper/dists
5-
distributionUrl = https\://services.gradle.org/distributions/gradle-6.5-all.zip
5+
distributionUrl = https\://services.gradle.org/distributions/gradle-8.9-bin.zip

library/build.gradle

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

34
android {
4-
compileSdkVersion 33
5+
6+
namespace 'com.hjq.toast'
57

68
defaultConfig {
79
minSdkVersion 14
8-
versionCode 1302
9-
versionName "13.2"
10-
}
11-
12-
// 使用 JDK 1.8
13-
compileOptions {
14-
targetCompatibility JavaVersion.VERSION_1_8
15-
sourceCompatibility JavaVersion.VERSION_1_8
1610
}
1711

18-
packagingOptions {
19-
// 剔除这个包下的所有文件(不会移除签名信息)
20-
exclude 'META-INF/*******'
21-
}
22-
23-
android.libraryVariants.configureEach { variant ->
24-
// aar 输出文件名配置
25-
variant.outputs.all { output ->
26-
outputFileName = "${rootProject.name}-${android.defaultConfig.versionName}.aar"
12+
libraryVariants.configureEach { variant ->
13+
variant.packageLibraryProvider.configure { packageLib ->
14+
// 剔除 META-INF 目录
15+
packageLib.exclude 'META-INF/'
16+
// 剔除 R.txt 文件
17+
packageLib.exclude 'R.txt'
2718
}
2819
}
29-
}
30-
31-
afterEvaluate {
32-
// 排除 BuildConfig.class 和 R.class
33-
generateReleaseBuildConfig.enabled = false
34-
generateDebugBuildConfig.enabled = false
35-
generateReleaseResValues.enabled = false
36-
generateDebugResValues.enabled = false
37-
}
38-
39-
tasks.withType(Javadoc).configureEach {
40-
options.addStringOption('Xdoclint:none', '-quiet')
41-
options.addStringOption('encoding', 'UTF-8')
42-
options.addStringOption('charSet', 'UTF-8')
43-
}
44-
45-
tasks.register('sourcesJar', Jar) {
46-
from android.sourceSets.main.java.srcDirs
47-
classifier = 'sources'
48-
}
49-
50-
tasks.register('javadoc', Javadoc) {
51-
source = android.sourceSets.main.java.srcDirs
52-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
53-
}
54-
55-
tasks.register('javadocJar', Jar) {
56-
dependsOn javadoc
57-
classifier = 'javadoc'
58-
from javadoc.destinationDir
59-
}
60-
61-
artifacts {
62-
archives javadocJar
63-
archives sourcesJar
6420
}

settings.gradle

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
include ':app', ':library'
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
// 阿里云云效仓库(Gradle 插件):https://maven.aliyun.com/mvn/guide
5+
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
6+
// 阿里云云效仓库:https://maven.aliyun.com/mvn/guide
7+
maven { url 'https://maven.aliyun.com/repository/public' }
8+
maven { url 'https://maven.aliyun.com/repository/google' }
9+
// 华为开源镜像:https://mirrors.huaweicloud.com
10+
maven { url 'https://repo.huaweicloud.com/repository/maven' }
11+
// JitPack 远程仓库:https://jitpack.io
12+
maven { url 'https://jitpack.io' }
13+
// MavenCentral 远程仓库:https://mvnrepository.com
14+
mavenCentral()
15+
// Google 仓库:https://maven.google.com/web/index.html
16+
google()
17+
// noinspection JcenterRepositoryObsolete
18+
jcenter()
19+
}
20+
}
21+
dependencyResolutionManagement {
22+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
23+
repositories {
24+
// 阿里云云效仓库:https://maven.aliyun.com/mvn/guide
25+
maven { url 'https://maven.aliyun.com/repository/public' }
26+
maven { url 'https://maven.aliyun.com/repository/google' }
27+
// 华为开源镜像:https://mirrors.huaweicloud.com
28+
maven { url 'https://repo.huaweicloud.com/repository/maven' }
29+
// JitPack 远程仓库:https://jitpack.io
30+
maven { url 'https://jitpack.io' }
31+
// MavenCentral 远程仓库:https://mvnrepository.com
32+
mavenCentral()
33+
// Google 仓库:https://maven.google.com/web/index.html
34+
google()
35+
// noinspection JcenterRepositoryObsolete
36+
jcenter()
37+
}
38+
}
39+
40+
include ':app'
41+
include ':library'

0 commit comments

Comments
 (0)