Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: OkHttpClientFactory error #19054

Closed
denisk20 opened this issue Apr 27, 2018 · 3 comments
Closed

Android: OkHttpClientFactory error #19054

denisk20 opened this issue Apr 27, 2018 · 3 comments
Labels
🌐Networking Related to a networking API. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@denisk20
Copy link

With this pull request merged it should now be possible to customize OkHttp client for Android. However following the steps in the description lead to an error:

java.lang.ClassCastException: okhttp3.CookieJar$1 cannot be cast to com.facebook.react.modules.network.CookieJarContainer
    at com.facebook.react.modules.network.NetworkingModule.<init>(NetworkingModule.java:141)
    at com.facebook.react.modules.network.NetworkingModule.<init>(NetworkingModule.java:164)
    at com.facebook.react.shell.MainReactPackage$18.get(MainReactPackage.java:245)
    at com.facebook.react.shell.MainReactPackage$18.get(MainReactPackage.java:242)
    at com.facebook.react.LazyReactPackage.createNativeModules(LazyReactPackage.java:79)
    at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:106)
    at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1172)
    at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1142)
    at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1080)
    at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113)
    at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:911)
    at java.lang.Thread.run(Thread.java:764)

Inspecting dependencies with ./gradlew app:dependencies shows that I have OkHttp version 3.6.0.

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 6.11.3
Yarn: 1.6.0
npm: 5.3.0
Watchman: 4.4.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.1 AI-173.4697961

Packages: (wanted => installed)
react: 16.3.0-alpha.1 => 16.3.0-alpha.1
react-native: 0.55.3 => 0.55.3

Steps to Reproduce

Create a class:

public class MyOkHttpClientFactory implements OkHttpClientFactory {
    public OkHttpClient createNewNetworkModuleClient() {
        return new OkHttpClient.Builder().build();
    }
}

In your ReactApplication.onCreate() add the following

@Override
public void onCreate() {
    super.onCreate();
    OkHttpClientProvider.setOkHttpClientFactory(new MyOkHttpClientFactory());
}

Build and run the app

Expected Behavior

The app works

Actual Behavior

The app crashes with the above stacktrace.

@react-native-bot react-native-bot added 🌐Networking Related to a networking API. Platform: Android Android applications. labels Apr 27, 2018
@odemolliens
Copy link

You should try this:

public class OKHttpOv implements OkHttpClientFactory {

   @Override
   public OkHttpClient createNewNetworkModuleClient() {
       return new OkHttpClient.Builder().cookieJar(new ReactCookieJarContainer()).build();
    }
}

Using .cookieJar(new ReactCookieJarContainer()) fix the problem

@stale
Copy link

stale bot commented Aug 21, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 21, 2018
@stale
Copy link

stale bot commented Sep 6, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Sep 6, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🌐Networking Related to a networking API. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants