No Description

build.gradle 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. }
  18. }
  19. def getExtOrIntegerDefault(name) {
  20. return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeWebView_' + name]).toInteger()
  21. }
  22. apply plugin: 'com.android.library'
  23. apply plugin: 'kotlin-android'
  24. android {
  25. compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
  26. buildToolsVersion getExtOrDefault('buildToolsVersion')
  27. defaultConfig {
  28. minSdkVersion 16
  29. targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
  30. versionCode 1
  31. versionName "1.0"
  32. }
  33. buildTypes {
  34. release {
  35. minifyEnabled false
  36. }
  37. }
  38. lintOptions {
  39. disable 'GradleCompatible'
  40. }
  41. compileOptions {
  42. sourceCompatibility JavaVersion.VERSION_1_8
  43. targetCompatibility JavaVersion.VERSION_1_8
  44. }
  45. }
  46. repositories {
  47. mavenCentral()
  48. jcenter()
  49. google()
  50. def found = false
  51. def defaultDir = null
  52. def androidSourcesName = 'React Native sources'
  53. if (rootProject.ext.has('reactNativeAndroidRoot')) {
  54. defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
  55. } else {
  56. defaultDir = new File(
  57. projectDir,
  58. '/../../../node_modules/react-native/android'
  59. )
  60. }
  61. if (defaultDir.exists()) {
  62. maven {
  63. url defaultDir.toString()
  64. name androidSourcesName
  65. }
  66. logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
  67. found = true
  68. } else {
  69. def parentDir = rootProject.projectDir
  70. 1.upto(5, {
  71. if (found) return true
  72. parentDir = parentDir.parentFile
  73. def androidSourcesDir = new File(
  74. parentDir,
  75. 'node_modules/react-native'
  76. )
  77. def androidPrebuiltBinaryDir = new File(
  78. parentDir,
  79. 'node_modules/react-native/android'
  80. )
  81. if (androidPrebuiltBinaryDir.exists()) {
  82. maven {
  83. url androidPrebuiltBinaryDir.toString()
  84. name androidSourcesName
  85. }
  86. logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
  87. found = true
  88. } else if (androidSourcesDir.exists()) {
  89. maven {
  90. url androidSourcesDir.toString()
  91. name androidSourcesName
  92. }
  93. logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
  94. found = true
  95. }
  96. })
  97. }
  98. if (!found) {
  99. throw new GradleException(
  100. "${project.name}: unable to locate React Native android sources. " +
  101. "Ensure you have you installed React Native as a dependency in your project and try again."
  102. )
  103. }
  104. }
  105. def kotlin_version = getExtOrDefault('kotlinVersion')
  106. dependencies {
  107. //noinspection GradleDynamicVersion
  108. implementation 'com.facebook.react:react-native:+'
  109. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  110. }