build.gradle 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. apply plugin: 'com.android.application'
  2. RES_PATH = RES_PATH.replace("\\", "/")
  3. COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/")
  4. buildDir = "${RES_PATH}/proj/build/${project.name ==~ /^[_a-zA-Z0-9-]+$/ ? project.name : 'CocosGame'}"
  5. android {
  6. compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
  7. buildToolsVersion PROP_BUILD_TOOLS_VERSION
  8. ndkPath PROP_NDK_PATH
  9. namespace NAME_SPACE
  10. compileOptions {
  11. sourceCompatibility JavaVersion.VERSION_1_8
  12. targetCompatibility JavaVersion.VERSION_1_8
  13. }
  14. defaultConfig {
  15. applicationId APPLICATION_ID
  16. minSdkVersion PROP_MIN_SDK_VERSION
  17. targetSdkVersion PROP_TARGET_SDK_VERSION
  18. versionCode 100
  19. versionName "1.0.0"
  20. externalNativeBuild {
  21. cmake {
  22. targets "cocos"
  23. arguments "-DRES_DIR=${RES_PATH}", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
  24. }
  25. ndk { abiFilters PROP_APP_ABI.split(':') }
  26. }
  27. }
  28. sourceSets.main {
  29. java.srcDirs "../src", "src"
  30. res.srcDirs "../res", 'res', "${RES_PATH}/proj/res"
  31. jniLibs.srcDirs "../libs", 'libs'
  32. manifest.srcFile "AndroidManifest.xml"
  33. assets.srcDirs "${RES_PATH}/data", "src/main/assets"
  34. jniLibs {
  35. // Vulkan validation layer
  36. // srcDir "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"
  37. }
  38. }
  39. externalNativeBuild {
  40. cmake {
  41. version "3.22.1"
  42. path "../CMakeLists.txt"
  43. buildStagingDirectory "${RES_PATH}/proj/build"
  44. }
  45. }
  46. signingConfigs {
  47. release {
  48. if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
  49. storeFile file(RELEASE_STORE_FILE)
  50. storePassword RELEASE_STORE_PASSWORD
  51. keyAlias RELEASE_KEY_ALIAS
  52. keyPassword RELEASE_KEY_PASSWORD
  53. }
  54. }
  55. }
  56. def appName = URLDecoder.decode("${PROP_APP_NAME}", "UTF-8")
  57. buildTypes {
  58. release {
  59. debuggable false
  60. jniDebuggable false
  61. renderscriptDebuggable false
  62. minifyEnabled true
  63. shrinkResources true
  64. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  65. if (project.hasProperty("RELEASE_STORE_FILE")) {
  66. signingConfig signingConfigs.release
  67. }
  68. externalNativeBuild {
  69. cmake {
  70. // switch HIDE_SYMBOLS to OFF to skip compilation flag `-fvisibility=hidden`
  71. arguments "-DHIDE_SYMBOLS=ON"
  72. }
  73. }
  74. if (!Boolean.parseBoolean(PROP_IS_DEBUG)) {
  75. getIsDefault().set(true)
  76. }
  77. resValue "string", "app_name", "${appName}"
  78. buildConfigField "String", "ATMOB_CENTRAL_APP_KEY", "\"$atmob_central_app_key\""
  79. buildConfigField "String", "GRAVITY_ACCESS_TOKEN", "\"$gravity_access_token\""
  80. buildConfigField "String", "TEST_CHANNEL", "\"$test_channel\""
  81. buildConfigField "String", "YIDUN_PRODUCT_ID", "\"$yidun_product_id\""
  82. buildConfigField "String", "YIDUN_REGISTER_BUSINESS_ID", "\"$yidun_register_business_id\""
  83. buildConfigField "String", "WECHAT_APP_ID", "\"$wechat_app_id\""
  84. buildConfigField "String", "ALIPAY_APP_ID", "\"$alipay_app_id\""
  85. buildConfigField "String", "PROD_SERVER_HOST", "\"$prod_server_host\""
  86. buildConfigField "String", "TEST_SERVER_HOST", "\"$test_server_host\""
  87. buildConfigField "boolean", "IS_PROD_SERVER", "true"
  88. }
  89. debug {
  90. debuggable true
  91. jniDebuggable true
  92. renderscriptDebuggable true
  93. minifyEnabled false
  94. shrinkResources false
  95. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  96. if (project.hasProperty("RELEASE_STORE_FILE")) {
  97. signingConfig signingConfigs.release
  98. }
  99. externalNativeBuild {
  100. cmake {
  101. // switch HIDE_SYMBOLS to OFF to skip compilation flag `-fvisibility=hidden`
  102. arguments "-DHIDE_SYMBOLS=ON"
  103. }
  104. }
  105. if (!Boolean.parseBoolean(PROP_IS_DEBUG)) {
  106. getIsDefault().set(true)
  107. }
  108. resValue "string", "app_name", "${appName}-debug"
  109. buildConfigField "String", "ATMOB_CENTRAL_APP_KEY", "\"$atmob_central_app_key\""
  110. buildConfigField "String", "GRAVITY_ACCESS_TOKEN", "\"$gravity_access_token\""
  111. buildConfigField "String", "TEST_CHANNEL", "\"$test_channel\""
  112. buildConfigField "String", "YIDUN_PRODUCT_ID", "\"$yidun_product_id\""
  113. buildConfigField "String", "YIDUN_REGISTER_BUSINESS_ID", "\"$yidun_register_business_id\""
  114. buildConfigField "String", "WECHAT_APP_ID", "\"$wechat_app_id\""
  115. buildConfigField "String", "ALIPAY_APP_ID", "\"$alipay_app_id\""
  116. buildConfigField "String", "PROD_SERVER_HOST", "\"$prod_server_host\""
  117. buildConfigField "String", "TEST_SERVER_HOST", "\"$test_server_host\""
  118. buildConfigField "boolean", "IS_PROD_SERVER", "false"
  119. }
  120. }
  121. buildFeatures {
  122. buildConfig = true
  123. }
  124. configurations.configureEach {
  125. resolutionStrategy {
  126. // don't cache changing modules at all
  127. cacheChangingModulesFor 10, 'seconds'
  128. }
  129. }
  130. applicationVariants.configureEach { variant ->
  131. def date = new Date().format("YYMMddHHmmss")
  132. variant.outputs.configureEach {
  133. def fileName = "${defaultConfig.applicationId}" +
  134. "-v${defaultConfig.versionName}" +
  135. "-${variant.buildType.name}" +
  136. "-${date}" +
  137. ".apk"
  138. outputFileName = fileName
  139. }
  140. }
  141. }
  142. dependencies {
  143. implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar'])
  144. implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
  145. implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar'])
  146. implementation project(':libservice')
  147. implementation project(':libcocos')
  148. if (Boolean.parseBoolean(PROP_ENABLE_INPUTSDK)) {
  149. implementation 'com.google.android.libraries.play.games:inputmapping:1.1.0-beta'
  150. implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
  151. }
  152. implementation "atmob.central:cocos-bridge:0.0.1-SNAPSHOT"
  153. implementation "androidx.constraintlayout:constraintlayout:2.1.4"
  154. }