NoClassDefFoundError When Using Dagger 2 After Switching to Android Studio 2.0 -
before upgrading android studio 2.0 use dagger 2 no problem. getting noclassdeffounderror
has shut me down more day , i'm reaching out help.
it seems though gradle cannot appmodule
class though pretty clear in project. have included set multidexenabled true
though project few files.
everything can find online says can click libraries imported. android studio has no such luxury.
any appreciated , have undying loyalty.
04-21 17:26:54.006 7875-7875/com.androidtitan.spotscoreapp e/androidruntime: fatal exception: main process: com.androidtitan.spotscoreapp, pid: 7875 java.lang.noclassdeffounderror: com.androidtitan.spotscoreapp.main.injection.appmodule_providesapplicationfactory @ com.androidtitan.spotscoreapp.main.injection.daggerappcomponent.initialize(daggerappcomponent.java:31) @ com.androidtitan.spotscoreapp.main.injection.daggerappcomponent.<init>(daggerappcomponent.java:23) @ com.androidtitan.spotscoreapp.main.injection.daggerappcomponent.<init>(daggerappcomponent.java:0) @ com.androidtitan.spotscoreapp.main.injection.daggerappcomponent$builder.build(daggerappcomponent.java:66) @ com.androidtitan.spotscoreapp.app.oncreate(app.java:28) @ com.android.tools.fd.runtime.bootstrapapplication.oncreate(bootstrapapplication.java:326) @ android.app.instrumentation.callapplicationoncreate(instrumentation.java:1020) @ android.app.activitythread.handlebindapplication(activitythread.java:5010) @ android.app.activitythread.access$1600(activitythread.java:172) @ android.app.activitythread$h.handlemessage(activitythread.java:1482) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:5835) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1399) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1194) package com.androidtitan.spotscoreapp.main.injection; import android.app.application; import android.content.context; import javax.inject.singleton; import dagger.module; import dagger.provides;
appmodule
@module public class appmodule { private static application application; public appmodule(application application) { this.application = application; } @provides @singleton application providesapplication() { return application; } @provides @singleton context providesapplicationcontext() { return application.getbasecontext(); } }
appcomponent
package com.androidtitan.spotscoreapp.main.injection; import android.app.application; import android.content.context; import com.androidtitan.spotscoreapp.main.ui.activity.loginactivity; import com.androidtitan.spotscoreapp.main.ui.fragment.loginfragment; import com.androidtitan.spotscoreapp.main.ui.fragment.signupfragment; import javax.inject.singleton; import dagger.component; @singleton @component( modules = { appmodule.class, loginpresentermodule.class } ) public interface appcomponent { application getapplication(); context getapplicationcontext(); void inject(loginfragment activity); }
app extends application
import android.app.application; import android.support.multidex.multidexapplication; import com.androidtitan.spotscoreapp.main.injection.appcomponent; import com.androidtitan.spotscoreapp.main.injection.appmodule; import com.androidtitan.spotscoreapp.main.injection.daggerappcomponent; import com.firebase.client.firebase; import timber.log.timber; public class app extends application { private static appcomponent appcomponent; @override public void oncreate() { super.oncreate(); firebase.setandroidcontext(this); appcomponent = daggerappcomponent.builder() .appmodule(new appmodule(this)) .build(); if (buildconfig.debug) { timber.plant(new timber.debugtree()); } } public static appcomponent getappcomponent(){ return appcomponent; } }
build.gradle(module:app)
apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' android { compilesdkversion 23 buildtoolsversion "24.0.0 rc1" defaultconfig { applicationid "com.androidtitan.spotscoreapp" minsdkversion 16 targetsdkversion 23 versioncode 1 versionname "1.0" multidexenabled true } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } packagingoptions { exclude 'meta-inf/dependencies.txt' exclude 'meta-inf/notice' exclude 'meta-inf/notice.txt' exclude 'meta-inf/license' exclude 'meta-inf/license.txt' } } dependencies { compile filetree(include: ['*.jar'], dir: 'libs') testcompile 'junit:junit:4.12' apt 'com.google.dagger:dagger-compiler:2.0' compile 'com.android.support:multidex:1.0.0' provided 'com.google.dagger:dagger-compiler:2.0' provided 'org.glassfish:javax.annotation:10.0-b28' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.jakewharton.timber:timber:4.1.2' compile 'com.android.support:design:23.3.0' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.firebase:firebase-client-android:2.3.1' }
build.gradle(project:spotscoreapp)
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.0.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' // note: not place application dependencies here; belong // in individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: delete) { delete rootproject.builddir }
androidmanifest
`
<uses-permission android:name="android.permission.internet" /> <application android:name=".app" android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme" > <activity android:name=".main.ui.activity.loginactivity" android:label="@string/title_activity_login" android:theme="@style/apptheme.noactionbar" /> <activity android:name=".main.ui.activity.mainactivity" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application>
`
i had similar issue , resolved doing pretty usual things in android studio. need to
invalidate caches , clean project
you know, dagger2 generates lot of code @ compile time , things can mess up, if using instant run, provided android studio 2.0
Comments
Post a Comment