解析sdk“java.lang.NoSuchMethodError”。(Parse sdk “java.lang.NoSuchMethodError”. Conflict between Okhttp

编程入门 行业动态 更新时间:2024-10-22 21:34:09
解析sdk“java.lang.NoSuchMethodError”。(Parse sdk “java.lang.NoSuchMethodError”. Conflict between Okhttp Libraries)

我在android studio中使用Parse SDK。 每件事情都很好,直到我在我的项目中启用了multidex,因为在添加了地图库后,我的项目超出了64K方法的限制。 运行我的应用程序时出现以下错误:

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)

这就是我的gradle文件的样子:

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' }

这是我的清单文件:

<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>

这是我的应用程序类:

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); } }

我认为问题Parse.initialize在MyApplication类的Parse.initialize语句中。 因为当我调试我的应用程序并在该语句上设置断点(在该语句之前每件事情似乎都很好)当执行initialize语句时我的应用程序崩溃了。 我搜索了很多,我没有找到任何解决这个问题的方法。 请帮忙...

编辑:好的经过进一步研究和玩gradle依赖我发现这个错误不是因为multiDexEnabled而是因为Parse和google-maps-services使用的okhttp库之间的冲突。 谷歌地图服务使用OkHttp:2.0.0,我猜,Parse使用的是OkHttp:2.4.0。 我认为OkHttp:2.0.0没有这样的名称setFollowRedirects方法,它覆盖OkHttp:2.4.0这就是为什么我的应用程序崩溃了。 如果我删除google-maps-services编译语句,我的应用程序工作正常。

注意:如果我compile com.squareup.okhttp:okhttp:2.4.0错误不再出现,但我的解析函数(即Login和Signup回调)给出了这个错误com.parse.ParseException:java.lang.IllegalArgumentException: value == null ,它们不再有效。

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.

最满意答案

初始化Parse时将空字符串传递给客户端密钥。

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

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());

更多推荐

本文发布于:2023-07-05 07:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lang   NoSuchMethodError   sdk   java   Okhttp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!