Skip to content

Commit

Permalink
Remove replaceOkHttpClient method
Browse files Browse the repository at this point in the history
replaceOkHttpClient is a noop since
0a71f48.

Leaving this code in place is dangerous as it can lead to subtle bugs
where people upgrading react-native assume they're continuing to replace
the okhttp client when in fact this is not the case.
  • Loading branch information
cdlewis committed Nov 24, 2017
1 parent 766f020 commit 81019e6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public static OkHttpClient getOkHttpClient() {
}
return sClient;
}

// okhttp3 OkHttpClient is immutable
// This allows app to init an OkHttpClient with custom settings.
public static void replaceOkHttpClient(OkHttpClient client) {
sClient = client;
}

public static OkHttpClient createClient() {
// No timeouts by default
Expand Down
70 changes: 0 additions & 70 deletions docs/Debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,76 +163,6 @@ Alternatively, select "Dev Settings" from the Developer Menu, then update the "D

> If you run into any issues, it may be possible that one of your Chrome extensions is interacting in unexpected ways with the debugger. Try disabling all of your extensions and re-enabling them one-by-one until you find the problematic extension.
### Debugging with [Stetho](http://facebook.github.io/stetho/) on Android

Follow this guide to enable Stetho for Debug mode:

1. In `android/app/build.gradle`, add these lines in the `dependencies` section:

```gradle
debugCompile 'com.facebook.stetho:stetho:1.5.0'
debugCompile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
```

> The above will configure Stetho v1.5.0. You can check at http://facebook.github.io/stetho/ if a newer version is available.
2. Create the following Java classes to wrap the Stetho call, one for release and one for debug:

```java
// android/app/src/release/java/com/{yourAppName}/StethoWrapper.java

public class StethoWrapper {

public static void initialize(Context context) {
// NO_OP
}

public static void addInterceptor() {
// NO_OP
}
}
```

```java
// android/app/src/debug/java/com/{yourAppName}/StethoWrapper.java

public class StethoWrapper {
public static void initialize(Context context) {
Stetho.initializeWithDefaults(context);
}

public static void addInterceptor() {
OkHttpClient client = OkHttpClientProvider.getOkHttpClient()
.newBuilder()
.addNetworkInterceptor(new StethoInterceptor())
.build();

OkHttpClientProvider.replaceOkHttpClient(client);
}
}
```

3. Open `android/app/src/main/java/com/{yourAppName}/MainApplication.java` and replace the original `onCreate` function:

```java
public void onCreate() {
super.onCreate();

if (BuildConfig.DEBUG) {
StethoWrapper.initialize(this);
StethoWrapper.addInterceptor();
}

SoLoader.init(this, /* native exopackage */ false);
}
```

4. Open the project in Android Studio and resolve any dependency issues. The IDE should guide you through this steps after hovering your pointer over the red lines.

5. Run `react-native run-android`.

6. In a new Chrome tab, open: `chrome://inspect`, then click on the 'Inspect device' item next to "Powered by Stetho".

## Debugging native code

When working with native code, such as when writing native modules, you can launch the app from Android Studio or Xcode and take advantage of the native debugging features (setting up breakpoints, etc.) as you would in case of building a standard native app.

0 comments on commit 81019e6

Please sign in to comment.