build.gradle 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. apply plugin: "com.android.application"
  2. apply plugin: "org.jetbrains.kotlin.android"
  3. apply plugin: "com.facebook.react"
  4. def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
  5. static def versionToNumber(major, minor, patch) {
  6. return patch * 100 + minor * 10000 + major * 1000000
  7. }
  8. def getRNVersion() {
  9. def version = providers.exec {
  10. workingDir(projectDir)
  11. commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
  12. }.standardOutput.asText.get().trim()
  13. def coreVersion = version.split("-")[0]
  14. def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
  15. return versionToNumber(
  16. major,
  17. minor,
  18. patch
  19. )
  20. }
  21. def rnVersion = getRNVersion()
  22. /**
  23. * This is the configuration block to customize your React Native Android app.
  24. * By default you don't need to apply any configuration, just uncomment the lines you need.
  25. */
  26. react {
  27. entryFile = file(["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android", "absolute"].execute(null, rootDir).text.trim())
  28. reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
  29. hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
  30. codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
  31. // Use Expo CLI to bundle the app, this ensures the Metro config
  32. // works correctly with Expo projects.
  33. cliFile = new File(["node", "--print", "require.resolve('@expo/cli', { paths: [require.resolve('expo/package.json')] })"].execute(null, rootDir).text.trim())
  34. bundleCommand = "export:embed"
  35. /* Folders */
  36. // The root of your project, i.e. where "package.json" lives. Default is '..'
  37. // root = file("../")
  38. // The folder where the react-native NPM package is. Default is ../node_modules/react-native
  39. // reactNativeDir = file("../node_modules/react-native")
  40. // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
  41. // codegenDir = file("../node_modules/@react-native/codegen")
  42. /* Variants */
  43. // The list of variants to that are debuggable. For those we're going to
  44. // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
  45. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
  46. // debuggableVariants = ["liteDebug", "prodDebug"]
  47. /* Bundling */
  48. // A list containing the node command and its flags. Default is just 'node'.
  49. // nodeExecutableAndArgs = ["node"]
  50. //
  51. // The path to the CLI configuration file. Default is empty.
  52. // bundleConfig = file(../rn-cli.config.js)
  53. //
  54. // The name of the generated asset file containing your JS bundle
  55. // bundleAssetName = "MyApplication.android.bundle"
  56. //
  57. // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
  58. // entryFile = file("../js/MyApplication.android.js")
  59. //
  60. // A list of extra flags to pass to the 'bundle' commands.
  61. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
  62. // extraPackagerArgs = []
  63. /* Hermes Commands */
  64. // The hermes compiler command to run. By default it is 'hermesc'
  65. // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
  66. //
  67. // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
  68. // hermesFlags = ["-O", "-output-source-map"]
  69. if (rnVersion >= versionToNumber(0, 75, 0)) {
  70. /* Autolinking */
  71. autolinkLibrariesWithApp()
  72. }
  73. }
  74. /**
  75. * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
  76. */
  77. def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()
  78. /**
  79. * The preferred build flavor of JavaScriptCore (JSC)
  80. *
  81. * For example, to use the international variant, you can use:
  82. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  83. *
  84. * The international variant includes ICU i18n library and necessary data
  85. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  86. * give correct results when using with locales other than en-US. Note that
  87. * this variant is about 6MiB larger per architecture than default.
  88. */
  89. def jscFlavor = 'org.webkit:android-jsc:+'
  90. android {
  91. ndkVersion rootProject.ext.ndkVersion
  92. buildToolsVersion rootProject.ext.buildToolsVersion
  93. compileSdk rootProject.ext.compileSdkVersion
  94. namespace 'hk.com.crazycharge'
  95. defaultConfig {
  96. applicationId 'hk.com.crazycharge'
  97. minSdkVersion rootProject.ext.minSdkVersion
  98. targetSdkVersion rootProject.ext.targetSdkVersion
  99. versionCode 28
  100. versionName "1.3.1"
  101. }
  102. signingConfigs {
  103. debug {
  104. storeFile file('debug.keystore')
  105. storePassword 'android'
  106. keyAlias 'androiddebugkey'
  107. keyPassword 'android'
  108. }
  109. }
  110. buildTypes {
  111. debug {
  112. signingConfig signingConfigs.debug
  113. }
  114. release {
  115. // Caution! In production, you need to generate your own keystore file.
  116. // see https://reactnative.dev/docs/signed-apk-android.
  117. signingConfig signingConfigs.debug
  118. shrinkResources (findProperty('android.enableShrinkResourcesInReleaseBuilds')?.toBoolean() ?: false)
  119. minifyEnabled enableProguardInReleaseBuilds
  120. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  121. crunchPngs (findProperty('android.enablePngCrunchInReleaseBuilds')?.toBoolean() ?: true)
  122. }
  123. }
  124. packagingOptions {
  125. jniLibs {
  126. useLegacyPackaging (findProperty('expo.useLegacyPackaging')?.toBoolean() ?: false)
  127. }
  128. }
  129. }
  130. // Apply static values from `gradle.properties` to the `android.packagingOptions`
  131. // Accepts values in comma delimited lists, example:
  132. // android.packagingOptions.pickFirsts=/LICENSE,**/picasa.ini
  133. ["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
  134. // Split option: 'foo,bar' -> ['foo', 'bar']
  135. def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
  136. // Trim all elements in place.
  137. for (i in 0..<options.size()) options[i] = options[i].trim();
  138. // `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
  139. options -= ""
  140. if (options.length > 0) {
  141. println "android.packagingOptions.$prop += $options ($options.length)"
  142. // Ex: android.packagingOptions.pickFirsts += '**/SCCS/**'
  143. options.each {
  144. android.packagingOptions[prop] += it
  145. }
  146. }
  147. }
  148. dependencies {
  149. // The version of react-native is set by the React Native Gradle Plugin
  150. implementation("com.facebook.react:react-android")
  151. def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
  152. def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
  153. def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
  154. if (isGifEnabled) {
  155. // For animated gif support
  156. implementation("com.facebook.fresco:animated-gif:${reactAndroidLibs.versions.fresco.get()}")
  157. }
  158. if (isWebpEnabled) {
  159. // For webp support
  160. implementation("com.facebook.fresco:webpsupport:${reactAndroidLibs.versions.fresco.get()}")
  161. if (isWebpAnimatedEnabled) {
  162. // Animated webp support
  163. implementation("com.facebook.fresco:animated-webp:${reactAndroidLibs.versions.fresco.get()}")
  164. }
  165. }
  166. if (hermesEnabled.toBoolean()) {
  167. implementation("com.facebook.react:hermes-android")
  168. } else {
  169. implementation jscFlavor
  170. }
  171. }
  172. if (rnVersion < versionToNumber(0, 75, 0)) {
  173. apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
  174. applyNativeModulesAppBuildGradle(project)
  175. }
  176. apply plugin: 'com.google.gms.google-services'