Skip to content

Commit 0398988

Browse files
committed
Update Android namespace location
1 parent 3b4d22f commit 0398988

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

android/build.gradle

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,97 @@
1+
def safeAppExtGet(prop, fallback) {
2+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
3+
appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
4+
}
5+
6+
def resolveReactNativeDirectory() {
7+
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
8+
if (reactNativeLocation != null) {
9+
return file(reactNativeLocation)
10+
}
11+
12+
// monorepo workaround
13+
// react-native can be hoisted or in project's own node_modules
14+
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
15+
if (reactNativeFromProjectNodeModules.exists()) {
16+
return reactNativeFromProjectNodeModules
17+
}
18+
19+
def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
20+
if (reactNativeFromNodeModulesWithReanimated.exists()) {
21+
return reactNativeFromNodeModulesWithReanimated
22+
}
23+
24+
throw new GradleException(
25+
"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."
26+
)
27+
}
28+
29+
def reactNativeRootDir = resolveReactNativeDirectory()
30+
31+
def reactProperties = new Properties()
32+
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
33+
34+
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
35+
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
36+
137
buildscript {
2-
ext.safeExtGet = {prop, fallback ->
38+
ext.safeExtGet = { prop, fallback ->
339
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
440
}
41+
ext.IS_ROOT = project == rootProject
542

643
// The Android Gradle plugin is only required when opening the android folder stand-alone.
744
// This avoids unnecessary downloads and potential conflicts when the library is included as a
845
// module dependency in an application project.
9-
if (project == rootProject) {
46+
47+
if (IS_ROOT) {
1048
repositories {
1149
google()
1250
mavenCentral()
1351
}
14-
1552
dependencies {
16-
//noinspection GradleDependency
17-
classpath("com.android.tools.build:gradle:4.2.2")
53+
classpath "com.android.tools.build:gradle:7.3.1"
1854
}
1955
}
2056
}
2157

2258
apply plugin: 'com.android.library'
2359

2460
android {
25-
compileSdkVersion safeExtGet('compileSdkVersion', 30)
26-
//noinspection GradleDependency
27-
buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')
28-
61+
namespace "com.github.douglasjunior.reactNativeGetLocation"
62+
compileSdkVersion safeExtGet("compileSdkVersion", 33)
2963
defaultConfig {
3064
minSdkVersion safeExtGet('minSdkVersion', 21)
3165
//noinspection OldTargetApi
32-
targetSdkVersion safeExtGet('targetSdkVersion', 30)
66+
targetSdkVersion safeExtGet('targetSdkVersion', 33)
3367
}
3468
lintOptions {
3569
abortOnError false
3670
}
3771
}
3872

3973
repositories {
40-
repositories {
41-
mavenCentral()
42-
mavenLocal()
74+
mavenCentral()
75+
mavenLocal()
76+
if (REACT_NATIVE_MINOR_VERSION < 71) {
4377
maven {
4478
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
45-
url("$rootDir/../node_modules/react-native/android")
79+
url "$reactNativeRootDir/android"
4680
}
4781
maven {
4882
// Android JSC is installed from npm
49-
url("$rootDir/../node_modules/jsc-android/dist")
83+
url "$reactNativeRootDir/../jsc-android/dist"
5084
}
51-
52-
google()
53-
maven { url 'https://www.jitpack.io' }
5485
}
86+
google()
5587
}
5688

5789
dependencies {
58-
//noinspection GradleDynamicVersion
59-
implementation "com.facebook.react:react-native:${safeExtGet('reactnativeVersion', '+')}"
90+
if (REACT_NATIVE_MINOR_VERSION >= 71) {
91+
implementation "com.facebook.react:react-android${IS_ROOT ? ':+' : ''}"
92+
// version substituted by RNGP
93+
} else {
94+
// noinspection GradleDynamicVersion
95+
implementation "com.facebook.react:react-native:+" // From node_modules
96+
}
6097
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.github.douglasjunior.reactNativeGetLocation" >
1+
<manifest>
32

4-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
53
</manifest>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-get-location",
33
"displayName": "React-Native Get Location",
4-
"version": "4.0.1",
4+
"version": "5.0.0",
55
"description": "⚛ Simple to use React Native library to get device location for Android and iOS.",
66
"main": "src",
77
"license": "MIT",

0 commit comments

Comments
 (0)