build.gradle 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import java.text.SimpleDateFormat
  2. def localProperties = new Properties()
  3. def localPropertiesFile = rootProject.file('local.properties')
  4. if (localPropertiesFile.exists()) {
  5. localPropertiesFile.withReader('UTF-8') { reader ->
  6. localProperties.load(reader)
  7. }
  8. }
  9. def flutterRoot = localProperties.getProperty('flutter.sdk')
  10. if (flutterRoot == null) {
  11. throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
  12. }
  13. def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  14. if (flutterVersionCode == null) {
  15. flutterVersionCode = '1'
  16. }
  17. def flutterVersionName = localProperties.getProperty('flutter.versionName')
  18. if (flutterVersionName == null) {
  19. flutterVersionName = '1.0'
  20. }
  21. apply plugin: 'com.android.application'
  22. apply plugin: 'kotlin-android'
  23. apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
  24. android {
  25. compileSdkVersion 30
  26. // ndkVersion "21.3.6528147"
  27. sourceSets {
  28. main.java.srcDirs += 'src/main/kotlin'
  29. }
  30. applicationVariants.all { variant ->
  31. variant.outputs.all {
  32. def versionName = defaultConfig.versionName
  33. def date = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
  34. if (variant.buildType.name == 'release') {
  35. outputFileName = "ctjt_flutter_${variant.buildType.name}_${versionName}_${date}.apk"
  36. } else if (variant.buildType.name == 'debug') {
  37. outputFileName = "ctjt_flutter_${versionName}_${date}.apk"
  38. }
  39. }
  40. }
  41. signingConfigs {
  42. debug {
  43. storeFile file('android_key.keystore')
  44. storePassword 'abcd1234'
  45. keyAlias 'ctjt_flutter'
  46. keyPassword 'abcd1234'
  47. }
  48. release {
  49. storeFile file('android_key.keystore')
  50. storePassword 'abcd1234'
  51. keyAlias 'ctjt_flutter'
  52. keyPassword 'abcd1234'
  53. }
  54. }
  55. lintOptions {
  56. disable 'InvalidPackage'
  57. //如打包出现Failed to transform libs.jar to match attributes
  58. //checkReleaseBuilds false
  59. }
  60. defaultConfig {
  61. // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  62. applicationId "com.example.ctjt_flutter"
  63. minSdkVersion 19
  64. targetSdkVersion 30
  65. versionCode flutterVersionCode.toInteger()
  66. versionName flutterVersionName
  67. multiDexEnabled true
  68. // Bugly相关配置
  69. // ndk {
  70. // //设置支持的SO库架构
  71. // abiFilters 'armeabi-v7a'//, 'arm64-v8a', 'x86', 'x86_64'
  72. // }
  73. }
  74. buildTypes {
  75. debug {
  76. signingConfig signingConfigs.debug
  77. }
  78. release {
  79. // Signing with the debug keys for now, so `flutter run --release` works.
  80. //signingConfig signingConfigs.debug
  81. signingConfig signingConfigs.release
  82. minifyEnabled false // 资源压缩设置
  83. shrinkResources false // 删除无用资源
  84. useProguard true // 代码压缩设置
  85. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // 读取代码压缩配置文件
  86. }
  87. }
  88. }
  89. flutter {
  90. source '../..'
  91. }
  92. dependencies {
  93. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  94. // 引入support支持库的multidex库
  95. implementation 'com.android.support:multidex:1.0.3'
  96. }