131 lines
4.1 KiB
Groovy
131 lines
4.1 KiB
Groovy
// 应用插件
|
||
plugins {
|
||
// Android应用程序插件,用于构建Android应用
|
||
id "com.android.application"
|
||
// Kotlin Android插件,支持Kotlin语言开发
|
||
id "kotlin-android"
|
||
// Flutter Gradle插件,用于集成Flutter框架
|
||
id "dev.flutter.flutter-gradle-plugin"
|
||
}
|
||
|
||
// 定义局部属性变量
|
||
def localProperties = new Properties()
|
||
// 获取local.properties文件
|
||
def localPropertiesFile = rootProject.file('local.properties')
|
||
// 如果local.properties文件存在,则加载其内容
|
||
if (localPropertiesFile.exists()) {
|
||
localPropertiesFile.withReader('UTF-8') { reader ->
|
||
localProperties.load(reader)
|
||
}
|
||
}
|
||
|
||
// 从local.properties中获取Flutter版本代码,如果不存在则默认为'1'
|
||
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
|
||
if (flutterVersionCode == null) {
|
||
flutterVersionCode = '1'
|
||
}
|
||
|
||
// 从local.properties中获取Flutter版本名称,如果不存在则默认为'1.0'
|
||
def flutterVersionName = localProperties.getProperty('flutter.versionName')
|
||
if (flutterVersionName == null) {
|
||
flutterVersionName = '1.0'
|
||
}
|
||
// 获取签名密码
|
||
def keystoreProperties = new Properties()
|
||
def keystorePropertiesFile = rootProject.file('key.properties')
|
||
if (keystorePropertiesFile.exists()) {
|
||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||
}
|
||
|
||
// Android配置块
|
||
android {
|
||
// 应用程序的命名空间
|
||
namespace "com.example.starwork_flutter"
|
||
// 编译SDK版本,使用Flutter配置的版本
|
||
compileSdk flutter.compileSdkVersion
|
||
// NDK版本,使用Flutter配置的版本
|
||
ndkVersion flutter.ndkVersion
|
||
|
||
// Java编译选项
|
||
compileOptions {
|
||
// 源代码兼容性设置为Java 1.8
|
||
sourceCompatibility JavaVersion.VERSION_1_8
|
||
// 目标兼容性设置为Java 1.8
|
||
targetCompatibility JavaVersion.VERSION_1_8
|
||
}
|
||
|
||
// Kotlin编译选项
|
||
kotlinOptions {
|
||
// JVM目标版本设置为1.8
|
||
jvmTarget = '1.8'
|
||
}
|
||
|
||
// 源代码集配置
|
||
sourceSets {
|
||
// 添加Kotlin源代码目录
|
||
main.java.srcDirs += 'src/main/kotlin'
|
||
}
|
||
|
||
// 默认配置
|
||
defaultConfig {
|
||
// 应用程序ID,唯一标识符
|
||
applicationId "com.example.starwork_flutter"
|
||
// 最小SDK版本,设置为25
|
||
minSdkVersion 25
|
||
// 目标SDK版本,设置为35
|
||
targetSdkVersion 35
|
||
// 版本代码,用于应用商店区分版本
|
||
versionCode flutterVersionCode.toInteger()
|
||
// 版本名称,用户可见的版本号
|
||
versionName flutterVersionName
|
||
// 设置支持的ABI架构
|
||
ndk {
|
||
// abiFilters "arm64-v8a"
|
||
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||
}
|
||
}
|
||
|
||
// 👇 添加 signingConfigs
|
||
// 对应flavorizr.gradle中的 signingConfig 属性
|
||
signingConfigs {
|
||
debug {
|
||
// 使用默认 debug 签名(无需配置)
|
||
}
|
||
sky {
|
||
keyAlias keystoreProperties['sky.keyAlias']
|
||
keyPassword keystoreProperties['sky.keyPassword']
|
||
storeFile keystoreProperties['sky.storeFile'] ? file(keystoreProperties['sky.storeFile']) : null
|
||
storePassword keystoreProperties['sky.storePassword']
|
||
}
|
||
|
||
xhj {
|
||
keyAlias keystoreProperties['xhj.keyAlias']
|
||
keyPassword keystoreProperties['xhj.keyPassword']
|
||
storeFile keystoreProperties['xhj.storeFile'] ? file(keystoreProperties['sky.storeFile']) : null
|
||
storePassword keystoreProperties['xhj.storePassword']
|
||
}
|
||
}
|
||
|
||
// 构建类型配置
|
||
buildTypes {
|
||
debug {
|
||
signingConfig signingConfigs.debug
|
||
}
|
||
release {
|
||
// release 类型根据 flavor 使用不同签名
|
||
}
|
||
}
|
||
}
|
||
|
||
// Flutter配置块
|
||
flutter {
|
||
// Flutter源代码路径
|
||
source '../..'
|
||
}
|
||
|
||
// 依赖项配置
|
||
// 目前没有添加任何依赖项
|
||
dependencies {}
|
||
// ----- BEGIN flavorDimensions (autogenerated by flutter_flavorizr) -----
|
||
apply from: "flavorizr.gradle"
|
||
// ----- END flavorDimensions (autogenerated by flutter_flavorizr) ----- |