Skip to content

Commit

Permalink
Simplify build.gradle file
Browse files Browse the repository at this point in the history
  • Loading branch information
radko93 committed Sep 24, 2019
1 parent 5a1920b commit 5751f2a
Showing 1 changed file with 24 additions and 109 deletions.
133 changes: 24 additions & 109 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,135 +1,50 @@
buildscript {
ext.safeExtGet = {prop, fallback ->
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://jitpack.io"
}
}

dependencies {
// Matches the RN Hello World template
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L8
classpath 'com.android.tools.build:gradle:2.2.3'
//noinspection GradleDependency
classpath("com.android.tools.build:gradle:${safeExtGet('gradlePluginVersion', '3.4.1')}")
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 27

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
compileSdkVersion safeExtGet('compileSdkVersion', 28)
//noinspection GradleDependency
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}

lintOptions {
abortOnError false
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
//noinspection OldTargetApi
targetSdkVersion safeExtGet('targetSdkVersion', 28)
}
lintOptions {
abortOnError false
}
}
}

repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches the RN Hello World template
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
url "$projectDir/../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
}
mavenCentral()
}

dependencies {
implementation 'com.facebook.react:react-native:+'
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:${safeExtGet('reactnativeVersion', '+')}"
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.react.rnspinkit"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}

developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}

afterEvaluate { project ->

task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"

configureReactNativePom pom
}
}
}
}

0 comments on commit 5751f2a

Please sign in to comment.