build.gradle 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. apply plugin: "com.android.application"
  2. apply plugin: 'com.google.gms.google-services'
  3. import com.android.build.OutputFile
  4. def myVersionName = "2.5.0" //★★★★★版本号★★★★★
  5. /**
  6. * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  7. * and bundleReleaseJsAndAssets).
  8. * These basically call `react-native bundle` with the correct arguments during the Android build
  9. * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  10. * bundle directly from the development server. Below you can see all the possible configurations
  11. * and their defaults. If you decide to add a configuration block, make sure to add it before the
  12. * `apply from: "../../node_modules/react-native/react.gradle"` line.
  13. *
  14. * project.ext.react = [
  15. * // the name of the generated asset file containing your JS bundle
  16. * bundleAssetName: "index.android.bundle",
  17. *
  18. * // the entry file for bundle generation. If none specified and
  19. * // "index.android.js" exists, it will be used. Otherwise "index.js" is
  20. * // default. Can be overridden with ENTRY_FILE environment variable.
  21. * entryFile: "index.android.js",
  22. *
  23. * // https://reactnative.dev/docs/performance#enable-the-ram-format
  24. * bundleCommand: "ram-bundle",
  25. *
  26. * // whether to bundle JS and assets in debug mode
  27. * bundleInDebug: false,
  28. *
  29. * // whether to bundle JS and assets in release mode
  30. * bundleInRelease: true,
  31. *
  32. * // whether to bundle JS and assets in another build variant (if configured).
  33. * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  34. * // The configuration property can be in the following formats
  35. * // 'bundleIn${productFlavor}${buildType}'
  36. * // 'bundleIn${buildType}'
  37. * // bundleInFreeDebug: true,
  38. * // bundleInPaidRelease: true,
  39. * // bundleInBeta: true,
  40. *
  41. * // whether to disable dev mode in custom build variants (by default only disabled in release)
  42. * // for example: to disable dev mode in the staging build type (if configured)
  43. * devDisabledInStaging: true,
  44. * // The configuration property can be in the following formats
  45. * // 'devDisabledIn${productFlavor}${buildType}'
  46. * // 'devDisabledIn${buildType}'
  47. *
  48. * // the root of your project, i.e. where "package.json" lives
  49. * root: "../../",
  50. *
  51. * // where to put the JS bundle asset in debug mode
  52. * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  53. *
  54. * // where to put the JS bundle asset in release mode
  55. * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  56. *
  57. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  58. * // require('./image.png')), in debug mode
  59. * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  60. *
  61. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  62. * // require('./image.png')), in release mode
  63. * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  64. *
  65. * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  66. * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  67. * // date; if you have any other folders that you want to ignore for performance reasons (gradle
  68. * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  69. * // for example, you might want to remove it from here.
  70. * inputExcludes: ["android/**", "ios/**"],
  71. *
  72. * // override which node gets called and with what additional arguments
  73. * nodeExecutableAndArgs: ["node"],
  74. *
  75. * // supply additional arguments to the packager
  76. * extraPackagerArgs: []
  77. * ]
  78. */
  79. project.ext.react = [
  80. //entryFile: "index.js",
  81. //hermesCommand: "../../node_modules/hermes-engine/%OS-BIN%/hermes", // Or whatever path you need
  82. enableHermes: true, // clean and rebuild if changing
  83. ]
  84. apply from: "../../node_modules/react-native/react.gradle"
  85. apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
  86. apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
  87. /**
  88. * Set this to true to create two separate APKs instead of one:
  89. * - An APK that only works on ARM devices
  90. * - An APK that only works on x86 devices
  91. * The advantage is the size of the APK is reduced by about 4MB.
  92. * Upload all the APKs to the Play Store and people will download
  93. * the correct one based on the CPU architecture of their device.
  94. */
  95. def enableSeparateBuildPerCPUArchitecture = false
  96. /**
  97. * Run Proguard to shrink the Java bytecode in release builds.
  98. */
  99. def enableProguardInReleaseBuilds = true
  100. /**
  101. * The preferred build flavor of JavaScriptCore.
  102. *
  103. * For example, to use the international variant, you can use:
  104. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  105. *
  106. * The international variant includes ICU i18n library and necessary data
  107. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  108. * give correct results when using with locales other than en-US. Note that
  109. * this variant is about 6MiB larger per architecture than default.
  110. */
  111. def jscFlavor = 'org.webkit:android-jsc:+'
  112. /**
  113. * Whether to enable the Hermes VM.
  114. *
  115. * This should be set on project.ext.react and mirrored here. If it is not set
  116. * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
  117. * and the benefits of using Hermes will therefore be sharply reduced.
  118. */
  119. def enableHermes = project.ext.react.get("enableHermes", false);
  120. def getMyVersionCode() {
  121. def files = file('version.properties')
  122. Properties props = new Properties()
  123. props.load(new FileInputStream(files))
  124. def code = props['VERSION_CODE'].toInteger()
  125. //def task = gradle.startParameter.taskNames
  126. //if ('assembleRelease' in task) {
  127. code++
  128. //}
  129. props['VERSION_CODE'] = code.toString()
  130. props.store(files.newWriter(), null)
  131. return code
  132. }
  133. static def releaseTime() {
  134. return new Date().format("yyyyMMdd", TimeZone.getDefault());
  135. }
  136. android {
  137. ndkVersion rootProject.ext.ndkVersion
  138. compileSdkVersion rootProject.ext.compileSdkVersion
  139. compileOptions {
  140. sourceCompatibility JavaVersion.VERSION_1_8
  141. targetCompatibility JavaVersion.VERSION_1_8
  142. }
  143. defaultConfig {
  144. applicationId "com.strides.chargeco"
  145. minSdkVersion rootProject.ext.minSdkVersion
  146. targetSdkVersion rootProject.ext.targetSdkVersion
  147. versionCode getMyVersionCode()
  148. versionName myVersionName
  149. multiDexEnabled true
  150. missingDimensionStrategy 'react-native-camera', 'general'
  151. }
  152. splits {
  153. abi {
  154. reset()
  155. enable enableSeparateBuildPerCPUArchitecture
  156. universalApk false // If true, also generate a universal APK
  157. include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
  158. }
  159. }
  160. signingConfigs {
  161. debug {
  162. storeFile file('vbea.keystore')
  163. storePassword 'dec2020'
  164. keyAlias 'vbea'
  165. keyPassword 'dec2020'
  166. }
  167. release {
  168. storeFile file('vbea.keystore')
  169. storePassword 'dec2020'
  170. keyAlias 'vbea'
  171. keyPassword 'dec2020'
  172. }
  173. }
  174. buildTypes {
  175. debug {
  176. signingConfig signingConfigs.debug
  177. //热更新应用分发Staging key
  178. resValue "string", "CodePushDeploymentKey", "zu0zkOWpBhXTGQ83pC15FW3puB--tuSG5TvIQ"
  179. }
  180. releaseStaging {
  181. signingConfig signingConfigs.release
  182. minifyEnabled enableProguardInReleaseBuilds
  183. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  184. ndk {
  185. abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
  186. }
  187. //热更新应用分发Staging key
  188. resValue "string", "CodePushDeploymentKey", "zu0zkOWpBhXTGQ83pC15FW3puB--tuSG5TvIQ"
  189. matchingFallbacks = ['release']
  190. }
  191. release {
  192. // Caution! In production, you need to generate your own keystore file.
  193. // see https://reactnative.dev/docs/signed-apk-android.
  194. signingConfig signingConfigs.release
  195. minifyEnabled enableProguardInReleaseBuilds
  196. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  197. ndk {
  198. abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
  199. }
  200. //热更新应用分发Production key
  201. resValue "string", "CodePushDeploymentKey", "rQGN1c2GXKx5EBT1scXipC9xwSQZMG62xiWOd"
  202. }
  203. }
  204. // applicationVariants are e.g. debug, release
  205. applicationVariants.all { variant ->
  206. variant.outputs.each { output ->
  207. // For each separate APK per architecture, set a unique version code as described here:
  208. // https://developer.android.com/studio/build/configure-apk-splits.html
  209. // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
  210. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  211. def abi = output.getFilter(OutputFile.ABI)
  212. if (abi != null) { // null for the universal-debug, universal-release variants
  213. output.versionCodeOverride =
  214. defaultConfig.versionCode * 1000 + versionCodes.get(abi)
  215. }
  216. }
  217. variant.outputs.all { output ->
  218. if (variant.buildType.name=="release") {
  219. def fileName = "ChargEco-V${variant.versionName}-${variant.versionCode}"
  220. // 加入打包时间
  221. fileName = fileName + "-${releaseTime()}"
  222. // 加入版本类型
  223. fileName = fileName + "-${variant.buildType.name}.apk"
  224. //output.outputFile = new File(outputFile.parent, fileName)
  225. outputFileName = fileName
  226. }
  227. }
  228. }
  229. }
  230. dependencies {
  231. implementation fileTree(dir: "libs", include: ["*.jar"])
  232. //noinspection GradleDynamicVersion
  233. implementation "com.facebook.react:react-native:0.64.2" // From node_modules
  234. implementation 'com.facebook.fresco:animated-gif:2.0.0' // 如果你需要支持GIF动图
  235. implementation "androidx.appcompat:appcompat:1.0.0"
  236. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
  237. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  238. exclude group:'com.facebook.fbjni'
  239. }
  240. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  241. exclude group:'com.facebook.flipper'
  242. exclude group:'com.squareup.okhttp3', module:'okhttp'
  243. }
  244. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  245. exclude group:'com.facebook.flipper'
  246. }
  247. if (enableHermes) {
  248. def hermesPath = "../../node_modules/hermes-engine/android/";
  249. debugImplementation files(hermesPath + "hermes-debug.aar")
  250. releaseImplementation files(hermesPath + "hermes-release.aar")
  251. } else {
  252. implementation jscFlavor
  253. }
  254. /*implementation(project(':react-native-maps')){
  255. exclude group: 'com.google.android.gms', module: 'play-services-base'
  256. exclude group: 'com.google.android.gms', module: 'play-services-maps'
  257. }
  258. implementation 'com.google.android.gms:play-services-base:17.2.1'*/
  259. /*implementation 'com.google.android.gms:play-services-maps:17.0.0'
  260. implementation 'com.google.maps.android:android-maps-utils:2.2.3'*/
  261. implementation platform('com.google.firebase:firebase-bom:32.0.0')
  262. implementation 'com.google.firebase:firebase-messaging'
  263. implementation 'com.google.firebase:firebase-analytics'
  264. }
  265. // Run this once to be able to run the application with BUCK
  266. // puts all compile dependencies into folder libs for BUCK to use
  267. task copyDownloadableDepsToLibs(type: Copy) {
  268. from configurations.compile
  269. into 'libs'
  270. }
  271. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)