I'm trying to use Fresco but it crashes as soon as I try to initialize it. I use Android Studio and I've been following the instructions located here.
In my application class I initialize Fresco just like in the tutorial in the onCreate
method like so:
Fresco.initialize(this);
This is the stacktrace of the crash:
09-25 18:31:05.896 7789-7789/com.myproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.facebook.imagepipeline.producers.HttpUrlConnectionNetworkFetcher
at com.facebook.imagepipeline.core.ImagePipelineConfig.<init>(ImagePipelineConfig.java:126)
at com.facebook.imagepipeline.core.ImagePipelineConfig.<init>(ImagePipelineConfig.java:61)
at com.facebook.imagepipeline.core.ImagePipelineConfig$Builder.build(ImagePipelineConfig.java:378)
at com.facebook.imagepipeline.core.ImagePipelineFactory.initialize(ImagePipelineFactory.java:77)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:32)
at com.myproject.MyProjectApplication.onCreate(MyProjectApplication.java:196)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:999)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4151)
at android.app.ActivityThread.access$1300(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
This is my build.gradle file
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
applicationId "com.myproject"
minSdkVersion 15
targetSdkVersion 22
versionCode 22
versionName "0.0.22"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
jumboMode = true
}
}
repositories {
flatDir {
dirs 'libs'
}
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile ('com.facebook.fresco:fresco:0.7.0+')
compile 'com.android.support:multidex:1.0.0'
compile(name:'httpmime-4.3.5', ext:'jar')
compile(name:'httpcore-4.3.2', ext:'jar')
...
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
}
configurations {
all*.exclude group: 'com.nineoldandroids', module: 'library'
}
update
I'm experiencing this on an emulator running Android version 4.1.2 and an actual phone running 4.4.4. On Lollipop devices everything works. Fresco supports Gingerbread and above.
You might have exceeded 65K method limit. If you haven't added 'multiDexEnabled true' in defaultConfig do so. Also to support MultiDex on pre lollipop devices you have to add MultiDex compat library in your dependencies. Your build.gradle file will look like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "in.justride"
minSdkVersion 15
targetSdkVersion 17
versionCode 30
versionName "3.0.0"
**multiDexEnabled true**
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
**splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
universalApk false
}
}**
}
}
repositories{
maven {
url "http://repository.codehaus.org/org/codehaus"
}
maven {
url "https://jitpack.io"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'org.parceler:parceler:0.2.13'
compile 'com.squareup.retrofit:converter-jackson:2.0.0-beta1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.balysv:material-ripple:1.0.2'
**compile 'com.facebook.fresco:fresco:0.7.0+'**
compile 'com.android.support:recyclerview-v7:22.2.+'
compile 'com.android.support:cardview-v7:22.2.+'
**compile 'com.android.support:multidex:1.0.0'**
}
Also, in your project Application class override attachBaseContext() method like this:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Please tell if this is helpful. Split is used as Fresco is a native library so there is a different set of binaries for each CPU architecture and a separate .apk is built for each CPU containing only the specific set of libraries for that CPU architecture.
Update
Multidex support is by default included in ART (lollipop+). Prior to lollipop, multidex support is provided through support library. Hence, we need to include it in dependencies. (if min SDK < 21)