I encounter this problem only on lollipop version. I can run the app easily on versions above lollipop. The error shows up when I run the app in my application file:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/picasso/Picasso;
at aroundwise.nepi.MyApplication.onCreate(MyApplication.java:44)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5122)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1510)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.picasso.Picasso" on path: DexPathList[[zip file "/data/app/aroundwise.nepi-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at aroundwise.nepi.MyApplication.onCreate(MyApplication.java:44)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5122)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1510)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Suppressed: java.lang.ClassNotFoundException: com.squareup.picasso.Picasso
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Here is my Application file:
public class MyApplication extends Application {
private static ComplexPreferences sharedPreferences;
public static MyApplication instance;
AroundWiseSDK aroundWiseSDK;
private Picasso picasso;
@Override
public void onCreate() {
super.onCreate();
sharedPreferences = ComplexPreferences.getComplexPreferences(getBaseContext(), Constants.PREFFERENCES, MODE_PRIVATE);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/ProximaNova-Regular.otf")
.setFontAttrId(R.attr.fontPath)
.build());
Callbacks c = new Callbacks();
instance = this;
HashMap<String, String> clientData = new HashMap<>();
clientData.put("key_placeholder", "value_placeholder");
picasso = Picasso.with(getApplicationContext());
aroundWiseSDK = new AroundWiseSDK(getBaseContext(), this, c, false, "https://promenada.aroundwise.com", clientData);
aroundWiseSDK.setMainActivity(DiscoverActivity.class);
aroundWiseSDK.bindBackgroundService();
}
public Picasso getPicasso() {
return picasso;
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// MultiDex.install(base);
}
public static ComplexPreferences getSharedPreferences(Context context) {
if (sharedPreferences == null) {
sharedPreferences = ComplexPreferences.getComplexPreferences(context, Constants.PREFFERENCES, MODE_PRIVATE);
}
return sharedPreferences;
}
}
This is my gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'io.fabric'
apply plugin: 'com.getkeepsafe.dexcount'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 24
buildToolsVersion "25.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/BCKEY.DSA'
exclude 'AUTHORS'
exclude 'META-INF/services/javax.annotation.processing.Processor' // butterknife
exclude 'META-INF/BCKEY.SF'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
defaultConfig {
applicationId "aroundwise.nepi"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.1.8"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//multiDexKeepFile file('multidex-config.txt')
// multiDexKeepProguard file('multidex-config.pro')
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// multiDexKeepFile file('multidex-config.txt')
// multiDexKeepProguard file('multidex-config.pro')
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def apk = output.outputFile;
def newName;
if (variant.buildType.name == "release") {
newName = apk.name.replace("app-debug", "-release-Nepi" + "-v" + defaultConfig.versionName + ".apk");
} else {
newName = apk.name.replace("app-debug.apk", "-Nepi" + "-v" + defaultConfig.versionName + ".apk");
}
output.outputFile = new File(apk.parentFile, newName);
if (variant.buildType.zipAlignEnabled) {
output.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
}
logger.info('INFO: Set outputFile to ' + output.outputFile + " for [" + variant.name + "]");
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
//BUTTERKNIFE
apt 'com.jakewharton:butterknife-compiler:8.2.1'
//MVP & ParcelablePlease & Adapter
apt 'com.hannesdorfmann.annotatedadapter:processor:1.1.1'
apt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
//AROUNDWISE SDK's
compile(name: 'aroundwisesdk', ext: 'aar')
compile(name: 'aroundwisecards', ext: 'aar')
//GOOGLE
//FACEBOOK
//ANDROID
//RETROFIT&RxANDROID
//UTIL
//compile 'com.lorentzos.swipecards:library:1.0.9@aar'
//BeaconSDk needed
compile 'me.relex:circleindicator:1.1.5@aar'
compile 'com.hannesdorfmann.annotatedadapter:annotation:1.1.1'
compile 'com.hannesdorfmann.annotatedadapter:support-recyclerview:1.1.1'
compile 'com.hannesdorfmann.mosby:mvp:2.0.1'
compile 'com.hannesdorfmann.mosby:viewstate:2.0.1'
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
compile 'com.hannesdorfmann.mosby:retrofit:1.1.0'
compile 'com.google.gms:google-services:2.1.2'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.maps.android:android-maps-utils:0.4.4'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-annotations:24.2.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.jakewharton:butterknife:8.2.1'
compile 'com.github.jinatonic.confetti:confetti:1.0.0'
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.3-SNAPSHOT'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.3.0'
compile 'com.github.lzyzsd:circleprogress:1.1.0@aar'
compile 'com.daprlabs.aaron:cardstack:0.3.1-beta0'
compile 'org.altbeacon:android-beacon-library:2.+@aar'
compile 'com.squareup.okhttp:okhttp:2.3.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
apt 'com.google.dagger:dagger-compiler:2.0.2'
compile 'com.google.dagger:dagger:2.0.2'
}
repositories {
flatDir {
dirs 'libs'
}
apply plugin: 'com.google.gms.google-services'
}
And this is my manifest. I am using multidex but I do not need to extend MultiDexApplicaiton since I am using minSDK 21 ( at least that is what I understood from the documentation)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="aroundwise.nepi">
<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" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="aroundwise.nepi.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="aroundwise.nepi.permission.C2D_MESSAGE" />
<uses-feature android:name="android.hardware.camera2" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activities.mainActivity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="5ef18a8d1003a5ed11bbf50f188bc758133cba38" />
<activity
android:name=".activities.onBoardActivity.OnBoardActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".activities.discoverActivity.DiscoverActivity"
android:screenOrientation="portrait" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_api_key_me" />
<activity
android:name=".activities.cameraActivity.CameraActivity"
android:screenOrientation="portrait" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider840752006058179"
android:exported="true" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
tools:replace="android:theme" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="aroundwise.nepi.gcm" />
</intent-filter>
</receiver>
<service
android:name=".gcm.PushNotificationListener"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".gcm.GcmIdListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name=".gcm.GCMRegistationIntentService"
android:exported="false"></service>
</application>
</manifest>
I ran out of ideas, so please any help or tips are welcome.
Thank you!
If
publishNonDefault true
was defined in libs build.gradle, please remove it or make it false. Please try. I have resolved this issue by removingpublishNonDefault true
in build.gradle of lib which occurredNoClassDefFoundError
.If not working, please add
dexOptions { preDexLibraries false }
.If you are using fabric then please remove dependency of picasso from gradle, it will work fine.Try it...
You need to install
Multidex
to runpicasso
on lower devicespublic class MyApplication extends Application {
add this in your
manifest
underapplication
tag