From d0180b77d4f6959328332977900a6638bb907888 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Tue, 2 Jun 2026 16:50:26 +0800 Subject: [PATCH] build: upgrade build.gradle to run in Android Studio panda 4 --- FlycoTabLayoutZ_Lib/build.gradle | 2 + app/build.gradle | 129 ++++++++---------- .../java/com/fuying/sn/dialog/InfoDialog.java | 2 +- build.gradle | 38 +++++- gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 94 insertions(+), 79 deletions(-) diff --git a/FlycoTabLayoutZ_Lib/build.gradle b/FlycoTabLayoutZ_Lib/build.gradle index 09c8a19..af405d7 100644 --- a/FlycoTabLayoutZ_Lib/build.gradle +++ b/FlycoTabLayoutZ_Lib/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'com.android.library' version = "1.3.3" android { + namespace 'com.flyco.tablayout' + compileSdkVersion 28 buildToolsVersion "28.0.3" diff --git a/app/build.gradle b/app/build.gradle index 7364729..4668fa8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,23 +5,11 @@ static def appName() { } static def releaseTime() { - return new Date().format("yyyyMMdd-HHmmss", TimeZone.getDefault()) + return new Date().format("yyyyMMdd_HHmmss", TimeZone.getDefault()) } android { -// gradle.projectsEvaluated { -// tasks.withType(JavaCompile) { -// Set fileSet = options.bootstrapClasspath.getFiles() -// List newFileList = new ArrayList<>(); -// //JAVA语法,可连续调用,输入参数建议为相对路径 -// newFileList.add(new File("libs/framework.jar")) -// //最后将原始参数添加 -// newFileList.addAll(fileSet) -// options.bootstrapClasspath = files( -// newFileList.toArray() -// ) -// } -// } + namespace "com.fuying.sn" compileSdkVersion 29 buildToolsVersion "29.0.3" @@ -39,25 +27,24 @@ android { // 还可以添加 'x86', 'x86_64', 'mips', 'mips64' } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - javaCompileOptions { - annotationProcessorOptions { - includeCompileClasspath true - } - } - lintOptions { checkReleaseBuilds false + // Or, if you prefer, you can continue to check for errors in release builds, + // but continue the build even when errors are found: + abortOnError false } - dataBinding { - enabled true - } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + buildFeatures { + dataBinding true + buildConfig true + aidl true } //多版本 @@ -460,14 +447,6 @@ android { zipAlignEnabled true minifyEnabled false signingConfig signingConfigs.mtk - applicationVariants.all { variant -> - variant.outputs.each { output -> - if (outputFile != null) { - def fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType.name}.apk" - output.outputFileName = fileName - } - } - } } release { @@ -480,28 +459,28 @@ android { //混淆 minifyEnabled false //前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件 - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' //签名 signingConfig signingConfigs.mtk -// 将release版本的包名重命名,加上版本及日期 - applicationVariants.all { variant -> - variant.outputs.each { output -> - def outputFile = "" - if (outputFile != null) { - def fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType.name}.apk" - output.outputFileName = new File(outputFile, fileName) - } - } - } } } - lintOptions { - checkReleaseBuilds false - // Or, if you prefer, you can continue to check for errors in release builds, - // but continue the build even when errors are found: - abortOnError false + // Add application variant configuration here instead + applicationVariants.all { variant -> + variant.outputs.each { output -> + def buildType = variant.buildType.name + def fileName = "" + + if (buildType.contains("debug")) { + fileName = "${appName()}_V${defaultConfig.versionName}_${releaseTime()}.apk" + } else { + fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType}.apk" + } + + output.outputFileName = fileName + } } + } dependencies { @@ -581,23 +560,33 @@ dependencies { implementation 'com.github.getActivity:Toaster:12.6' } -preBuild { - doLast { - def imlFile = file(project.name + ".iml") - println 'Change ' + project.name + '.iml order' - try { - def parsedXml = (new XmlParser()).parse(imlFile) - def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' } - parsedXml.component[1].remove(jdkNode) - def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform" - println 'what' + sdkString - new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK']) - groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile)) - } catch (FileNotFoundException e) { - // nop, iml not found - println "no iml found" - } +// 在 dependencies 之后添加 +project.afterEvaluate { + android.applicationVariants.all { variant -> + variant.javaCompileProvider.get().options.bootstrapClasspath = files( + file('libs/framework.jar'), + android.getBootClasspath() + ) } - //https://www.pianshen.com/article/93481144911/ - //使用系统编译后的framework.jar } + +//preBuild { +// doLast { +// def imlFile = file(project.name + ".iml") +// println 'Change ' + project.name + '.iml order' +// try { +// def parsedXml = (new XmlParser()).parse(imlFile) +// def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' } +// parsedXml.component[1].remove(jdkNode) +// def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform" +// println 'what' + sdkString +// new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK']) +// groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile)) +// } catch (FileNotFoundException e) { +// // nop, iml not found +// println "no iml found" +// } +// } +// //https://www.pianshen.com/article/93481144911/ +// //使用系统编译后的framework.jar +//} diff --git a/app/src/main/java/com/fuying/sn/dialog/InfoDialog.java b/app/src/main/java/com/fuying/sn/dialog/InfoDialog.java index ae8896a..e11253c 100644 --- a/app/src/main/java/com/fuying/sn/dialog/InfoDialog.java +++ b/app/src/main/java/com/fuying/sn/dialog/InfoDialog.java @@ -35,7 +35,7 @@ public class InfoDialog extends Dialog { private InfoDialog mDialog; public Builder(Context context) { - mDialog = new InfoDialog(context, R.style.Theme_AppCompat_Dialog); + mDialog = new InfoDialog(context, R.style.CustomDialog); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //加载布局文件 diff --git a/build.gradle b/build.gradle index f863ec5..bde2601 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,22 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '2.3.21' + repositories { google() -// mavenCentral() - maven { url "https://jitpack.io" } + mavenCentral() + maven { url 'https://jitpack.io' } + maven { url 'https://maven.google.com' } maven { url 'https://developer.huawei.com/repo/' } maven { url 'https://developer.hihonor.com/repo' } maven { url 'https://maven.aliyun.com/repository/central' } - maven { url "https://maven.aliyun.com/repository/jcenter" } + maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } } dependencies { - classpath 'com.android.tools.build:gradle:3.6.4' + classpath 'com.android.tools.build:gradle:8.13.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -21,17 +24,38 @@ buildscript { } allprojects { + configurations.all { + resolutionStrategy { + force 'androidx.constraintlayout:constraintlayout:2.0.4' + force 'androidx.annotation:annotation:1.1.0' + + //for targetSdkVersion 29 + force 'androidx.lifecycle:lifecycle-livedata:2.3.1' + force 'androidx.lifecycle:lifecycle-livedata-core:2.3.1' + force 'androidx.lifecycle:lifecycle-runtime:2.3.1' + force 'androidx.lifecycle:lifecycle-viewmodel:2.3.1' + force 'androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1' + force 'androidx.savedstate:savedstate:1.1.0' + force 'androidx.profileinstaller:profileinstaller:1.1.0' + force 'androidx.startup:startup-runtime:1.0.0' + force 'androidx.arch.core:core-runtime:2.1.0' + + } + } + repositories { google() -// mavenCentral() - maven { url "https://jitpack.io" } + mavenCentral() + maven { url 'https://jitpack.io' } + maven { url 'https://maven.google.com' } maven { url 'https://developer.huawei.com/repo/' } maven { url 'https://developer.hihonor.com/repo' } maven { url 'https://maven.aliyun.com/repository/central' } - maven { url "https://maven.aliyun.com/repository/jcenter" } + maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/google' } } + gradle.projectsEvaluated { tasks.withType(JavaCompile) { //设置jar相对包路径或绝对路径 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index edb85c2..b4d3ae7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip