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