|
| 1 | +// android/build.gradle |
| 2 | + |
| 3 | +def safeExtGet(prop, fallback) { |
| 4 | + rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 5 | +} |
| 6 | + |
| 7 | +buildscript { |
| 8 | + // The Android Gradle plugin is only required when opening the android folder stand-alone. |
| 9 | + // This avoids unnecessary downloads and potential conflicts when the library is included as a |
| 10 | + // module dependency in an application project. |
| 11 | + if (project == rootProject) { |
| 12 | + repositories { |
| 13 | + google() |
| 14 | + jcenter() |
| 15 | + } |
| 16 | + dependencies { |
| 17 | + classpath 'com.android.tools.build:gradle:3.4.1' |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +apply plugin: 'com.android.library' |
| 23 | +apply plugin: 'maven' |
| 24 | + |
| 25 | +// Matches values in recent template from React Native 0.59 / 0.60 |
| 26 | +// https://github.com/facebook/react-native/blob/0.59-stable/template/android/build.gradle#L5-L9 |
| 27 | +// https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle#L5-L9 |
| 28 | +def DEFAULT_COMPILE_SDK_VERSION = 28 |
| 29 | +def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3" |
| 30 | +def DEFAULT_MIN_SDK_VERSION = 16 |
| 31 | +def DEFAULT_TARGET_SDK_VERSION = 28 |
| 32 | + |
| 33 | +android { |
| 34 | + compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) |
| 35 | + buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION) |
| 36 | + defaultConfig { |
| 37 | + minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) |
| 38 | + targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) |
| 39 | + versionCode 1 |
| 40 | + versionName "1.0" |
| 41 | + } |
| 42 | + lintOptions { |
| 43 | + abortOnError false |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +repositories { |
| 48 | + mavenLocal() |
| 49 | + maven { |
| 50 | + // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm |
| 51 | + url "$rootDir/../node_modules/react-native/android" |
| 52 | + } |
| 53 | + maven { |
| 54 | + // Android JSC is installed from npm |
| 55 | + url "$rootDir/../node_modules/jsc-android/dist" |
| 56 | + } |
| 57 | + google() |
| 58 | + jcenter() |
| 59 | +} |
| 60 | + |
| 61 | +dependencies { |
| 62 | + // ref: |
| 63 | + // https://github.com/facebook/react-native/blob/0.61-stable/template/android/app/build.gradle#L192 |
| 64 | + //noinspection GradleDynamicVersion |
| 65 | + implementation 'com.facebook.react:react-native:+' // From node_modules |
| 66 | +} |
| 67 | + |
| 68 | +def configureReactNativePom(def pom) { |
| 69 | + def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text) |
| 70 | + |
| 71 | + pom.project { |
| 72 | + name packageJson.title |
| 73 | + artifactId packageJson.name |
| 74 | + version = packageJson.version |
| 75 | + group = "com.reactnative.createguid" |
| 76 | + description packageJson.description |
| 77 | + url packageJson.repository.baseUrl |
| 78 | + |
| 79 | + licenses { |
| 80 | + license { |
| 81 | + name packageJson.license |
| 82 | + url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename |
| 83 | + distribution 'repo' |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + developers { |
| 88 | + developer { |
| 89 | + id packageJson.author.username |
| 90 | + name packageJson.author.name |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +afterEvaluate { project -> |
| 97 | + // some Gradle build hooks ref: |
| 98 | + // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html |
| 99 | + task androidJavadoc(type: Javadoc) { |
| 100 | + source = android.sourceSets.main.java.srcDirs |
| 101 | + classpath += files(android.bootClasspath) |
| 102 | + classpath += files(project.getConfigurations().getByName('compile').asList()) |
| 103 | + include '**/*.java' |
| 104 | + } |
| 105 | + |
| 106 | + task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) { |
| 107 | + classifier = 'javadoc' |
| 108 | + from androidJavadoc.destinationDir |
| 109 | + } |
| 110 | + |
| 111 | + task androidSourcesJar(type: Jar) { |
| 112 | + classifier = 'sources' |
| 113 | + from android.sourceSets.main.java.srcDirs |
| 114 | + include '**/*.java' |
| 115 | + } |
| 116 | + |
| 117 | + android.libraryVariants.all { variant -> |
| 118 | + def name = variant.name.capitalize() |
| 119 | + task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) { |
| 120 | + from variant.javaCompile.destinationDir |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + artifacts { |
| 125 | + archives androidSourcesJar |
| 126 | + archives androidJavadocJar |
| 127 | + } |
| 128 | + |
| 129 | + task installArchives(type: Upload) { |
| 130 | + configuration = configurations.archives |
| 131 | + repositories.mavenDeployer { |
| 132 | + // Deploy to react-native-event-bridge/maven, ready to publish to npm |
| 133 | + repository url: "file://${projectDir}/../android/maven" |
| 134 | + configureReactNativePom pom |
| 135 | + } |
| 136 | + } |
| 137 | +} |
0 commit comments