[ 
https://issues.apache.org/jira/browse/CB-7925?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14194171#comment-14194171
 ] 

Rajat Paharia edited comment on CB-7925 at 11/3/14 1:55 AM:
------------------------------------------------------------

The following fix (based on the solution outlined in the links above) seems to 
work for me. I have no idea what I'm doing, so can't comment as to whether this 
is a good solution or not though ;) 

To file: 
*platforms/android/CordovaLib/src/org/apache/cordova/CordovaResourceApi.java*

Add to top variable declarations: 
{code:title=CordovaResourceApi.java - variable declarations |borderStyle=solid}
    private static boolean initializedOkHttpClient = false;
{code}

Add to function *createHttpConnection*:
{code:title=CordovaResourceApi.java - createHttpConnection |borderStyle=solid}
    public HttpURLConnection createHttpConnection(Uri uri) throws IOException {
        if (!initializedOkHttpClient) {
            initializedOkHttpClient = true;
            URL.setURLStreamHandlerFactory(httpClient);
        }
        assertBackgroundThread();
        return httpClient.open(new URL(uri.toString()));
    }
{code}

The static variable initializedOkHttpClient ensures that we only call 
URL.setURLStreamHandlerFactory(httpClient); once. Without that, the app no 
longer crashes, but I get weird behavior when trying to upload files. 


was (Author: rajatrocks):
The following fix (based on the solution outlined in the links above) seems to 
work for me. I have no idea what I'm doing, so can't comment as to whether this 
is a good solution or not though ;) 

To file: 
*platforms/android/CordovaLib/src/org/apache/cordova/CordovaResourceApi.java*

Add to top variable declarations: 
{code:title=CordovaResourceApi.java - variable declarations |borderStyle=solid}
    private static boolean initializedOkHttpClient = false;
{code}

Add to function *createHttpConnection*:
{code:title=CordovaResourceApi.java - createHttpConnection |borderStyle=solid}
    public HttpURLConnection createHttpConnection(Uri uri) throws IOException {
        if (!initializedOkHttpClient) {
            initializedOkHttpClient = true;
            URL.setURLStreamHandlerFactory(httpClient);
        }
        assertBackgroundThread();
        return httpClient.open(new URL(uri.toString()));
    }
{code}



> Android app crashes when use File Transfer & another plugin that uses SSL 
> (related to OkHttp)
> ---------------------------------------------------------------------------------------------
>
>                 Key: CB-7925
>                 URL: https://issues.apache.org/jira/browse/CB-7925
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin File Transfer
>    Affects Versions: 4.0.0
>         Environment: Android 4.4.4
>            Reporter: Rajat Paharia
>
> In my app if I do a file upload using the File Transfer plugin and then try 
> to make a call to the Facebook plugin: 
> https://github.com/Wizcorp/phonegap-facebook-plugin - my app immediately 
> crashes. I believe this is caused by this issue with the version of the 
> OkHttp library currently being used: 
> http://stackoverflow.com/questions/21872818/okhttp-and-facebook-crashed
> https://github.com/square/okhttp/issues/184
> It would be great if the described workaround could be implemented in Cordova 
> while we wait for https://issues.apache.org/jira/browse/CB-6630 and an 
> upgrade to OkHttp 2.0



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to