build.gradle 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. ]
  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 that value will be read 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. /**
  115. * Architectures to build native code for.
  116. */
  117. def reactNativeArchitectures() {
  118. def value = project.getProperties().get("reactNativeArchitectures")
  119. return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
  120. }
  121. android {
  122. ndkVersion rootProject.ext.ndkVersion
  123. compileSdkVersion rootProject.ext.compileSdkVersion
  124. defaultConfig {
  125. applicationId "com.denet"
  126. minSdkVersion rootProject.ext.minSdkVersion
  127. targetSdkVersion rootProject.ext.targetSdkVersion
  128. versionCode 1
  129. versionName "1.0"
  130. buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
  131. if (isNewArchitectureEnabled()) {
  132. // We configure the NDK build only if you decide to opt-in for the New Architecture.
  133. externalNativeBuild {
  134. ndkBuild {
  135. arguments "APP_PLATFORM=android-21",
  136. "APP_STL=c++_shared",
  137. "NDK_TOOLCHAIN_VERSION=clang",
  138. "GENERATED_SRC_DIR=$buildDir/generated/source",
  139. "PROJECT_BUILD_DIR=$buildDir",
  140. "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
  141. "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
  142. "NODE_MODULES_DIR=$rootDir/../node_modules"
  143. cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
  144. cppFlags "-std=c++17"
  145. // Make sure this target name is the same you specify inside the
  146. // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
  147. targets "denet_appmodules"
  148. }
  149. }
  150. if (!enableSeparateBuildPerCPUArchitecture) {
  151. ndk {
  152. abiFilters (*reactNativeArchitectures())
  153. }
  154. }
  155. }
  156. }
  157. if (isNewArchitectureEnabled()) {
  158. // We configure the NDK build only if you decide to opt-in for the New Architecture.
  159. externalNativeBuild {
  160. ndkBuild {
  161. path "$projectDir/src/main/jni/Android.mk"
  162. }
  163. }
  164. def reactAndroidProjectDir = project(':ReactAndroid').projectDir
  165. def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
  166. dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
  167. from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
  168. into("$buildDir/react-ndk/exported")
  169. }
  170. def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
  171. dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
  172. from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
  173. into("$buildDir/react-ndk/exported")
  174. }
  175. afterEvaluate {
  176. // If you wish to add a custom TurboModule or component locally,
  177. // you should uncomment this line.
  178. // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
  179. preDebugBuild.dependsOn(packageReactNdkDebugLibs)
  180. preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
  181. // Due to a bug inside AGP, we have to explicitly set a dependency
  182. // between configureNdkBuild* tasks and the preBuild tasks.
  183. // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
  184. configureNdkBuildRelease.dependsOn(preReleaseBuild)
  185. configureNdkBuildDebug.dependsOn(preDebugBuild)
  186. reactNativeArchitectures().each { architecture ->
  187. tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
  188. dependsOn("preDebugBuild")
  189. }
  190. tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
  191. dependsOn("preReleaseBuild")
  192. }
  193. }
  194. }
  195. }
  196. splits {
  197. abi {
  198. reset()
  199. enable enableSeparateBuildPerCPUArchitecture
  200. universalApk false // If true, also generate a universal APK
  201. include (*reactNativeArchitectures())
  202. }
  203. }
  204. signingConfigs {
  205. debug {
  206. storeFile file('debug.keystore')
  207. storePassword 'android'
  208. keyAlias 'androiddebugkey'
  209. keyPassword 'android'
  210. }
  211. }
  212. buildTypes {
  213. debug {
  214. signingConfig signingConfigs.debug
  215. }
  216. release {
  217. // Caution! In production, you need to generate your own keystore file.
  218. // see https://reactnative.dev/docs/signed-apk-android.
  219. signingConfig signingConfigs.debug
  220. minifyEnabled enableProguardInReleaseBuilds
  221. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  222. }
  223. }
  224. // applicationVariants are e.g. debug, release
  225. applicationVariants.all { variant ->
  226. variant.outputs.each { output ->
  227. // For each separate APK per architecture, set a unique version code as described here:
  228. // https://developer.android.com/studio/build/configure-apk-splits.html
  229. // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
  230. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  231. def abi = output.getFilter(OutputFile.ABI)
  232. if (abi != null) { // null for the universal-debug, universal-release variants
  233. output.versionCodeOverride =
  234. defaultConfig.versionCode * 1000 + versionCodes.get(abi)
  235. }
  236. }
  237. }
  238. }
  239. dependencies {
  240. implementation fileTree(dir: "libs", include: ["*.jar"])
  241. //noinspection GradleDynamicVersion
  242. implementation "com.facebook.react:react-native:+" // From node_modules
  243. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
  244. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  245. exclude group:'com.facebook.fbjni'
  246. }
  247. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  248. exclude group:'com.facebook.flipper'
  249. exclude group:'com.squareup.okhttp3', module:'okhttp'
  250. }
  251. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  252. exclude group:'com.facebook.flipper'
  253. }
  254. if (enableHermes) {
  255. //noinspection GradleDynamicVersion
  256. implementation("com.facebook.react:hermes-engine:+") { // From node_modules
  257. exclude group:'com.facebook.fbjni'
  258. }
  259. } else {
  260. implementation jscFlavor
  261. }
  262. }
  263. if (isNewArchitectureEnabled()) {
  264. // If new architecture is enabled, we let you build RN from source
  265. // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
  266. // This will be applied to all the imported transtitive dependency.
  267. configurations.all {
  268. resolutionStrategy.dependencySubstitution {
  269. substitute(module("com.facebook.react:react-native"))
  270. .using(project(":ReactAndroid"))
  271. .because("On New Architecture we're building React Native from source")
  272. substitute(module("com.facebook.react:hermes-engine"))
  273. .using(project(":ReactAndroid:hermes-engine"))
  274. .because("On New Architecture we're building Hermes from source")
  275. }
  276. }
  277. }
  278. // Run this once to be able to run the application with BUCK
  279. // puts all compile dependencies into folder libs for BUCK to use
  280. task copyDownloadableDepsToLibs(type: Copy) {
  281. from configurations.implementation
  282. into 'libs'
  283. }
  284. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
  285. def isNewArchitectureEnabled() {
  286. // To opt-in for the New Architecture, you can either:
  287. // - Set `newArchEnabled` to true inside the `gradle.properties` file
  288. // - Invoke gradle with `-newArchEnabled=true`
  289. // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
  290. return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
  291. }