Brak opisu

build.gradle 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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://facebook.github.io/react-native/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. ]
  80. apply from: "../../node_modules/react-native/react.gradle"
  81. /**
  82. * Set this to true to create two separate APKs instead of one:
  83. * - An APK that only works on ARM devices
  84. * - An APK that only works on x86 devices
  85. * The advantage is the size of the APK is reduced by about 4MB.
  86. * Upload all the APKs to the Play Store and people will download
  87. * the correct one based on the CPU architecture of their device.
  88. */
  89. def enableSeparateBuildPerCPUArchitecture = false
  90. /**
  91. * Run Proguard to shrink the Java bytecode in release builds.
  92. */
  93. def enableProguardInReleaseBuilds = false
  94. /**
  95. * The preferred build flavor of JavaScriptCore.
  96. *
  97. * For example, to use the international variant, you can use:
  98. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  99. *
  100. * The international variant includes ICU i18n library and necessary data
  101. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  102. * give correct results when using with locales other than en-US. Note that
  103. * this variant is about 6MiB larger per architecture than default.
  104. */
  105. def jscFlavor = 'org.webkit:android-jsc:+'
  106. /**
  107. * Whether to enable the Hermes VM.
  108. *
  109. * This should be set on project.ext.react and mirrored here. If it is not set
  110. * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
  111. * and the benefits of using Hermes will therefore be sharply reduced.
  112. */
  113. def enableHermes = project.ext.react.get("enableHermes", false);
  114. android {
  115. compileSdkVersion rootProject.ext.compileSdkVersion
  116. compileOptions {
  117. sourceCompatibility JavaVersion.VERSION_1_8
  118. targetCompatibility JavaVersion.VERSION_1_8
  119. }
  120. defaultConfig {
  121. applicationId "com.demo"
  122. minSdkVersion rootProject.ext.minSdkVersion
  123. targetSdkVersion rootProject.ext.targetSdkVersion
  124. versionCode 1
  125. versionName "1.0"
  126. }
  127. splits {
  128. abi {
  129. reset()
  130. enable enableSeparateBuildPerCPUArchitecture
  131. universalApk false // If true, also generate a universal APK
  132. include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
  133. }
  134. }
  135. signingConfigs {
  136. debug {
  137. storeFile file('debug.keystore')
  138. storePassword 'android'
  139. keyAlias 'androiddebugkey'
  140. keyPassword 'android'
  141. }
  142. }
  143. buildTypes {
  144. debug {
  145. signingConfig signingConfigs.debug
  146. }
  147. release {
  148. // Caution! In production, you need to generate your own keystore file.
  149. // see https://facebook.github.io/react-native/docs/signed-apk-android.
  150. signingConfig signingConfigs.debug
  151. minifyEnabled enableProguardInReleaseBuilds
  152. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  153. }
  154. }
  155. packagingOptions {
  156. pickFirst "lib/armeabi-v7a/libc++_shared.so"
  157. pickFirst "lib/arm64-v8a/libc++_shared.so"
  158. pickFirst "lib/x86/libc++_shared.so"
  159. pickFirst "lib/x86_64/libc++_shared.so"
  160. }
  161. // applicationVariants are e.g. debug, release
  162. applicationVariants.all { variant ->
  163. variant.outputs.each { output ->
  164. // For each separate APK per architecture, set a unique version code as described here:
  165. // https://developer.android.com/studio/build/configure-apk-splits.html
  166. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  167. def abi = output.getFilter(OutputFile.ABI)
  168. if (abi != null) { // null for the universal-debug, universal-release variants
  169. output.versionCodeOverride =
  170. versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
  171. }
  172. }
  173. }
  174. }
  175. dependencies {
  176. implementation fileTree(dir: "libs", include: ["*.jar"])
  177. //noinspection GradleDynamicVersion
  178. implementation "com.facebook.react:react-native:+" // From node_modules
  179. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
  180. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  181. exclude group:'com.facebook.fbjni'
  182. }
  183. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  184. exclude group:'com.facebook.flipper'
  185. }
  186. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  187. exclude group:'com.facebook.flipper'
  188. }
  189. if (enableHermes) {
  190. def hermesPath = "../../node_modules/hermes-engine/android/";
  191. debugImplementation files(hermesPath + "hermes-debug.aar")
  192. releaseImplementation files(hermesPath + "hermes-release.aar")
  193. } else {
  194. implementation jscFlavor
  195. }
  196. }
  197. // Run this once to be able to run the application with BUCK
  198. // puts all compile dependencies into folder libs for BUCK to use
  199. task copyDownloadableDepsToLibs(type: Copy) {
  200. from configurations.compile
  201. into 'libs'
  202. }
  203. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)