alwx / react-native-http-bridge

HTTP server for React Native
118 stars 78 forks source link

Moving to newer versions of react native #32

Open Kemsa opened 1 year ago

Kemsa commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-http-bridge@0.6.1 for the project I'm working on.

I work with the latest react native (0.70) with a recent gradle version, here are the steps I did to make it compatible. (essentially changed compile to implementation and migrate android lib to androidx lib).

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-http-bridge/android/build.gradle b/node_modules/react-native-http-bridge/android/build.gradle
index 9417a5f..21a7664 100644
--- a/node_modules/react-native-http-bridge/android/build.gradle
+++ b/node_modules/react-native-http-bridge/android/build.gradle
@@ -34,7 +34,7 @@ android {
 }

 dependencies {
-    compile 'com.facebook.react:react-native:+'
-    compile 'com.google.android.gms:play-services-gcm:+'
-    compile 'org.nanohttpd:nanohttpd:2.3.1'
+    implementation  'com.facebook.react:react-native:+'
+    implementation  'com.google.android.gms:play-services-gcm:+'
+    implementation  'org.nanohttpd:nanohttpd:2.3.1'
 }
diff --git a/node_modules/react-native-http-bridge/android/src/main/java/me/alwx/HttpServer/Server.java b/node_modules/react-native-http-bridge/android/src/main/java/me/alwx/HttpServer/Server.java
index decf9f2..24f1500 100644
--- a/node_modules/react-native-http-bridge/android/src/main/java/me/alwx/HttpServer/Server.java
+++ b/node_modules/react-native-http-bridge/android/src/main/java/me/alwx/HttpServer/Server.java
@@ -14,7 +14,7 @@ import java.util.Set;
 import java.util.HashMap;
 import java.util.Random;

-import android.support.annotation.Nullable;
+import androidx.annotation.Nullable;
 import android.util.Log;

 public class Server extends NanoHTTPD {
@@ -44,8 +44,7 @@ public class Server extends NanoHTTPD {
             request = fillRequestMap(session, requestId);
         } catch (Exception e) {
             return newFixedLengthResponse(
-                    Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, e.getMessage()
-            );
+                    Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, e.getMessage());
         }

         this.sendEvent(reactContext, SERVER_EVENT_ID, request);
@@ -76,7 +75,7 @@ public class Server extends NanoHTTPD {
         Map<String, String> files = new HashMap<>();
         session.parseBody(files);
         if (files.size() > 0) {
-          request.putString("postData", files.get("postData"));
+            request.putString("postData", files.get("postData"));
         }

         return request;

This issue body was partially generated by patch-package.

ScreamZ commented 1 year ago

Thanks

Alwinator commented 1 year ago

@Kemsa @ScreamZ Feel free to checkout: react-native-http-bridge-refurbished.

It is meant to be a maintained version of this repo.