我正在使用android studio中的Parse SDK。每件事情都工作得很好,直到我在我的项目中启用multidex,因为在添加地图库后,我的项目超出了64K方法的限制。我得到以下错误,当我运行我的应用程序:解析sdk“java.lang.NoSuchMethodError”。 Okhttp库之间的冲突
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:[email protected]') {
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);
}
}
我觉得问题在于MyApplication类中的Parse.initialize
语句。因为当我调试我的应用程序,并在该语句上设置一个断点(每一件事情在该语句之前看起来都很好),当执行initialize语句时,我的应用程序崩溃。我搜索了很多,我没有找到任何解决这个问题。请帮助...
编辑: 确定后进一步研究,并与gradle这个依赖玩弄我发现这个错误不是因为multiDexEnabled的,而这是因为通过分析和使用okhttp库之间的冲突google-地图服务。 Google-maps-services使用OkHttp:2.0.0,我认为Parse是使用OkHttp:2.4.0。我认为OkHttp:2.0.0没有名称为setFollowRedirects
的这种方法,它覆盖了OkHttp:2.4.0,这就是为什么我的应用程序崩溃。如果我删除谷歌地图服务编译声明我的应用程序工作正常。
注意:如果我做了compile com.squareup.okhttp:okhttp:2.4.0
错误不再出现,但我的解析函数(即登录和注册回调)给出这个错误com.parse.ParseException:java.lang.IllegalArgumentException: value == null
,他们不再工作。
您是否曾尝试在'super.onCreate();'之前添加'MultiDex.install(this);''? – diogojme
确实很重要吗?因为我已经将它添加到了'attachBaseContext'方法中,并且我已经使用log语句进行了检查,它在'onCreate()'之前被调用。 –
我试过了,还是一样的错误。 –