|
1 | | -// android/build.gradle |
2 | | - |
3 | | -// based on: |
4 | | -// |
5 | | -// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle |
6 | | -// original location: |
7 | | -// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle |
8 | | -// |
9 | | -// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle |
10 | | -// original location: |
11 | | -// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle |
12 | | - |
13 | | -def DEFAULT_COMPILE_SDK_VERSION = 28 |
14 | | -def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3' |
15 | | -def DEFAULT_MIN_SDK_VERSION = 16 |
16 | | -def DEFAULT_TARGET_SDK_VERSION = 28 |
17 | | - |
18 | | -def safeExtGet(prop, fallback) { |
19 | | - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 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['WebView_kotlinVersion'] |
| 4 | + |
| 5 | + repositories { |
| 6 | + google() |
| 7 | + jcenter() |
| 8 | + } |
| 9 | + |
| 10 | + dependencies { |
| 11 | + classpath 'com.android.tools.build:gradle:4.1.2' |
| 12 | + } |
20 | 13 | } |
21 | 14 |
|
22 | 15 | apply plugin: 'com.android.library' |
23 | 16 |
|
24 | | -buildscript { |
25 | | - // The Android Gradle plugin is only required when opening the android folder stand-alone. |
26 | | - // This avoids unnecessary downloads and potential conflicts when the library is included as a |
27 | | - // module dependency in an application project. |
28 | | - // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies |
29 | | - if (project == rootProject) { |
30 | | - repositories { |
31 | | - google() |
32 | | - jcenter() |
33 | | - } |
34 | | - dependencies { |
35 | | - classpath 'com.android.tools.build:gradle:3.4.1' |
36 | | - } |
37 | | - } |
| 17 | +def getExtOrDefault(name) { |
| 18 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['DrawCanvas_' + name] |
| 19 | +} |
| 20 | + |
| 21 | +def getExtOrIntegerDefault(name) { |
| 22 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['DrawCanvas_' + name]).toInteger() |
38 | 23 | } |
39 | 24 |
|
40 | 25 | android { |
41 | | - compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) |
42 | | - buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) |
43 | | - defaultConfig { |
44 | | - minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) |
45 | | - targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) |
46 | | - versionCode 1 |
47 | | - versionName "1.0" |
48 | | - } |
49 | | - lintOptions { |
50 | | - abortOnError false |
| 26 | + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') |
| 27 | + buildToolsVersion getExtOrDefault('buildToolsVersion') |
| 28 | + defaultConfig { |
| 29 | + minSdkVersion 23 |
| 30 | + targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') |
| 31 | + versionCode 1 |
| 32 | + versionName "1.0" |
| 33 | + } |
| 34 | + |
| 35 | + buildTypes { |
| 36 | + release { |
| 37 | + minifyEnabled false |
51 | 38 | } |
| 39 | + } |
| 40 | + lintOptions { |
| 41 | + disable 'GradleCompatible' |
| 42 | + } |
| 43 | + compileOptions { |
| 44 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 45 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 46 | + } |
52 | 47 | } |
53 | 48 |
|
54 | 49 | repositories { |
55 | | - // ref: https://www.baeldung.com/maven-local-repository |
56 | | - mavenLocal() |
57 | | - maven { |
58 | | - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm |
59 | | - url "$rootDir/../node_modules/react-native/android" |
60 | | - } |
| 50 | + mavenCentral() |
| 51 | + jcenter() |
| 52 | + google() |
| 53 | + |
| 54 | + def found = false |
| 55 | + def defaultDir = null |
| 56 | + def androidSourcesName = 'React Native sources' |
| 57 | + |
| 58 | + if (rootProject.ext.has('reactNativeAndroidRoot')) { |
| 59 | + defaultDir = rootProject.ext.get('reactNativeAndroidRoot') |
| 60 | + } else { |
| 61 | + defaultDir = new File( |
| 62 | + projectDir, |
| 63 | + '/../../../node_modules/react-native/android' |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + if (defaultDir.exists()) { |
61 | 68 | maven { |
62 | | - // Android JSC is installed from npm |
63 | | - url "$rootDir/../node_modules/jsc-android/dist" |
| 69 | + url defaultDir.toString() |
| 70 | + name androidSourcesName |
64 | 71 | } |
65 | | - google() |
66 | | - jcenter() |
67 | | -} |
68 | | - |
69 | | -dependencies { |
70 | | - //noinspection GradleDynamicVersion |
71 | | - implementation 'com.facebook.react:react-native:+' // From node_modules |
72 | | -} |
73 | 72 |
|
74 | | -def configureReactNativePom(def pom) { |
75 | | - def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) |
76 | | - |
77 | | - pom.project { |
78 | | - name packageJson.title |
79 | | - artifactId packageJson.name |
80 | | - version = packageJson.version |
81 | | - group = "com.reactlibrary" |
82 | | - description packageJson.description |
83 | | - url packageJson.repository.baseUrl |
84 | | - |
85 | | - licenses { |
86 | | - license { |
87 | | - name packageJson.license |
88 | | - url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename |
89 | | - distribution 'repo' |
90 | | - } |
| 73 | + logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}") |
| 74 | + found = true |
| 75 | + } else { |
| 76 | + def parentDir = rootProject.projectDir |
| 77 | + |
| 78 | + 1.upto(5, { |
| 79 | + if (found) return true |
| 80 | + parentDir = parentDir.parentFile |
| 81 | + |
| 82 | + def androidSourcesDir = new File( |
| 83 | + parentDir, |
| 84 | + 'node_modules/react-native' |
| 85 | + ) |
| 86 | + |
| 87 | + def androidPrebuiltBinaryDir = new File( |
| 88 | + parentDir, |
| 89 | + 'node_modules/react-native/android' |
| 90 | + ) |
| 91 | + |
| 92 | + if (androidPrebuiltBinaryDir.exists()) { |
| 93 | + maven { |
| 94 | + url androidPrebuiltBinaryDir.toString() |
| 95 | + name androidSourcesName |
91 | 96 | } |
92 | 97 |
|
93 | | - developers { |
94 | | - developer { |
95 | | - id packageJson.author.username |
96 | | - name packageJson.author.name |
97 | | - } |
| 98 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}") |
| 99 | + found = true |
| 100 | + } else if (androidSourcesDir.exists()) { |
| 101 | + maven { |
| 102 | + url androidSourcesDir.toString() |
| 103 | + name androidSourcesName |
98 | 104 | } |
99 | | - } |
100 | | -} |
101 | | - |
102 | | -afterEvaluate { project -> |
103 | | - // some Gradle build hooks ref: |
104 | | - // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html |
105 | | - task androidJavadoc(type: Javadoc) { |
106 | | - source = android.sourceSets.main.java.srcDirs |
107 | | - classpath += files(android.bootClasspath) |
108 | | - classpath += files(project.getConfigurations().getByName('compile').asList()) |
109 | | - include '**/*.java' |
110 | | - } |
111 | | - |
112 | | - task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { |
113 | | - classifier = 'javadoc' |
114 | | - from androidJavadoc.destinationDir |
115 | | - } |
116 | | - |
117 | | - task androidSourcesJar(type: Jar) { |
118 | | - classifier = 'sources' |
119 | | - from android.sourceSets.main.java.srcDirs |
120 | | - include '**/*.java' |
121 | | - } |
122 | 105 |
|
123 | | - android.libraryVariants.all { variant -> |
124 | | - def name = variant.name.capitalize() |
125 | | - def javaCompileTask = variant.javaCompileProvider.get() |
| 106 | + logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") |
| 107 | + found = true |
| 108 | + } |
| 109 | + }) |
| 110 | + } |
| 111 | + |
| 112 | + if (!found) { |
| 113 | + throw new GradleException( |
| 114 | + "${project.name}: unable to locate React Native android sources. " + |
| 115 | + "Ensure you have you installed React Native as a dependency in your project and try again." |
| 116 | + ) |
| 117 | + } |
| 118 | +} |
126 | 119 |
|
127 | | - task "jar${name}"(type: Jar, dependsOn: javaCompileTask) { |
128 | | - from javaCompileTask.destinationDir |
129 | | - } |
130 | | - } |
| 120 | +def kotlin_version = getExtOrDefault('kotlin_version') |
131 | 121 |
|
132 | | - artifacts { |
133 | | - archives androidSourcesJar |
134 | | - archives androidJavadocJar |
135 | | - } |
136 | | - |
137 | | - task installArchives(type: Upload) { |
138 | | - configuration = configurations.archives |
139 | | - repositories.mavenDeployer { |
140 | | - // Deploy to react-native-event-bridge/maven, ready to publish to npm |
141 | | - repository url: "file://${projectDir}/../android/maven" |
142 | | - configureReactNativePom pom |
143 | | - } |
144 | | - } |
| 122 | +dependencies { |
| 123 | + // noinspection GradleDynamicVersion |
| 124 | + api 'com.facebook.react:react-native:+' |
| 125 | + api project(':padlet_rn-foundation') |
| 126 | + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" |
| 127 | + implementation project(path: ':react-native-webview') |
| 128 | + testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' |
145 | 129 | } |
0 commit comments