Qandeel Abbassi
Qandeel Abbassi

Reputation: 999

Parse sdk "java.lang.NoSuchMethodError". Conflict between Okhttp Libraries

I am working with Parse SDK in android studio. Every thing was working fine untill i enabled multidex in my project because after adding the maps libraries my project exceeded 64K methods limit. I get following error when i run my app:

java.lang.NoSuchMethodError: com.squareup.okhttp.OkHttpClient.setFollowRedirects
at com.parse.ParseOkHttpClient.<init>(ParseOkHttpClient.java:58)
at com.parse.ParseHttpClient.createClient(ParseHttpClient.java:45)
at com.parse.ParsePlugins$Android.newHttpClient(ParsePlugins.java:175)
at com.parse.ParsePlugins.restClient(ParsePlugins.java:91)
at com.parse.Parse.getEventuallyQueue(Parse.java:615)
at com.parse.Parse.access$800(Parse.java:42)
at com.parse.Parse$1.call(Parse.java:410)
at com.parse.Parse$1.call(Parse.java:407)
at bolts.Task$4.run(Task.java:357)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)

This is how my gradle file looks like:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

dexOptions {
    javaMaxHeapSize "4g"
}

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.github.clans:fab:1.6.2'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.maps:google-maps-services:0.1.9'
compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile('com.github.afollestad.material-dialogs:core:0.8.5.1@aar') {
    transitive = true
}
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.13.0'
}

and this is my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rowburst.traverous.traverous">

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:name="com.example.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/MAPS_API_KEY" />

    <activity
        android:name="com.example.LaunchingActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoDisplay">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.LoginActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" />

    <activity android:name="com.example.MainActivity"></activity>
</application>

And this is my application class:

public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Parse.initialize(new Parse.Configuration.Builder(this)
            .applicationId(Const.APP_ID)
            .server(Const.SERVER_URL)
            .build());
}

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
}

I think the problem is in Parse.initialize statement in MyApplication class. Because when i debug my app and set a breakpoint on that statement (every thing seems fine before that statement) when the initialize statement is executed my app crashes. I have searched alot and i didnt find any solution to this problem. Please help...

EDIT: Ok after further research and playing around with gradle dependencies i found out that this error is not because of multiDexEnabled rather it is because of conflict between okhttp library used by Parse and google-maps-services. Google-maps-services use OkHttp:2.0.0 where as Parse, i guess, uses OkHttp:2.4.0. I think OkHttp:2.0.0 has no such method of name setFollowRedirects and it is overriding OkHttp:2.4.0 thats why my app crashes. If i remove the google-maps-services compile statement my app works fine.

Note: If i do compile com.squareup.okhttp:okhttp:2.4.0 the error no more comes up but my parse functions (i.e. Login and Signup callback) give this error com.parse.ParseException:java.lang.IllegalArgumentException: value == null , they no longer work.

Upvotes: 0

Views: 241

Answers (2)

Arade
Arade

Reputation: 577

When you Initialize Parse pass empty string to client key.

Parse.initialize(new Parse.Configuration.Builder(this)
        .applicationId(Const.APP_ID)
        .server(Const.SERVER_URL)
        .clientKey("")
        .build());

Upvotes: 1

Swapnil
Swapnil

Reputation: 41

Try adding

compile 'com.squareup.okhttp:okhttp:2.4.0'

to your build.gradle file.

Upvotes: 0

Related Questions