react-native-navigation的迁移库

build.gradle 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import groovy.json.JsonSlurper
  2. apply plugin: 'com.android.library'
  3. apply plugin: 'kotlin-android'
  4. apply plugin: 'kotlin-android-extensions'
  5. def safeExtGet(prop, fallback) {
  6. rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
  7. }
  8. def DEFAULT_COMPILE_SDK_VERSION = 28
  9. def DEFAULT_MIN_SDK_VERSION = 19
  10. def DEFAULT_TARGET_SDK_VERSION = 28
  11. def kotlinVersion = rootProject.ext.get("RNNKotlinVersion")
  12. def kotlinStdlib = safeExtGet('RNNKotlinStdlib', 'kotlin-stdlib-jdk8')
  13. android {
  14. compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
  15. defaultConfig {
  16. minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
  17. targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
  18. versionCode 1
  19. versionName "1.0"
  20. }
  21. buildTypes {
  22. release {
  23. minifyEnabled false
  24. }
  25. debug {
  26. minifyEnabled false
  27. }
  28. }
  29. lintOptions {
  30. abortOnError false
  31. }
  32. testOptions {
  33. unitTests.includeAndroidResources = true
  34. unitTests.all { t ->
  35. reports {
  36. html.enabled true
  37. }
  38. testLogging {
  39. events "PASSED", "SKIPPED", "FAILED", "standardOut", "standardError"
  40. }
  41. afterSuite { desc, result ->
  42. if (!desc.parent) { // will match the outermost suite
  43. def output = " ${result.resultType} (${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped) "
  44. def repeatLength = output.length()
  45. println '\n\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength) + '\n'
  46. println "see report at file://${t.reports.html.destination}/index.html"
  47. }
  48. }
  49. }
  50. }
  51. compileOptions {
  52. sourceCompatibility JavaVersion.VERSION_1_8
  53. targetCompatibility JavaVersion.VERSION_1_8
  54. }
  55. flavorDimensions "RNN.reactNativeVersion"
  56. productFlavors {
  57. reactNative51 {
  58. dimension "RNN.reactNativeVersion"
  59. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "51")
  60. }
  61. reactNative55 {
  62. dimension "RNN.reactNativeVersion"
  63. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "55")
  64. }
  65. reactNative56 {
  66. dimension "RNN.reactNativeVersion"
  67. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "56")
  68. }
  69. reactNative57 {
  70. dimension "RNN.reactNativeVersion"
  71. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "57")
  72. }
  73. reactNative57_5 {
  74. dimension "RNN.reactNativeVersion"
  75. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "57")
  76. }
  77. reactNative60 {
  78. dimension "RNN.reactNativeVersion"
  79. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "60")
  80. }
  81. reactNative62 {
  82. dimension "RNN.reactNativeVersion"
  83. buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "62")
  84. }
  85. }
  86. def flavor = resolveFlavor()
  87. variantFilter { variant ->
  88. def names = variant.flavors*.name
  89. if (!names.contains(flavor)) {
  90. setIgnore(true)
  91. }
  92. }
  93. }
  94. String resolveFlavor() {
  95. List reactNativeVersionComponents = reactNativeVersionComponents(findReactNativePackageJson())
  96. Integer reactNativeMinorComponent = reactNativeVersionComponents[1].toInteger()
  97. Integer reactNativePatchComponent = reactNativeVersionComponents[2].toInteger()
  98. if (reactNativeMinorComponent >= 62) {
  99. return "reactNative62"
  100. } else if (reactNativeMinorComponent >= 60) {
  101. return "reactNative60"
  102. } else if (reactNativeMinorComponent >= 57 && reactNativePatchComponent >= 5) {
  103. return "reactNative57_5"
  104. } else if (reactNativeMinorComponent >= 57) {
  105. return "reactNative57"
  106. } else if (reactNativeMinorComponent >= 56) {
  107. return "reactNative56"
  108. } else if (reactNativeMinorComponent >= 55) {
  109. return "reactNative55"
  110. } else if (reactNativeMinorComponent >= 51) {
  111. return "reactNative51"
  112. }
  113. }
  114. Object findReactNativePackageJson() {
  115. def searchPath = 'node_modules/react-native/package.json'
  116. def projectDir = project.projectDir.toString() + '/'
  117. def rnPackageJsonFile = new File(projectDir + searchPath)
  118. while (!rnPackageJsonFile.exists()) {
  119. searchPath = '../' + searchPath
  120. rnPackageJsonFile = new File(projectDir + searchPath)
  121. }
  122. return rnPackageJsonFile
  123. }
  124. List reactNativeVersionComponents(rnPackageJsonFile) {
  125. def packageSlurper = new JsonSlurper()
  126. def reactNativePackageJson = packageSlurper.parseText(rnPackageJsonFile.text)
  127. def reactNativeVersion = reactNativePackageJson.version
  128. return reactNativeVersion.tokenize('-')[0].tokenize('.')
  129. }
  130. allprojects { p ->
  131. p.afterEvaluate {
  132. p.android.compileOptions.sourceCompatibility JavaVersion.VERSION_1_8
  133. p.android.compileOptions.targetCompatibility JavaVersion.VERSION_1_8
  134. }
  135. p.repositories {
  136. maven { url "https://jitpack.io" }
  137. }
  138. }
  139. dependencies {
  140. implementation "androidx.core:core-ktx:1.1.0"
  141. implementation "org.jetbrains.kotlin:$kotlinStdlib:$kotlinVersion"
  142. implementation 'androidx.appcompat:appcompat:1.1.0'
  143. implementation 'androidx.annotation:annotation:1.1.0'
  144. implementation 'com.google.android.material:material:1.2.0-alpha03'
  145. implementation 'com.github.wix-playground:ahbottomnavigation:3.2.0'
  146. implementation 'com.github.wix-playground:reflow-animator:1.0.6'
  147. implementation 'com.github.clans:fab:1.6.4'
  148. //noinspection GradleDynamicVersion
  149. implementation 'com.facebook.react:react-native:+'
  150. // tests
  151. testImplementation 'junit:junit:4.12'
  152. testImplementation "org.robolectric:robolectric:4.3-beta-1"
  153. testImplementation 'org.assertj:assertj-core:3.8.0'
  154. testImplementation 'com.squareup.assertj:assertj-android:1.1.1'
  155. testImplementation 'org.mockito:mockito-core:2.28.2'
  156. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  157. }