build.gradle 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import groovy.json.JsonSlurper
  2. apply plugin: "com.android.application"
  3. apply plugin: "org.jetbrains.kotlin.android"
  4. apply plugin: "com.facebook.react"
  5. // 获取当前时间戳,格式为 yymmddHHmm
  6. def getTimestampVersion = {
  7. def date = new Date()
  8. def formattedDate = date.format('yyMMddHHmm')
  9. return '1.0.0-' + formattedDate
  10. }
  11. def getAppVersion() {
  12. // 注意文件路径,'../package.json' 表示从当前目录(android/app)向上一级到项目根目录
  13. def inputFile = new File("../package.json")
  14. def packageJson = new JsonSlurper().parseText(inputFile.text)
  15. return packageJson["version"]
  16. }
  17. /**
  18. * This is the configuration block to customize your React Native Android app.
  19. * By default you don't need to apply any configuration, just uncomment the lines you need.
  20. */
  21. react {
  22. /* Folders */
  23. // The root of your project, i.e. where "package.json" lives. Default is '..'
  24. // root = file("../")
  25. // The folder where the react-native NPM package is. Default is ../node_modules/react-native
  26. // reactNativeDir = file("../node_modules/react-native")
  27. // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
  28. // codegenDir = file("../node_modules/@react-native/codegen")
  29. // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
  30. // cliFile = file("../node_modules/react-native/cli.js")
  31. /* Variants */
  32. // The list of variants to that are debuggable. For those we're going to
  33. // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
  34. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
  35. // debuggableVariants = ["liteDebug", "prodDebug"]
  36. /* Bundling */
  37. // A list containing the node command and its flags. Default is just 'node'.
  38. // nodeExecutableAndArgs = ["node"]
  39. //
  40. // The command to run when bundling. By default is 'bundle'
  41. // bundleCommand = "ram-bundle"
  42. //
  43. // The path to the CLI configuration file. Default is empty.
  44. // bundleConfig = file(../rn-cli.config.js)
  45. //
  46. // The name of the generated asset file containing your JS bundle
  47. // bundleAssetName = "MyApplication.android.bundle"
  48. //
  49. // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
  50. // entryFile = file("../js/MyApplication.android.js")
  51. //
  52. // A list of extra flags to pass to the 'bundle' commands.
  53. // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
  54. // extraPackagerArgs = []
  55. /* Hermes Commands */
  56. // The hermes compiler command to run. By default it is 'hermesc'
  57. // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
  58. //
  59. // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
  60. // hermesFlags = ["-O", "-output-source-map"]
  61. }
  62. /**
  63. * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
  64. */
  65. def enableProguardInReleaseBuilds = false
  66. /**
  67. * The preferred build flavor of JavaScriptCore (JSC)
  68. *
  69. * For example, to use the international variant, you can use:
  70. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  71. *
  72. * The international variant includes ICU i18n library and necessary data
  73. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  74. * give correct results when using with locales other than en-US. Note that
  75. * this variant is about 6MiB larger per architecture than default.
  76. */
  77. def jscFlavor = 'org.webkit:android-jsc:+'
  78. android {
  79. ndkVersion rootProject.ext.ndkVersion
  80. buildToolsVersion rootProject.ext.buildToolsVersion
  81. compileSdk rootProject.ext.compileSdkVersion
  82. dexOptions {
  83. javaMaxHeapSize "4g"
  84. }
  85. namespace "com.tjy.app"
  86. defaultConfig {
  87. applicationId app_id
  88. minSdkVersion rootProject.ext.minSdkVersion
  89. targetSdkVersion rootProject.ext.targetSdkVersion
  90. versionCode 111000
  91. // versionName getTimestampVersion()
  92. versionName getAppVersion() // 改为使用从 package.json 读取的版本
  93. }
  94. signingConfigs {
  95. debug {
  96. storeFile file('debug.keystore')
  97. storePassword 'testAndroid'
  98. keyAlias 'androiddebugkey'
  99. keyPassword 'testAndroid'
  100. }
  101. release {
  102. storeFile file('tjy-release-key.keystore')
  103. storePassword 'tjy@2025'
  104. keyAlias 'tjy-release-key'
  105. keyPassword 'tjy@2025'
  106. }
  107. }
  108. buildTypes {
  109. debug {
  110. signingConfig signingConfigs.debug
  111. }
  112. release {
  113. // Caution! In production, you need to generate your own keystore file.
  114. // see https://reactnative.dev/docs/signed-apk-android.
  115. signingConfig signingConfigs.release
  116. minifyEnabled enableProguardInReleaseBuilds
  117. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  118. // shrinkResources true // 移除无用资源
  119. // debuggable false
  120. // jniDebuggable false
  121. // renderscriptDebuggable false
  122. }
  123. }
  124. }
  125. dependencies {
  126. // The version of react-native is set by the React Native Gradle Plugin
  127. implementation("com.facebook.react:react-android")
  128. implementation 'com.facebook.fresco:animated-gif:2.5.0'
  129. implementation("com.facebook.react:flipper-integration")
  130. if (hermesEnabled.toBoolean()) {
  131. implementation("com.facebook.react:hermes-android")
  132. } else {
  133. implementation jscFlavor
  134. }
  135. }
  136. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)