build.gradle 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. apply plugin: "com.android.application"
  2. import com.android.build.OutputFile
  3. /**
  4. * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  5. * and bundleReleaseJsAndAssets).
  6. * These basically call `react-native bundle` with the correct arguments during the Android build
  7. * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  8. * bundle directly from the development server. Below you can see all the possible configurations
  9. * and their defaults. If you decide to add a configuration block, make sure to add it before the
  10. * `apply from: "../../node_modules/react-native/react.gradle"` line.
  11. *
  12. * project.ext.react = [
  13. * // the name of the generated asset file containing your JS bundle
  14. * bundleAssetName: "index.android.bundle",
  15. *
  16. * // the entry file for bundle generation. If none specified and
  17. * // "index.android.js" exists, it will be used. Otherwise "index.js" is
  18. * // default. Can be overridden with ENTRY_FILE environment variable.
  19. * entryFile: "index.android.js",
  20. *
  21. * // https://reactnative.dev/docs/performance#enable-the-ram-format
  22. * bundleCommand: "ram-bundle",
  23. *
  24. * // whether to bundle JS and assets in debug mode
  25. * bundleInDebug: false,
  26. *
  27. * // whether to bundle JS and assets in release mode
  28. * bundleInRelease: true,
  29. *
  30. * // whether to bundle JS and assets in another build variant (if configured).
  31. * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  32. * // The configuration property can be in the following formats
  33. * // 'bundleIn${productFlavor}${buildType}'
  34. * // 'bundleIn${buildType}'
  35. * // bundleInFreeDebug: true,
  36. * // bundleInPaidRelease: true,
  37. * // bundleInBeta: true,
  38. *
  39. * // whether to disable dev mode in custom build variants (by default only disabled in release)
  40. * // for example: to disable dev mode in the staging build type (if configured)
  41. * devDisabledInStaging: true,
  42. * // The configuration property can be in the following formats
  43. * // 'devDisabledIn${productFlavor}${buildType}'
  44. * // 'devDisabledIn${buildType}'
  45. *
  46. * // the root of your project, i.e. where "package.json" lives
  47. * root: "../../",
  48. *
  49. * // where to put the JS bundle asset in debug mode
  50. * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  51. *
  52. * // where to put the JS bundle asset in release mode
  53. * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  54. *
  55. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  56. * // require('./image.png')), in debug mode
  57. * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  58. *
  59. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  60. * // require('./image.png')), in release mode
  61. * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  62. *
  63. * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  64. * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  65. * // date; if you have any other folders that you want to ignore for performance reasons (gradle
  66. * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  67. * // for example, you might want to remove it from here.
  68. * inputExcludes: ["android/**", "ios/**"],
  69. *
  70. * // override which node gets called and with what additional arguments
  71. * nodeExecutableAndArgs: ["node"],
  72. *
  73. * // supply additional arguments to the packager
  74. * extraPackagerArgs: []
  75. * ]
  76. */
  77. project.ext.react = [
  78. enableHermes: false, // clean and rebuild if changing
  79. deleteDebugFilesForVariant: { false }
  80. ]
  81. apply from: "../../node_modules/react-native/react.gradle"
  82. /**
  83. * Set this to true to create two separate APKs instead of one:
  84. * - An APK that only works on ARM devices
  85. * - An APK that only works on x86 devices
  86. * The advantage is the size of the APK is reduced by about 4MB.
  87. * Upload all the APKs to the Play Store and people will download
  88. * the correct one based on the CPU architecture of their device.
  89. */
  90. def enableSeparateBuildPerCPUArchitecture = false
  91. /**
  92. * Run Proguard to shrink the Java bytecode in release builds.
  93. */
  94. def enableProguardInReleaseBuilds = false
  95. /**
  96. * The preferred build flavor of JavaScriptCore.
  97. *
  98. * For example, to use the international variant, you can use:
  99. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  100. *
  101. * The international variant includes ICU i18n library and necessary data
  102. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  103. * give correct results when using with locales other than en-US. Note that
  104. * this variant is about 6MiB larger per architecture than default.
  105. */
  106. def jscFlavor = 'org.webkit:android-jsc:+'
  107. /**
  108. * Whether to enable the Hermes VM.
  109. *
  110. * This should be set on project.ext.react and that value will be read here. If it is not set
  111. * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
  112. * and the benefits of using Hermes will therefore be sharply reduced.
  113. */
  114. def enableHermes = project.ext.react.get("enableHermes", false);
  115. /**
  116. * Architectures to build native code for in debug.
  117. */
  118. def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
  119. android {
  120. ndkVersion rootProject.ext.ndkVersion
  121. compileSdkVersion rootProject.ext.compileSdkVersion
  122. defaultConfig {
  123. applicationId "com.zzliaoyuan.power_sensor"
  124. minSdkVersion rootProject.ext.minSdkVersion
  125. targetSdkVersion rootProject.ext.targetSdkVersion
  126. versionCode 20
  127. versionName "2.0"
  128. }
  129. splits {
  130. abi {
  131. reset()
  132. enable enableSeparateBuildPerCPUArchitecture
  133. universalApk false // If true, also generate a universal APK
  134. include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
  135. }
  136. }
  137. signingConfigs {
  138. debug {
  139. storeFile file('debug.keystore')
  140. storePassword 'android'
  141. keyAlias 'androiddebugkey'
  142. keyPassword 'android'
  143. }
  144. release {
  145. if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
  146. storeFile file(MYAPP_RELEASE_STORE_FILE)
  147. storePassword MYAPP_RELEASE_STORE_PASSWORD
  148. keyAlias MYAPP_RELEASE_KEY_ALIAS
  149. keyPassword MYAPP_RELEASE_KEY_PASSWORD
  150. }
  151. }
  152. }
  153. sourceSets {
  154. main {
  155. jniLibs.srcDirs = ['src\\main\\jniLibs']
  156. }
  157. }
  158. buildTypes {
  159. debug {
  160. signingConfig signingConfigs.debug
  161. if (nativeArchitectures) {
  162. ndk {
  163. abiFilters nativeArchitectures.split(',')
  164. }
  165. }
  166. }
  167. release {
  168. // Caution! In production, you need to generate your own keystore file.
  169. // see https://reactnative.dev/docs/signed-apk-android.
  170. signingConfig signingConfigs.release
  171. minifyEnabled enableProguardInReleaseBuilds
  172. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  173. }
  174. }
  175. // applicationVariants are e.g. debug, release
  176. applicationVariants.all { variant ->
  177. variant.outputs.each { output ->
  178. // For each separate APK per architecture, set a unique version code as described here:
  179. // https://developer.android.com/studio/build/configure-apk-splits.html
  180. // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
  181. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  182. def abi = output.getFilter(OutputFile.ABI)
  183. if (abi != null) { // null for the universal-debug, universal-release variants
  184. output.versionCodeOverride =
  185. defaultConfig.versionCode * 1000 + versionCodes.get(abi)
  186. }
  187. }
  188. }
  189. }
  190. repositories {
  191. flatDir{
  192. dirs 'src\\main\\jniLibs'
  193. }
  194. }
  195. dependencies {
  196. implementation fileTree(dir: "libs", include: ["*.jar"])
  197. //noinspection GradleDynamicVersion
  198. implementation "com.facebook.react:react-native:+" // From node_modules
  199. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
  200. api 'com.github.dfqin:grantor:2.5' // MainActivity获取相机权限用
  201. // rifdmastercore
  202. implementation(name: 'corewrapper', ext:'aar')
  203. api 'com.github.dfqin:grantor:2.5'
  204. // UHF
  205. implementation files('libs/cw-deviceapi20191022.jar')
  206. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  207. exclude group: 'com.facebook.fbjni'
  208. }
  209. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  210. exclude group: 'com.facebook.flipper'
  211. exclude group: 'com.squareup.okhttp3', module: 'okhttp'
  212. }
  213. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  214. exclude group: 'com.facebook.flipper'
  215. }
  216. //bugly
  217. // implementation 'com.tencent.bugly:crashreport_upgrade:latest.release'
  218. // implementation 'com.tencent.bugly:nativecrashreport:latest.release'
  219. if (enableHermes) {
  220. def hermesPath = "../../node_modules/hermes-engine/android/";
  221. debugImplementation files(hermesPath + "hermes-debug.aar")
  222. releaseImplementation files(hermesPath + "hermes-release.aar")
  223. } else {
  224. implementation jscFlavor
  225. }
  226. }
  227. // Run this once to be able to run the application with BUCK
  228. // puts all compile dependencies into folder libs for BUCK to use
  229. task copyDownloadableDepsToLibs(type: Copy) {
  230. from configurations.implementation
  231. into 'libs'
  232. }
  233. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)