andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

Jcenter still coming in, old gradle coming in during app build #504

Open mikehardy opened 2 years ago

mikehardy commented 2 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch react-native-sqlite-storage@6.0.1 for the project I'm working on.

jcenter proclaimed they would stay up in readonly forever, but their service has become incredibly flaky.

I was no longer able to build my android app because jcenter was down this morning and this module brought in an old gradle and jcenter even when it was not necessary

I replaced the gradle plugin dependency with a block that works the way I do it in the react-native-device-info module I maintain as well as all the other modules - it only pulls in gradle and the module dependencies when it's necessary, which is to say: it does not pull them in during app builds

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-sqlite-storage/platforms/android-native/build.gradle b/node_modules/react-native-sqlite-storage/platforms/android-native/build.gradle
index 94a8675..53e90cc 100644
--- a/node_modules/react-native-sqlite-storage/platforms/android-native/build.gradle
+++ b/node_modules/react-native-sqlite-storage/platforms/android-native/build.gradle
@@ -1,11 +1,17 @@
 buildscript {
-    repositories {
-        google()
-        jcenter()
-    }
+    // 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.
+    if (project == rootProject) {
+        repositories {
+            mavenCentral()
+            google()
+        }
+        def buildGradleVersion = ext.has('buildGradlePluginVersion') ? ext.get('buildGradlePluginVersion') : '7.0.3'

-    dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.4'
+        dependencies {
+            classpath "com.android.tools.build:gradle:$buildGradleVersion"
+        }
     }
 }

@@ -16,12 +22,11 @@ def safeExtGet(prop, fallback) {
 }

 android {
-    compileSdkVersion safeExtGet('compileSdkVersion', 23)
-    buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')
+    compileSdkVersion safeExtGet('compileSdkVersion', 30)

     defaultConfig {
         minSdkVersion safeExtGet('minSdkVersion', 16)
-        targetSdkVersion safeExtGet('targetSdkVersion', 22)
+        targetSdkVersion safeExtGet('targetSdkVersion', 28)
         versionCode 1
         versionName "1.0"
     }
diff --git a/node_modules/react-native-sqlite-storage/platforms/android/build.gradle b/node_modules/react-native-sqlite-storage/platforms/android/build.gradle
index ff79b10..a0c6468 100644
--- a/node_modules/react-native-sqlite-storage/platforms/android/build.gradle
+++ b/node_modules/react-native-sqlite-storage/platforms/android/build.gradle
@@ -1,11 +1,17 @@
 buildscript {
-    repositories {
-        google()
-        jcenter()
-    }
+    // 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.
+    if (project == rootProject) {
+        repositories {
+            mavenCentral()
+            google()
+        }
+        def buildGradleVersion = ext.has('buildGradlePluginVersion') ? ext.get('buildGradlePluginVersion') : '7.0.3'

-    dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.4'
+        dependencies {
+            classpath "com.android.tools.build:gradle:$buildGradleVersion"
+        }
     }
 }

@@ -16,12 +22,11 @@ def safeExtGet(prop, fallback) {
 }

 android {
-    compileSdkVersion safeExtGet('compileSdkVersion', 23)
-    buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3')
+    compileSdkVersion safeExtGet('compileSdkVersion', 30)

     defaultConfig {
         minSdkVersion safeExtGet('minSdkVersion', 16)
-        targetSdkVersion safeExtGet('targetSdkVersion', 22)
+        targetSdkVersion safeExtGet('targetSdkVersion', 28)
         versionCode 1
         versionName "1.0"
     }

This issue body was partially generated by patch-package.

fogg4444 commented 1 year ago

@mikehardy I'm having the same problem. Your diff looks good. Can it be merged?

mikehardy commented 1 year ago

@fogg4444 no idea - I'm actually not using this package anymore but I don't see why the PR wouldn't still be valid. Feel free to ping on it + ask the maintainer, until then you've always got patch-package...

fogg4444 commented 1 year ago

@fogg4444 no idea - I'm actually not using this package anymore but I don't see why the PR wouldn't still be valid. Feel free to ping on it + ask the maintainer, until then you've always got patch-package...

I copied your patch file approach for now. I'll ping the maintainer. Thanks!