Skip to content

Commit

Permalink
feat(android): fix android build (#140)
Browse files Browse the repository at this point in the history
* fix android build. react-native version increase

* feat(android): fix android build
  • Loading branch information
gusparis authored Nov 28, 2022
1 parent cc2fed0 commit 3c26eb5
Show file tree
Hide file tree
Showing 11 changed files with 707 additions and 1,086 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ React Native month picker component for iOS and Android.
| <p align="center">***Light*** | <img align="center" src="./screenshots/android_light.png" width="120">|<img align="center" src="./screenshots/ios_light.png" width="120">
| <p align="center">***Dark*** | <img align="center" src="./screenshots/android_dark.png" width="120">|<img align="center" src="./screenshots/ios_dark.png" width="120">

![react-native-month-year-picker](https://github.com/gusparis/react-native-month-year-picker/workflows/react-native-month-year-picker/badge.svg)

## Getting started

`$ npm install react-native-month-year-picker --save`
Expand Down
130 changes: 13 additions & 117 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

def DEFAULT_COMPILE_SDK_VERSION = 29
def DEFAULT_BUILD_TOOLS_VERSION = '29.0.3'
def DEFAULT_COMPILE_SDK_VERSION = 31
def DEFAULT_BUILD_TOOLS_VERSION = '31.0.0'
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 29
def DEFAULT_NDK_VERSION = '20.1.5948944'
def DEFAULT_TARGET_SDK_VERSION = 31

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand All @@ -24,18 +11,13 @@ apply plugin: 'com.android.library'


buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.4'
}
}

Expand All @@ -46,103 +28,17 @@ android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
defaultConfig {
ndkVersion safeExtGet('ndkVersion', DEFAULT_NDK_VERSION)
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}

repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
// Android JSC is installed from npm
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
jcenter()
mavenCentral()
}

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

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.gusparis.monthpicker"
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 ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
project.getConfigurations().getByName('implementation').setCanBeResolved(true)

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()
def javaCompileTask = variant.javaCompileProvider.get()

task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives

}
}
implementation "com.facebook.react:react-native:+"
}
1 change: 0 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion

compileOptions {
Expand Down
17 changes: 6 additions & 11 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

buildscript {
ext {
buildToolsVersion = "29.0.3"
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = '20.1.5948944'
compileSdkVersion = 30
targetSdkVersion = 30
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath('com.android.tools.build:gradle:4.0.1')

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath('com.android.tools.build:gradle:3.5.4')
}
}

allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../../node_modules/react-native/android")
Expand All @@ -31,9 +28,7 @@ allprojects {
// Android JSC is installed from npm
url("$rootDir/../../node_modules/jsc-android/dist")
}

google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
2 changes: 1 addition & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ android.useAndroidX=true
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.75.1
FLIPPER_VERSION=0.99.0
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
4 changes: 2 additions & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, "10.0"
platform :ios, "11.0"
# https://github.com/facebook/react-native/issues/30002#issuecomment-696594433
source "https://github.com/CocoaPods/Specs.git"
# source 'https://cdn.cocoapods.org/'
Expand All @@ -23,7 +23,7 @@ target "example" do
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
use_flipper!
# use_flipper!
post_install do |installer|
react_native_post_install(installer)
installer.pods_project.build_configurations.each do |config|
Expand Down
Loading

0 comments on commit 3c26eb5

Please sign in to comment.