build.gradle 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import org.apache.tools.ant.taskdefs.condition.Os
  2. apply plugin: 'com.android.application'
  3. apply plugin: 'com.tencent.vasdolly'
  4. android {
  5. compileSdkVersion = PROP_COMPILE_SDK_VERSION.toInteger()
  6. buildToolsVersion = PROP_BUILD_TOOLS_VERSION
  7. namespace "com.blackart.b22"
  8. repositories {
  9. mavenCentral()
  10. }
  11. defaultConfig {
  12. minSdkVersion PROP_MIN_SDK_VERSION
  13. targetSdkVersion PROP_TARGET_SDK_VERSION
  14. versionCode 7
  15. versionName "1.0"
  16. externalNativeBuild {
  17. ndkBuild {
  18. if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
  19. // skip the NDK Build step if PROP_NDK_MODE is none
  20. targets 'cocos2djs'
  21. arguments 'NDK_TOOLCHAIN_VERSION=clang'
  22. def module_paths = [project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x"),
  23. project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/cocos"),
  24. project.file("D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/external")]
  25. if (Os.isFamily(Os.FAMILY_WINDOWS)) {
  26. arguments 'NDK_MODULE_PATH=' + module_paths.join(";")
  27. } else {
  28. arguments 'NDK_MODULE_PATH=' + module_paths.join(':')
  29. }
  30. arguments '-j' + Runtime.runtime.availableProcessors()
  31. }
  32. }
  33. ndk {
  34. abiFilters PROP_APP_ABI.split(':')
  35. }
  36. }
  37. }
  38. sourceSets.main {
  39. java.srcDirs "../src", "src"
  40. res.srcDirs "../res", 'res'
  41. jniLibs.srcDirs "../libs", 'libs'
  42. manifest.srcFile "AndroidManifest.xml"
  43. }
  44. externalNativeBuild {
  45. ndkBuild {
  46. if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) {
  47. // skip the NDK Build step if PROP_NDK_MODE is none
  48. path "jni/Android.mk"
  49. }
  50. }
  51. }
  52. signingConfigs {
  53. release {
  54. if (project.hasProperty("RELEASE_STORE_FILE")) {
  55. storeFile file(RELEASE_STORE_FILE)
  56. storePassword RELEASE_STORE_PASSWORD
  57. keyAlias RELEASE_KEY_ALIAS
  58. keyPassword RELEASE_KEY_PASSWORD
  59. }
  60. }
  61. }
  62. buildTypes {
  63. release {
  64. debuggable false
  65. jniDebuggable false
  66. renderscriptDebuggable false
  67. minifyEnabled true
  68. shrinkResources true
  69. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  70. if (project.hasProperty("RELEASE_STORE_FILE")) {
  71. signingConfig signingConfigs.release
  72. }
  73. externalNativeBuild {
  74. ndkBuild {
  75. arguments 'NDK_DEBUG=0'
  76. }
  77. }
  78. }
  79. debug {
  80. debuggable true
  81. jniDebuggable true
  82. renderscriptDebuggable true
  83. if (project.hasProperty("RELEASE_STORE_FILE")) {
  84. signingConfig signingConfigs.release
  85. }
  86. externalNativeBuild {
  87. ndkBuild {
  88. arguments 'NDK_DEBUG=1'
  89. }
  90. }
  91. }
  92. }
  93. }
  94. android.applicationVariants.all { variant ->
  95. // delete previous files first
  96. delete "${buildDir}/intermediates/merged_assets/${variant.dirName}"
  97. variant.mergeAssets.doLast {
  98. def sourceDir = "${buildDir}/../../../../.."
  99. copy {
  100. from "${sourceDir}"
  101. include "assets/**"
  102. include "src/**"
  103. include "jsb-adapter/**"
  104. into outputDir
  105. }
  106. copy {
  107. from "${sourceDir}/main.js"
  108. from "${sourceDir}/project.json"
  109. into outputDir
  110. }
  111. }
  112. def outputFileDir = "D:\\b22_client\\apk\\${variant.name}"
  113. println "copy cocos assets"
  114. //variant.getPackageApplicationProvider().get().outputDirectory = new File(outputFileDir)
  115. variant.outputs.all { output ->
  116. def packageLastName = applicationId.substring(applicationId.lastIndexOf(".") + 1, applicationId.length())
  117. if (variant.buildType.name == "debug") {
  118. outputFileName = "${packageLastName}_debug.apk"
  119. } else {
  120. outputFileName = "${packageLastName}_${variant.versionCode}.apk"
  121. }
  122. }
  123. }
  124. tasks.whenTaskAdded { task ->
  125. if (task.name == 'assembleDebug' || task.name == 'assembleRelease') {
  126. task.finalizedBy(copyApkTask, copyApkTaskDest)
  127. }
  128. }
  129. task copyApkTask(type: Copy) {
  130. def buildType = project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') } ? 'release' : 'debug'
  131. def sourceDir = "${buildDir}/outputs/apk/${buildType}"
  132. def uploadDir = "D:\\b22_client\\apk\\upload"
  133. doFirst {
  134. delete uploadDir
  135. file(uploadDir).mkdirs()
  136. }
  137. include '**/*.apk'
  138. from sourceDir
  139. into uploadDir
  140. }
  141. task copyApkTaskDest(type: Copy) {
  142. def buildType = project.gradle.startParameter.taskNames.any { it.toLowerCase().contains('release') } ? 'release' : 'debug'
  143. def sourceDir = "${buildDir}/outputs/apk/${buildType}"
  144. def destDir = "D:\\b22_client\\apk"
  145. include '**/*.apk'
  146. from sourceDir
  147. into destDir
  148. }
  149. // gradle rebuildChannel 配置此任务用于不希望重新构建apk,直接根据指定的apk生成渠道包
  150. rebuildChannel {
  151. channelFile = file("channel.txt")
  152. //指定的apk生成渠道包,文件名中如果有base将被替换为渠道名,否则渠道名将作为前缀
  153. baseApk = new File("D:\\b22_client\\apk\\b22_${android.defaultConfig.versionCode}.apk")
  154. //默认为new File(project.buildDir, "rebuildChannel")
  155. outputDir = new File("D:\\b22_client\\apk\\channel\\")
  156. //快速模式:生成渠道包时不进行校验(速度可以提升10倍以上,默认为false)
  157. fastMode = false
  158. //低内存模式(仅针对V2签名,默认为false):只把签名块、中央目录和EOCD读取到内存,不把最大头的内容块读取到内存,在手机上合成APK时,可以使用该模式
  159. lowMemory = false
  160. }
  161. dependencies {
  162. implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar'])
  163. implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
  164. implementation fileTree(dir: "D:/CocosEditors/Creator/2.4.12/resources/cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar'])
  165. implementation project(':libcocos2dx')
  166. // git https://github.com/Blankj/AndroidUtilCode/blob/master/lib/utilcode/README-CN.md
  167. implementation 'com.blankj:utilcodex:1.31.0'
  168. // facebook-login
  169. implementation 'com.facebook.android:facebook-login:17.0.1'
  170. implementation 'com.facebook.android:audience-network-sdk:6.17.0'
  171. // google-login
  172. implementation 'com.google.android.gms:play-services-auth:19.2.0'
  173. // google-ads
  174. implementation 'com.google.android.gms:play-services-ads:23.3.0'
  175. // google-plasy-bill
  176. def billing_version = "7.0.0"
  177. implementation "com.android.billingclient:billing:$billing_version"
  178. // git https://github.com/Tencent/VasDolly
  179. api 'com.tencent.vasdolly:helper:3.0.6'
  180. }