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.
 
 
 
 
 
 

332 line
13 KiB

  1. apply plugin: "com.android.application"
  2. import com.android.build.OutputFile
  3. import org.apache.tools.ant.taskdefs.condition.Os
  4. /**
  5. * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
  6. * and bundleReleaseJsAndAssets).
  7. * These basically call `react-native bundle` with the correct arguments during the Android build
  8. * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
  9. * bundle directly from the development server. Below you can see all the possible configurations
  10. * and their defaults. If you decide to add a configuration block, make sure to add it before the
  11. * `apply from: "../../node_modules/react-native/react.gradle"` line.
  12. *
  13. * project.ext.react = [
  14. * // the name of the generated asset file containing your JS bundle
  15. * bundleAssetName: "index.android.bundle",
  16. *
  17. * // the entry file for bundle generation. If none specified and
  18. * // "index.android.js" exists, it will be used. Otherwise "index.js" is
  19. * // default. Can be overridden with ENTRY_FILE environment variable.
  20. * entryFile: "index.android.js",
  21. *
  22. * // https://reactnative.dev/docs/performance#enable-the-ram-format
  23. * bundleCommand: "ram-bundle",
  24. *
  25. * // whether to bundle JS and assets in debug mode
  26. * bundleInDebug: false,
  27. *
  28. * // whether to bundle JS and assets in release mode
  29. * bundleInRelease: true,
  30. *
  31. * // whether to bundle JS and assets in another build variant (if configured).
  32. * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
  33. * // The configuration property can be in the following formats
  34. * // 'bundleIn${productFlavor}${buildType}'
  35. * // 'bundleIn${buildType}'
  36. * // bundleInFreeDebug: true,
  37. * // bundleInPaidRelease: true,
  38. * // bundleInBeta: true,
  39. *
  40. * // whether to disable dev mode in custom build variants (by default only disabled in release)
  41. * // for example: to disable dev mode in the staging build type (if configured)
  42. * devDisabledInStaging: true,
  43. * // The configuration property can be in the following formats
  44. * // 'devDisabledIn${productFlavor}${buildType}'
  45. * // 'devDisabledIn${buildType}'
  46. *
  47. * // the root of your project, i.e. where "package.json" lives
  48. * root: "../../",
  49. *
  50. * // where to put the JS bundle asset in debug mode
  51. * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
  52. *
  53. * // where to put the JS bundle asset in release mode
  54. * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
  55. *
  56. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  57. * // require('./image.png')), in debug mode
  58. * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
  59. *
  60. * // where to put drawable resources / React Native assets, e.g. the ones you use via
  61. * // require('./image.png')), in release mode
  62. * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
  63. *
  64. * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
  65. * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
  66. * // date; if you have any other folders that you want to ignore for performance reasons (gradle
  67. * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
  68. * // for example, you might want to remove it from here.
  69. * inputExcludes: ["android/**", "ios/**"],
  70. *
  71. * // override which node gets called and with what additional arguments
  72. * nodeExecutableAndArgs: ["node"],
  73. *
  74. * // supply additional arguments to the packager
  75. * extraPackagerArgs: []
  76. * ]
  77. */
  78. project.ext.vectoricons = [
  79. iconFontNames: [
  80. "MaterialCommunityIcons.ttf",
  81. "FontAwesome.ttf",
  82. ]
  83. ]
  84. apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
  85. project.ext.react = [
  86. enableHermes: true, // clean and rebuild if changing
  87. ]
  88. apply from: "../../node_modules/react-native/react.gradle"
  89. /**
  90. * Set this to true to create two separate APKs instead of one:
  91. * - An APK that only works on ARM devices
  92. * - An APK that only works on x86 devices
  93. * The advantage is the size of the APK is reduced by about 4MB.
  94. * Upload all the APKs to the Play Store and people will download
  95. * the correct one based on the CPU architecture of their device.
  96. */
  97. def enableSeparateBuildPerCPUArchitecture = true
  98. /**
  99. * Run Proguard to shrink the Java bytecode in release builds.
  100. */
  101. def enableProguardInReleaseBuilds = false
  102. /**
  103. * The preferred build flavor of JavaScriptCore.
  104. *
  105. * For example, to use the international variant, you can use:
  106. * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
  107. *
  108. * The international variant includes ICU i18n library and necessary data
  109. * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
  110. * give correct results when using with locales other than en-US. Note that
  111. * this variant is about 6MiB larger per architecture than default.
  112. */
  113. def jscFlavor = 'org.webkit:android-jsc:+'
  114. /**
  115. * Whether to enable the Hermes VM.
  116. *
  117. * This should be set on project.ext.react and that value will be read here. If it is not set
  118. * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
  119. * and the benefits of using Hermes will therefore be sharply reduced.
  120. */
  121. def enableHermes = project.ext.react.get("enableHermes", false);
  122. /**
  123. * Architectures to build native code for.
  124. */
  125. def reactNativeArchitectures() {
  126. def value = project.getProperties().get("reactNativeArchitectures")
  127. return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
  128. }
  129. android {
  130. ndkVersion rootProject.ext.ndkVersion
  131. compileSdkVersion rootProject.ext.compileSdkVersion
  132. defaultConfig {
  133. applicationId "com.lesspass.android"
  134. minSdkVersion rootProject.ext.minSdkVersion
  135. targetSdkVersion rootProject.ext.targetSdkVersion
  136. versionCode 9007003
  137. versionName "9.7.3"
  138. buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
  139. if (isNewArchitectureEnabled()) {
  140. // We configure the CMake build only if you decide to opt-in for the New Architecture.
  141. externalNativeBuild {
  142. cmake {
  143. arguments "-DPROJECT_BUILD_DIR=$buildDir",
  144. "-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
  145. "-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
  146. "-DNODE_MODULES_DIR=$rootDir/../node_modules",
  147. "-DANDROID_STL=c++_shared"
  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. cmake {
  161. path "$projectDir/src/main/jni/CMakeLists.txt"
  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 configureCMakeDebug* tasks and the preBuild tasks.
  183. // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
  184. configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
  185. configureCMakeDebug.dependsOn(preDebugBuild)
  186. reactNativeArchitectures().each { architecture ->
  187. tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
  188. dependsOn("preDebugBuild")
  189. }
  190. tasks.findByName("configureCMakeRelWithDebInfo[${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. release {
  212. if (project.hasProperty('LESSPASS_RELEASE_STORE_FILE')) {
  213. storeFile file(LESSPASS_RELEASE_STORE_FILE)
  214. storePassword LESSPASS_RELEASE_STORE_PASSWORD
  215. keyAlias LESSPASS_RELEASE_KEY_ALIAS
  216. keyPassword LESSPASS_RELEASE_KEY_PASSWORD
  217. }
  218. }
  219. }
  220. buildTypes {
  221. debug {
  222. signingConfig signingConfigs.debug
  223. }
  224. release {
  225. minifyEnabled enableProguardInReleaseBuilds
  226. proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
  227. signingConfig signingConfigs.release
  228. manifestPlaceholders = [excludeSystemAlertWindowPermission: "true"]
  229. }
  230. }
  231. // applicationVariants are e.g. debug, release
  232. applicationVariants.all { variant ->
  233. variant.outputs.each { output ->
  234. // For each separate APK per architecture, set a unique version code as described here:
  235. // https://developer.android.com/studio/build/configure-apk-splits.html
  236. // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
  237. def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
  238. def abi = output.getFilter(OutputFile.ABI)
  239. if (abi != null) { // null for the universal-debug, universal-release variants
  240. output.versionCodeOverride =
  241. defaultConfig.versionCode * 100 + versionCodes.get(abi)
  242. }
  243. }
  244. }
  245. }
  246. dependencies {
  247. implementation fileTree(dir: "libs", include: ["*.jar"])
  248. //noinspection GradleDynamicVersion
  249. implementation "com.facebook.react:react-native:+" // From node_modules
  250. implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
  251. debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  252. exclude group:'com.facebook.fbjni'
  253. }
  254. debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
  255. exclude group:'com.facebook.flipper'
  256. exclude group:'com.squareup.okhttp3', module:'okhttp'
  257. }
  258. debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
  259. exclude group:'com.facebook.flipper'
  260. }
  261. implementation "com.madgag.spongycastle:core:1.58.0.0"
  262. if (enableHermes) {
  263. //noinspection GradleDynamicVersion
  264. implementation("com.facebook.react:hermes-engine:+") { // From node_modules
  265. exclude group:'com.facebook.fbjni'
  266. }
  267. } else {
  268. implementation jscFlavor
  269. }
  270. testImplementation "junit:junit:4.12"
  271. }
  272. if (isNewArchitectureEnabled()) {
  273. // If new architecture is enabled, we let you build RN from source
  274. // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
  275. // This will be applied to all the imported transtitive dependency.
  276. configurations.all {
  277. resolutionStrategy.dependencySubstitution {
  278. substitute(module("com.facebook.react:react-native"))
  279. .using(project(":ReactAndroid"))
  280. .because("On New Architecture we're building React Native from source")
  281. substitute(module("com.facebook.react:hermes-engine"))
  282. .using(project(":ReactAndroid:hermes-engine"))
  283. .because("On New Architecture we're building Hermes from source")
  284. }
  285. }
  286. }
  287. // Run this once to be able to run the application with BUCK
  288. // puts all compile dependencies into folder libs for BUCK to use
  289. task copyDownloadableDepsToLibs(type: Copy) {
  290. from configurations.implementation
  291. into 'libs'
  292. }
  293. apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
  294. def isNewArchitectureEnabled() {
  295. // To opt-in for the New Architecture, you can either:
  296. // - Set `newArchEnabled` to true inside the `gradle.properties` file
  297. // - Invoke gradle with `-newArchEnabled=true`
  298. // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
  299. return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
  300. }