|
| 1 | +buildscript { |
| 2 | + // Buildscript is evaluated before everything else so we can't use getExtOrDefault |
| 3 | + def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Lnc_kotlinVersion'] |
| 4 | + |
| 5 | + repositories { |
| 6 | + google() |
| 7 | + jcenter() |
| 8 | + } |
| 9 | + |
| 10 | + dependencies { |
| 11 | + classpath 'com.android.tools.build:gradle:3.2.1' |
| 12 | + // noinspection DifferentKotlinGradleVersion |
| 13 | + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +apply plugin: 'com.android.library' |
| 18 | +apply plugin: 'kotlin-android' |
| 19 | + |
| 20 | +def getExtOrDefault(name) { |
| 21 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Lnc_' + name] |
| 22 | +} |
| 23 | + |
| 24 | +def getExtOrIntegerDefault(name) { |
| 25 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Lnc_' + name]).toInteger() |
| 26 | +} |
| 27 | + |
| 28 | +android { |
| 29 | + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') |
| 30 | + buildToolsVersion getExtOrDefault('buildToolsVersion') |
| 31 | + defaultConfig { |
| 32 | + minSdkVersion rootProject.ext.has('minSdkVersion') ? rootProject.ext.minSdkVersion : 16 |
| 33 | + targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') |
| 34 | + versionCode 1 |
| 35 | + versionName "1.0" |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + buildTypes { |
| 40 | + release { |
| 41 | + minifyEnabled false |
| 42 | + } |
| 43 | + } |
| 44 | + lintOptions { |
| 45 | + disable 'GradleCompatible' |
| 46 | + } |
| 47 | + compileOptions { |
| 48 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 49 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +repositories { |
| 54 | + mavenCentral() |
| 55 | + jcenter() |
| 56 | + google() |
| 57 | + flatDir { |
| 58 | + dirs 'libs' |
| 59 | + } |
| 60 | + |
| 61 | + def found = false |
| 62 | + def defaultDir = null |
| 63 | + def androidSourcesName = 'React Native sources' |
| 64 | + |
| 65 | + if (rootProject.ext.has('reactNativeAndroidRoot')) { |
| 66 | + defaultDir = rootProject.ext.get('reactNativeAndroidRoot') |
| 67 | + } else { |
| 68 | + defaultDir = new File( |
| 69 | + projectDir, |
| 70 | + '/../../../node_modules/react-native/android' |
| 71 | + ) |
| 72 | + } |
| 73 | + |
| 74 | + if (defaultDir.exists()) { |
| 75 | + maven { |
| 76 | + url defaultDir.toString() |
| 77 | + name androidSourcesName |
| 78 | + } |
| 79 | + |
| 80 | + logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") |
| 81 | + found = true |
| 82 | + } else { |
| 83 | + def parentDir = rootProject.projectDir |
| 84 | + |
| 85 | + 1.upto(5, { |
| 86 | + if (found) return true |
| 87 | + parentDir = parentDir.parentFile |
| 88 | + |
| 89 | + def androidSourcesDir = new File( |
| 90 | + parentDir, |
| 91 | + 'node_modules/react-native' |
| 92 | + ) |
| 93 | + |
| 94 | + def androidPrebuiltBinaryDir = new File( |
| 95 | + parentDir, |
| 96 | + 'node_modules/react-native/android' |
| 97 | + ) |
| 98 | + |
| 99 | + if (androidPrebuiltBinaryDir.exists()) { |
| 100 | + maven { |
| 101 | + url androidPrebuiltBinaryDir.toString() |
| 102 | + name androidSourcesName |
| 103 | + } |
| 104 | + |
| 105 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") |
| 106 | + found = true |
| 107 | + } else if (androidSourcesDir.exists()) { |
| 108 | + maven { |
| 109 | + url androidSourcesDir.toString() |
| 110 | + name androidSourcesName |
| 111 | + } |
| 112 | + |
| 113 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") |
| 114 | + found = true |
| 115 | + } |
| 116 | + }) |
| 117 | + } |
| 118 | + |
| 119 | + if (!found) { |
| 120 | + throw new GradleException( |
| 121 | + "${project.name}: unable to locate React Native android sources. " + |
| 122 | + "Ensure you have you installed React Native as a dependency in your project and try again." |
| 123 | + ) |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +def kotlin_version = getExtOrDefault('kotlinVersion') |
| 128 | + |
| 129 | +dependencies { |
| 130 | + // noinspection GradleDynamicVersion |
| 131 | + api 'com.facebook.react:react-native:+' |
| 132 | + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 133 | + compileOnly files('libs/lnc-mobile.aar') |
| 134 | +} |
0 commit comments