|
| 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 |
| 20 | +} |
| 21 | + |
| 22 | +apply plugin: 'com.android.library' |
| 23 | +apply plugin: 'maven' |
| 24 | + |
| 25 | +buildscript { |
| 26 | + // The Android Gradle plugin is only required when opening the android folder stand-alone. |
| 27 | + // This avoids unnecessary downloads and potential conflicts when the library is included as a |
| 28 | + // module dependency in an application project. |
| 29 | + // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies |
| 30 | + if (project == rootProject) { |
| 31 | + repositories { |
| 32 | + google() |
| 33 | + jcenter() |
| 34 | + } |
| 35 | + dependencies { |
| 36 | + classpath 'com.android.tools.build:gradle:3.4.1' |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +apply plugin: 'com.android.library' |
| 42 | +apply plugin: 'maven' |
| 43 | + |
| 44 | +android { |
| 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 | + } |
| 56 | +} |
| 57 | + |
| 58 | +repositories { |
| 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 | + } |
| 65 | + maven { |
| 66 | + // Android JSC is installed from npm |
| 67 | + url "$rootDir/../node_modules/jsc-android/dist" |
| 68 | + } |
| 69 | + google() |
| 70 | + jcenter() |
| 71 | +} |
| 72 | + |
| 73 | +dependencies { |
| 74 | + //noinspection GradleDynamicVersion |
| 75 | + implementation 'com.facebook.react:react-native:+' // From node_modules |
| 76 | + implementation 'com.wang.avi:library:2.1.3' |
| 77 | +} |
| 78 | + |
| 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 | + } |
| 96 | + } |
| 97 | + |
| 98 | + developers { |
| 99 | + developer { |
| 100 | + id packageJson.author.username |
| 101 | + name packageJson.author.name |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 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 | + } |
| 150 | +} |
0 commit comments