java.lang.NoClassDefFoundError: retrofit2.Retrofit$Builder Fabric 初始化
Posted
技术标签:
【中文标题】java.lang.NoClassDefFoundError: retrofit2.Retrofit$Builder Fabric 初始化【英文标题】:java.lang.NoClassDefFoundError: retrofit2.Retrofit$Builder Fabric initialization 【发布时间】:2016-09-08 09:19:28 【问题描述】:我正在为我的应用程序使用 Fabric API 和 twitter 工具包,但我总是只会在某些构建版本中收到错误消息。 就我的 API 19 而言,我收到以下错误:
Fabric.with(this, new Twitter(authConfig));
这是错误
java.lang.NoClassDefFoundError: retrofit2.Retrofit$Builder
at com.twitter.sdk.android.core.internal.oauth.OAuthService.<init>(OAuthService.java:69)
at com.twitter.sdk.android.core.internal.oauth.OAuth2Service.<init>(OAuth2Service.java:59)
at com.twitter.sdk.android.core.TwitterCore.createGuestSessionProvider(TwitterCore.java:223)
at com.twitter.sdk.android.core.TwitterCore.getGuestSessionProvider(TwitterCore.java:216)
at com.twitter.sdk.android.tweetui.TweetUi.onPreExecute(TweetUi.java:77)
at io.fabric.sdk.android.InitializationTask.onPreExecute(InitializationTask.java:44)
at io.fabric.sdk.android.services.concurrency.AsyncTask.executeOnExecutor(AsyncTask.java:611)
at io.fabric.sdk.android.services.concurrency.PriorityAsyncTask.executeOnExecutor(PriorityAsyncTask.java:43)
at io.fabric.sdk.android.Kit.initialize(Kit.java:69)
at io.fabric.sdk.android.Fabric.initializeKits(Fabric.java:439)
at io.fabric.sdk.android.Fabric.init(Fabric.java:383)
at io.fabric.sdk.android.Fabric.setFabric(Fabric.java:341)
at io.fabric.sdk.android.Fabric.with(Fabric.java:312)
at com.lmst.runnincity.Model.SkobblerAddOn.onCreate(SkobblerAddOn.java:39)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4446)
at android.app.ActivityThread.access$1500(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
at dalvik.system.NativeStart.main(Native Method)
这是我的 build.gradle
buildscript
repositories
maven url 'https://maven.fabric.io/public'
dependencies
classpath 'io.fabric.tools:gradle:1.+'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig
applicationId "com.**********"
minSdkVersion 15
targetSdkVersion 24
versionCode 2
versionName "1.1.1"
multiDexEnabled true
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
sourceSets main assets.srcDirs = ['src/main/assets', 'src/main/assets/']
repositories
mavenCentral()
maven url 'https://maven.fabric.io/public'
dependencies
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.7'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-database:9.2.0'
compile 'com.google.firebase:firebase-storage:9.2.0'
compile 'com.google.firebase:firebase-auth:9.2.0'
compile 'com.wx.wheelview:wheelview:1.3.3'
compile project(':sdktools')
compile 'com.google.android.gms:play-services-appindexing:9.2.0'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile('com.twitter.sdk.android:twitter:2.0.0@aar')
compile('com.twitter.sdk.android:tweet-composer:2.0.0@aar')
transitive = true;
transitive = true;
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
【参考方案1】:尝试包含对 multidex https://developer.android.com/studio/build/multidex.html 的支持 我的依赖和 Crashlytics 一样简单:
dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar')
transitive = true;
compile('com.twitter.sdk.android:twitter:2.3.1@aar')
transitive = true;
...
compile 'com.android.support:multidex:1.0.1'
【讨论】:
以上是关于java.lang.NoClassDefFoundError: retrofit2.Retrofit$Builder Fabric 初始化的主要内容,如果未能解决你的问题,请参考以下文章