You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
9.1 KiB

4 years ago
  1. apply plugin: "com.android.application"
  2. project.ext.envConfigFiles = [
  3. debug: ".env",
  4. release: ".env.production",
  5. stagingrelease: ".env.staging",
  6. ]
  7. apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
  8. import com.android.build.OutputFile
  9. /**
  10. * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  11. * and bundleReleaseJsAndAssets).
  12. * These basically call `react-native bundle` with the correct arguments during the Android build
  13. * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  14. * bundle directly from the development server. Below you can see all the possible configurations
  15. * and their defaults. If you decide to add a configuration block, make sure to add it before the
  16. * `apply from: "../../node_modules/react-native/react.gradle"` line.
  17. *
  18. * project.ext.react = [
  19. * // the name of the generated asset file containing your JS bundle
  20. * bundleAssetName: "index.android.bundle",
  21. *
  22. * // the entry file for bundle generation. If none specified and
  23. * // "index.android.js" exists, it will be used. Otherwise "index.js" is
  24. * // default. Can be overridden with ENTRY_FILE environment variable.
  25. * entryFile: "index.android.js",
  26. *
  27. * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
  28. * bundleCommand: "ram-bundle",
  29. *
  30. * // whether to bundle JS and assets in debug mode
  31. * bundleInDebug: false,
  32. *
  33. * // whether to bundle JS and assets in release mode
  34. * bundleInRelease: true,
  35. *
  36. * // whether to bundle JS and assets in another build variant (if configured).
  37. * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  38. * // The configuration property can be in the following formats
  39. * // 'bundleIn${productFlavor}${buildType}'
  40. * // 'bundleIn${buildType}'
  41. * // bundleInFreeDebug: true,
  42. * // bundleInPaidRelease: true,
  43. * // bundleInBeta: true,
  44. *
  45. * // whether to disable dev mode in custom build variants (by default only disabled in release)
  46. * // for example: to disable dev mode in the staging build type (if configured)
  47. * devDisabledInStaging: true,
  48. * // The configuration property can be in the following formats
  49. * // 'devDisabledIn${productFlavor}${buildType}'
  50. * // 'devDisabledIn${buildType}'
  51. *
  52. * // the root of your project, i.e. where "package.json" lives
  53. * root: "../../",
  54. *
  55. * // where to put the JS bundle asset in debug mode
  56. * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  57. *
  58. * // where to put the JS bundle asset in release mode
  59. * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  60. *
  61. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  62. * // require('./image.png')), in debug mode
  63. * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  64. *
  65. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  66. * // require('./image.png')), in release mode
  67. * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  68. *
  69. * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  70. * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  71. * // date; if you have any other folders that you want to ignore for performance reasons (gradle
  72. * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  73. * // for example, you might want to remove it from here.
  74. * inputExcludes: ["android/**", "ios/**"],
  75. *
  76. * // override which node gets called and with what additional arguments
  77. * nodeExecutableAndArgs: ["node"],
  78. *
  79. * // supply additional arguments to the packager
  80. * extraPackagerArgs: []
  81. * ]
  82. */
  83. project.ext.react = [
  84. enableHermes: true, // clean and rebuild if changing
  85. ]
  86. apply from: "../../node_modules/react-native/react.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. android {
  121. compileSdkVersion rootProject.ext.compileSdkVersion
  122. compileOptions {
  123. sourceCompatibility JavaVersion.VERSION_1_8
  124. targetCompatibility JavaVersion.VERSION_1_8
  125. }
  126. defaultConfig {
  127. applicationId "com.rntemplate"
  128. minSdkVersion rootProject.ext.minSdkVersion
  129. targetSdkVersion rootProject.ext.targetSdkVersion
  130. versionCode 1
  131. versionName "1.0"
  132. resValue "string", "build_config_package", "com.rntemplate"
  133. }
  134. splits {
  135. abi {
  136. reset()
  137. enable enableSeparateBuildPerCPUArchitecture
  138. universalApk false // If true, also generate a universal APK
  139. include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
  140. }
  141. }
  142. signingConfigs {
  143. debug {
  144. storeFile file('debug.keystore')
  145. storePassword 'android'
  146. keyAlias 'androiddebugkey'
  147. keyPassword 'android'
  148. }
  149. }
  150. buildTypes {
  151. debug {
  152. signingConfig signingConfigs.debug
  153. }
  154. release {
  155. // Caution! In production, you need to generate your own keystore file.
  156. // see https://facebook.github.io/react-native/docs/signed-apk-android.
  157. signingConfig signingConfigs.debug
  158. minifyEnabled enableProguardInReleaseBuilds
  159. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  160. }
  161. stagingrelease {
  162. initWith release
  163. matchingFallbacks = ['release']
  164. }
  165. }
  166. packagingOptions {
  167. pickFirst "lib/armeabi-v7a/libc++_shared.so"
  168. pickFirst "lib/arm64-v8a/libc++_shared.so"
  169. pickFirst "lib/x86/libc++_shared.so"
  170. pickFirst "lib/x86_64/libc++_shared.so"
  171. }
  172. // applicationVariants are e.g. debug, release
  173. applicationVariants.all { variant ->
  174. variant.outputs.each { output ->
  175. // For each separate APK per architecture, set a unique version code as described here:
  176. // https://developer.android.com/studio/build/configure-apk-splits.html
  177. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  178. def abi = output.getFilter(OutputFile.ABI)
  179. if (abi != null) { // null for the universal-debug, universal-release variants
  180. output.versionCodeOverride =
  181. versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
  182. }
  183. }
  184. }
  185. }
  186. dependencies {
  187. implementation fileTree(dir: "libs", include: ["*.jar"])
  188. //noinspection GradleDynamicVersion
  189. implementation "com.facebook.react:react-native:+" // From node_modules
  190. implementation "androidx.appcompat:appcompat:1.1.0-rc01"
  191. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02"
  192. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  193. exclude group:'com.facebook.fbjni'
  194. }
  195. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  196. exclude group:'com.facebook.flipper'
  197. }
  198. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  199. exclude group:'com.facebook.flipper'
  200. }
  201. if (enableHermes) {
  202. def hermesPath = "../../node_modules/hermes-engine/android/";
  203. debugImplementation files(hermesPath + "hermes-debug.aar")
  204. releaseImplementation files(hermesPath + "hermes-release.aar")
  205. } else {
  206. implementation jscFlavor
  207. }
  208. }
  209. // Run this once to be able to run the application with BUCK
  210. // puts all compile dependencies into folder libs for BUCK to use
  211. task copyDownloadableDepsToLibs(type: Copy) {
  212. from configurations.compile
  213. into 'libs'
  214. }
  215. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)