Skip to content

Commit

Permalink
fix(android): fix monorepo build (#151)
Browse files Browse the repository at this point in the history
* fix(android): fix monorepo build

Please try this in a non monorepo build. Even if it should work fine

* Update build.gradle
  • Loading branch information
Titozzz committed Sep 15, 2021
1 parent fbf9c43 commit ec8fe06
Showing 1 changed file with 36 additions and 57 deletions.
93 changes: 36 additions & 57 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,37 @@ def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Mmkv_' + name]).toInteger()
}

def found = false
def reactNativeDir = null
def androidSourcesName = 'React Native sources'
def parentDir = rootProject.projectDir

if (rootProject.ext.has('reactNativeAndroidRoot')) {
reactNativeDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
reactNativeDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}
if (reactNativeDir.exists()) {
found = true
} else {
1.upto(5, {
if (found) return true
parentDir = reactNativeDir.parentFile

reactNativeDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (reactNativeDir.exists()) {
found = true
}
})
}

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
Expand All @@ -29,13 +60,12 @@ android {
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments '-DANDROID_STL=c++_shared',
"-DNODE_MODULES_DIR=${rootDir}/../node_modules",
"-DNODE_MODULES_DIR=${reactNativeDir.parentFile.parentFile.toString()}",
"-DMMKV_DISABLE_FLUTTER=1"
}
}
Expand Down Expand Up @@ -75,62 +105,12 @@ repositories {
jcenter()
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

if (defaultDir.exists()) {
if (reactNativeDir.exists()) {
maven {
url defaultDir.toString()
url reactNativeDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
logger.info(":${project.name}:reactNativeAndroidRoot ${reactNativeDir.canonicalPath}")
}

if (!found) {
Expand All @@ -144,8 +124,7 @@ repositories {
dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'

def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
def rnAAR = fileTree(reactNativeDir.toString()).matching({ it.include "**/**/*.aar" }).singleFile
extractJNI(files(rnAAR))
}

Expand Down

0 comments on commit ec8fe06

Please sign in to comment.