build.gradle 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. apply plugin: 'com.android.application'
  2. // NOTE!!! 重要!!! aar需要kotlin支持,不引入会导致小程序打不开.
  3. apply plugin: 'kotlin-android'
  4. apply plugin: 'kotlin-android-extensions'
  5. android {
  6. useLibrary 'org.apache.http.legacy'
  7. compileSdkVersion rootProject.ext.compileSdkVersion
  8. buildToolsVersion rootProject.ext.buildToolsVersion
  9. def miniAppConfig = rootProject.ext.miniAppConfig
  10. defaultConfig {
  11. buildConfigField "String", "SDK_KEY", "\"$miniAppConfig.sdkKey\""
  12. buildConfigField "String", "SDK_KEY_SECRET", "\"$miniAppConfig.sdkKeySecret\""
  13. buildConfigField "Boolean", "SPLASHSCREEN", "$miniAppConfig.splashscreen"
  14. buildConfigField "String", "ENABLE_VCONSOLE", "\"$miniAppConfig.enableVConsole\""
  15. buildConfigField "Boolean", "PRIVACY_POPUP", "$miniAppConfig.privacyPopup"
  16. buildConfigField "Boolean", "APP_MENU_ENABLE", "$miniAppConfig.appMenuEnable"
  17. buildConfigField "String", "SCHEME", "\"$miniAppConfig.scheme\""
  18. manifestPlaceholders = [
  19. MINIAPP_SCHEME : miniAppConfig.scheme,
  20. ]
  21. }
  22. signingConfigs {
  23. debug {
  24. keyAlias 'androiddebugkey'
  25. keyPassword 'android'
  26. storeFile rootProject.file('compile/debug.keystore')
  27. storePassword 'android'
  28. }
  29. // 使用该 test.jks 生成的 应用签名 md5 为 d8d9a7134de382c19ff2a42a287ec627
  30. release {
  31. keyAlias 'test'
  32. keyPassword '12345678'
  33. storeFile file('./sign/test2.jks')
  34. storePassword '12345678'
  35. }
  36. }
  37. defaultConfig {
  38. multiDexEnabled true
  39. versionName miniAppConfig.version
  40. versionCode miniAppConfig.versionCode
  41. minSdkVersion rootProject.ext.minSdkVersion
  42. targetSdkVersion rootProject.ext.targetSdkVersion
  43. }
  44. buildTypes {
  45. debug {
  46. debuggable true
  47. signingConfig signingConfigs.debug
  48. minifyEnabled false
  49. shrinkResources false
  50. }
  51. release {
  52. debuggable false
  53. signingConfig signingConfigs.release
  54. minifyEnabled true
  55. shrinkResources true
  56. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  57. }
  58. }
  59. packagingOptions {
  60. exclude 'META-INF/DEPENDENCIES'
  61. exclude 'META-INF/NOTICE'
  62. exclude 'META-INF/LICENSE'
  63. exclude 'META-INF/LICENSE.txt'
  64. exclude 'META-INF/NOTICE.txt'
  65. }
  66. flavorDimensions 'abi'
  67. productFlavors {
  68. arm {
  69. dimension 'abi'
  70. ndk {
  71. abiFilters "arm64-v8a", "armeabi-v7a"
  72. }
  73. }
  74. arm32 {
  75. dimension 'abi'
  76. ndk {
  77. abiFilter "armeabi-v7a"
  78. }
  79. }
  80. arm64 {
  81. dimension 'abi'
  82. ndk {
  83. abiFilter "arm64-v8a"
  84. }
  85. }
  86. }
  87. lintOptions {
  88. checkReleaseBuilds false
  89. abortOnError false
  90. }
  91. compileOptions {
  92. sourceCompatibility = 1.8
  93. targetCompatibility = 1.8
  94. }
  95. }
  96. // def wxa_sdk_version = rootProject.ext.miniAppConfig.sdkVersion
  97. def wxa_sdk_version = rootProject.ext.saaaSDKVersionDepend
  98. def miniAppPluginConfig = rootProject.ext.miniAppPluginConfig
  99. def libsDir = file("./libs")
  100. if (!file("$libsDir/com/tencent/luggage/wxa-standalone-open-runtime-SaaA-plugin-sdk/${wxa_sdk_version}").exists()) {
  101. libsDir.mkdir()
  102. apply plugin: 'de.undercouch.download'
  103. def zipFileName = "wxa-standalone-open-runtime-SaaA-sdk-all-${wxa_sdk_version}.zip"
  104. download.run {
  105. src "https://dldir1.qq.com/WechatWebDev/donut/android/pluginsdk/${zipFileName}"
  106. dest libsDir
  107. }
  108. def zipFilePath = "$libsDir/$zipFileName"
  109. copy {
  110. def subDir = 'localAar'
  111. from {
  112. zipTree(zipFilePath).matching { include "$subDir/**" }
  113. }
  114. into libsDir
  115. eachFile { fcp ->
  116. fcp.path = fcp.path.replaceFirst("^$subDir", '')
  117. }
  118. includeEmptyDirs false
  119. }
  120. file(zipFilePath).delete()
  121. }
  122. task updateResource {
  123. doFirst {
  124. println "[I] start connect with devtools"
  125. def url = miniAppPluginConfig.devtoolsResourceUrl
  126. def shouldInterrupt = false
  127. try {
  128. println "[I] url: $url"
  129. def response = new URL(url).getText()
  130. println("[I] response: $response")
  131. if (response.contains("success")) {
  132. // 请求成功
  133. println("[I] update Android resource done")
  134. } else {
  135. shouldInterrupt = true
  136. }
  137. } catch (Exception e) {
  138. println("[W] connecting with devtools fail.." + e.getMessage())
  139. }
  140. if (shouldInterrupt) {
  141. throw new GradleException("update Android resource fail")
  142. }
  143. }
  144. }
  145. preBuild.dependsOn updateResource
  146. dependencies {
  147. if (miniAppPluginConfig.debugWithAar) {
  148. def sdkName = miniAppPluginConfig.pluginId
  149. def sdkVersion = miniAppPluginConfig.pluginVersion
  150. implementation("com.donut.plugin:${sdkName}:${sdkVersion}")
  151. println("[I] Use Aar")
  152. } else {
  153. implementation project(path: ':plugin')
  154. println("[I] Use Source Code")
  155. }
  156. def miniAppConfig = rootProject.ext.miniAppConfig
  157. implementation("com.tencent.luggage:wxa-standalone-open-runtime-SaaA-plugin-sdk:${wxa_sdk_version}")
  158. }