build: 升级构建工具链并适配现代 Android 插件
- Gradle 升级至 8.13,Android Gradle 插件升级至 8.13.2 - compileSdk/targetSdk 升级至 36,namespace 替代 package - 引入 Kotlin 插件与协程依赖,统一 stdlib 版本 - 精简打包输出命名,移除过时配置与 abiFilters - 修复 manifest exported 属性与 CMake 链接对齐
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
apply plugin: 'com.android.application'
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
id 'org.jetbrains.kotlin.android'
|
||||||
|
// id 'kotlin-kapt'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def appName() {
|
def appName() {
|
||||||
return "Mir4Updater"
|
return "Mir4Updater"
|
||||||
@@ -9,38 +14,40 @@ def releaseTime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 30
|
namespace "com.example.mir4updater"
|
||||||
// buildToolsVersion "34.0.0"
|
|
||||||
|
compileSdkVersion 36
|
||||||
|
buildToolsVersion "36.0.0"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.example.mir4updater"
|
applicationId "com.example.mir4updater"
|
||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 30
|
targetSdkVersion 36
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
vectorDrawables.useSupportLibrary = true
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
//可以根据需要来自行选择并添加对应cpu类型的.so库。
|
//可以根据需要来自行选择并添加对应cpu类型的.so库。
|
||||||
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||||
// 还可以添加 'armeabi', 'x86', 'x86_64', 'mips', 'mips64'
|
// 还可以添加 'armeabi', 'x86', 'x86_64', 'mips', 'mips64'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
}
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
|
|
||||||
vectorDrawables.useSupportLibrary = true
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
viewBinding {
|
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBinding {
|
buildFeatures {
|
||||||
enabled true
|
dataBinding true
|
||||||
}
|
buildConfig true
|
||||||
|
aidl true
|
||||||
}
|
}
|
||||||
|
|
||||||
// splits {
|
// splits {
|
||||||
@@ -84,40 +91,25 @@ android {
|
|||||||
debug {
|
debug {
|
||||||
versionNameSuffix "_debug"
|
versionNameSuffix "_debug"
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
//Zipalign优化
|
|
||||||
zipAlignEnabled true
|
|
||||||
signingConfig signingConfigs.own
|
signingConfig signingConfigs.own
|
||||||
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 {
|
release {
|
||||||
//混淆
|
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
//Zipalign优化
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
zipAlignEnabled true
|
|
||||||
//前一部分代表系统默认的android程序的混淆文件,该文件已经包含了基本的混淆声明,后一个文件是自己的定义混淆文件
|
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
||||||
//签名
|
|
||||||
signingConfig signingConfigs.own
|
signingConfig signingConfigs.own
|
||||||
// 将release版本的包名重命名,加上版本及日期
|
}
|
||||||
applicationVariants.all { variant ->
|
}
|
||||||
variant.outputs.each { output ->
|
|
||||||
def outputFile = ""
|
android.applicationVariants.all { variant ->
|
||||||
if (outputFile != null) {
|
variant.outputs.all { output -> // 改为 all
|
||||||
def fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType.name}.apk"
|
def buildType = variant.buildType.name
|
||||||
output.outputFileName = new File(outputFile, fileName)
|
if (buildType.contains("debug")) {
|
||||||
}
|
outputFileName = "${appName()}_V${defaultConfig.versionName}_${releaseTime()}.apk"
|
||||||
}
|
} else {
|
||||||
|
outputFileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType}.apk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -126,6 +118,14 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation project(path: ':ttutils')
|
implementation project(path: ':ttutils')
|
||||||
|
|
||||||
|
// 添加 Kotlin 标准库
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
// 添加这行,使用 BOM 统一 Kotlin 相关库的版本
|
||||||
|
implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version"))
|
||||||
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0'
|
||||||
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.11.0'
|
||||||
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-rx3:1.11.0'
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
implementation "androidx.recyclerview:recyclerview:1.2.1"
|
implementation "androidx.recyclerview:recyclerview:1.2.1"
|
||||||
|
|||||||
@@ -31,14 +31,16 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".activity.main.MainActivity">
|
<activity android:name=".activity.main.MainActivity"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".activity.xapk.XapkHandlerActivity">
|
<activity android:name=".activity.xapk.XapkHandlerActivity"
|
||||||
|
android:exported="true">
|
||||||
<!--from apkpure-->
|
<!--from apkpure-->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|||||||
35
build.gradle
35
build.gradle
@@ -1,22 +1,23 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
ext.kotlin_version = '2.4.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://jitpack.io" }
|
maven { url 'https://jitpack.io' }
|
||||||
|
maven { url 'https://maven.google.com' }
|
||||||
maven { url 'https://developer.huawei.com/repo/' }
|
maven { url 'https://developer.huawei.com/repo/' }
|
||||||
maven { url 'https://developer.hihonor.com/repo' }
|
maven { url 'https://developer.hihonor.com/repo' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/central' }
|
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/public' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/google' }
|
maven { url 'https://maven.aliyun.com/repository/google' }
|
||||||
|
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.6.4'
|
classpath 'com.android.tools.build:gradle:8.13.2'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
@@ -24,23 +25,27 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
configurations.all {
|
|
||||||
resolutionStrategy {
|
|
||||||
force 'androidx.constraintlayout:constraintlayout:2.0.4'
|
|
||||||
force 'androidx.annotation:annotation:1.4.0' // 强制所有依赖使用 1.4.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url "https://jitpack.io" }
|
maven { url 'https://jitpack.io' }
|
||||||
|
maven { url 'https://maven.google.com' }
|
||||||
maven { url 'https://developer.huawei.com/repo/' }
|
maven { url 'https://developer.huawei.com/repo/' }
|
||||||
maven { url 'https://developer.hihonor.com/repo' }
|
maven { url 'https://developer.hihonor.com/repo' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/central' }
|
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/public' }
|
||||||
maven { url 'https://maven.aliyun.com/repository/google' }
|
maven { url 'https://maven.aliyun.com/repository/google' }
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations.all {
|
||||||
|
resolutionStrategy.eachDependency { details ->
|
||||||
|
if (details.requested.group == 'org.jetbrains.kotlin') {
|
||||||
|
// 统一所有 Kotlin 标准库及扩展模块的版本,避免重复类冲突
|
||||||
|
details.useVersion '1.8.10'
|
||||||
|
details.because '统一 Kotlin stdlib 版本以解决 duplicate class 冲突'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.4.1)
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
|
||||||
|
project(ttutils)
|
||||||
|
|
||||||
# Creates and names a library, sets it as either STATIC
|
# Creates and names a library, sets it as either STATIC
|
||||||
# or SHARED, and provides the relative paths to its source code.
|
# or SHARED, and provides the relative paths to its source code.
|
||||||
# You can define multiple libraries, and CMake builds them for you.
|
# You can define multiple libraries, and CMake builds them for you.
|
||||||
@@ -54,4 +56,6 @@ target_link_libraries( # Specifies the target library.
|
|||||||
|
|
||||||
# Links the target library to the log library
|
# Links the target library to the log library
|
||||||
# included in the NDK.
|
# included in the NDK.
|
||||||
${log-lib})
|
${log-lib})
|
||||||
|
|
||||||
|
set_target_properties(ttutils PROPERTIES LINK_FLAGS "-Wl,-z,max-page-size=16384")
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
namespace "com.ttstd.ttutils"
|
||||||
|
|
||||||
compileSdkVersion 34
|
compileSdkVersion 34
|
||||||
// buildToolsVersion "34.0.0"
|
// buildToolsVersion "34.0.0"
|
||||||
|
|
||||||
@@ -21,7 +23,7 @@ android {
|
|||||||
// build.gradle中移除armeabi mips等
|
// build.gradle中移除armeabi mips等
|
||||||
|
|
||||||
//选择要添加的对应 cpu 类型的 .so 库。
|
//选择要添加的对应 cpu 类型的 .so 库。
|
||||||
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||||
// 还可以添加 'armeabi', 'x86', 'x86_64', 'mips', 'mips64'
|
// 还可以添加 'armeabi', 'x86', 'x86_64', 'mips', 'mips64'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest package="com.ttstd.ttutils" />
|
||||||
package="com.ttstd.ttutils" />
|
|
||||||
|
|||||||
Reference in New Issue
Block a user