Ingen beskrivning

build.gradle 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. buildscript {
  2. ext.getExtOrDefault = {name ->
  3. return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeWebView_' + name]
  4. }
  5. // The Android Gradle plugin is only required when opening the android folder stand-alone.
  6. // This avoids unnecessary downloads and potential conflicts when the library is included as a
  7. // module dependency in an application project.
  8. if (project == rootProject) {
  9. repositories {
  10. google()
  11. jcenter()
  12. }
  13. dependencies {
  14. classpath("com.android.tools.build:gradle:3.6.0")
  15. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}")
  16. }
  17. } else {
  18. repositories {
  19. jcenter()
  20. }
  21. dependencies {
  22. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}")
  23. }
  24. }
  25. }
  26. def getExtOrIntegerDefault(name) {
  27. return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeWebView_' + name]).toInteger()
  28. }
  29. apply plugin: 'com.android.library'
  30. apply plugin: 'kotlin-android'
  31. android {
  32. compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
  33. buildToolsVersion getExtOrDefault('buildToolsVersion')
  34. defaultConfig {
  35. minSdkVersion 16
  36. targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
  37. versionCode 1
  38. versionName "1.0"
  39. }
  40. buildTypes {
  41. release {
  42. minifyEnabled false
  43. }
  44. }
  45. lintOptions {
  46. disable 'GradleCompatible'
  47. }
  48. compileOptions {
  49. sourceCompatibility JavaVersion.VERSION_1_8
  50. targetCompatibility JavaVersion.VERSION_1_8
  51. }
  52. }
  53. repositories {
  54. mavenCentral()
  55. jcenter()
  56. google()
  57. def found = false
  58. def defaultDir = null
  59. def androidSourcesName = 'React Native sources'
  60. if (rootProject.ext.has('reactNativeAndroidRoot')) {
  61. defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
  62. } else {
  63. defaultDir = new File(
  64. projectDir,
  65. '/../../../node_modules/react-native/android'
  66. )
  67. }
  68. if (defaultDir.exists()) {
  69. maven {
  70. url defaultDir.toString()
  71. name androidSourcesName
  72. }
  73. logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
  74. found = true
  75. } else {
  76. def parentDir = rootProject.projectDir
  77. 1.upto(5, {
  78. if (found) return true
  79. parentDir = parentDir.parentFile
  80. def androidSourcesDir = new File(
  81. parentDir,
  82. 'node_modules/react-native'
  83. )
  84. def androidPrebuiltBinaryDir = new File(
  85. parentDir,
  86. 'node_modules/react-native/android'
  87. )
  88. if (androidPrebuiltBinaryDir.exists()) {
  89. maven {
  90. url androidPrebuiltBinaryDir.toString()
  91. name androidSourcesName
  92. }
  93. logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
  94. found = true
  95. } else if (androidSourcesDir.exists()) {
  96. maven {
  97. url androidSourcesDir.toString()
  98. name androidSourcesName
  99. }
  100. logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
  101. found = true
  102. }
  103. })
  104. }
  105. if (!found) {
  106. throw new GradleException(
  107. "${project.name}: unable to locate React Native android sources. " +
  108. "Ensure you have you installed React Native as a dependency in your project and try again."
  109. )
  110. }
  111. }
  112. def kotlin_version = getExtOrDefault('kotlinVersion')
  113. dependencies {
  114. //noinspection GradleDynamicVersion
  115. implementation 'com.facebook.react:react-native:+'
  116. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  117. }