Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve build issues with React Native 0.69-0.71 #667

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use safeExtGet
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : "1.8.0"
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNKeychain_kotlinVersion']
repositories {
maven {
url "https://plugins.gradle.org/m2/"
Expand All @@ -22,11 +22,13 @@ def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply from: "$projectDir/react-native-helpers.gradle"

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

repositories {
google()
Expand All @@ -38,13 +40,12 @@ android {
if (project.android.hasProperty("namespace")) {
namespace = "com.oblador.keychain"
}
compileSdkVersion safeExtGet('compileSdkVersion', 34)
buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0')
compileSdkVersion safeExtGet('compileSdkVersion', project.properties['RNKeychain_compileSdkVersion'])

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 23)
compileSdkVersion safeExtGet('compileSdkVersion', 34)
targetSdkVersion safeExtGet('targetSdkVersion', 34)
minSdkVersion safeExtGet('minSdkVersion', project.properties['RNKeychain_minSdkVersion'])
compileSdkVersion safeExtGet('compileSdkVersion', project.properties['RNKeychain_compileSdkVersion'])
targetSdkVersion safeExtGet('targetSdkVersion', project.properties['RNKeychain_targetSdkVersion'])
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

Expand All @@ -56,22 +57,22 @@ android {
buildFeatures {
buildConfig true
}

lintOptions {
disable "GradleCompatible"
abortOnError false
}
}

repositories {
mavenCentral()
}

def kotlin_version = safeExtGet('kotlinVersion', '1.8.0')
def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNKeychain_kotlinVersion'])

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-android:+"
if (project.ext.shouldConsumeReactNativeFromMavenCentral()) {
// noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-android:+'
} else {
// noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
}
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand Down
5 changes: 5 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ org.gradle.daemon=true
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

RNKeychain_kotlinVersion=1.8.0
RNKeychain_compileSdkVersion=34
RNKeychain_targetSdkVersion=34
RNKeychain_minSdkVersion=23
48 changes: 48 additions & 0 deletions android/react-native-helpers.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
def safeAppExtGet(prop, fallback) {
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
}

// Let's detect react-native's directory, it will be used to determine RN's version
// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L88
def resolveReactNativeDirectory() {
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromNodeModules = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModules.exists()) {
return reactNativeFromNodeModules
}

throw new GradleException(
"${project.name}: unable to resolve react-native location in " +
"node_modules. You should project extension property (in app/build.gradle) " +
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
)
}

// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L199#L205
def reactNativeRootDir = resolveReactNativeDirectory()

def reactProperties = new Properties()
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }

def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()

project.ext.resolveReactNativeDirectory = { ->
return resolveReactNativeDirectory()
}

project.ext.shouldConsumeReactNativeFromMavenCentral = { ->
return REACT_NATIVE_MINOR_VERSION >= 71
}
Loading