暫無描述

build.gradle 3.0KB

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