Dagger2为NetworkModule_LoggingInterceptorFactory收到NoClassDefFoundError错误

时间:2017-06-04 06:09:01

标签: android dependency-injection dagger-2 dagger

当我尝试在更多Android设备上测试我的应用程序时,我收到此错误:

java.lang.NoClassDefFoundError: com.myapp.androidapp.Dagger.Modules.NetworkModule_LoggingInterceptorFactory

我搜索有关Dagger的更多问题,但我无法找到这个错误,我该如何解决,

我的应用程序在SonyLenovo tables上工作正常,但它不适用于Samsung

申请类:

component = DaggerGithubApplicationComponent.builder()
        .contextModule(new ContextModule(this))
        .jobManagerModule(new JobManagerModule())
        .networkServiceModule(new NetworkServiceModule("https://api.github.com/"))
        .build();

githubService = component.getGithubService();
picasso = component.getPicasso();
jobManager = component.getJobManager();
handler = component.getHandler();

我的NetworkModule类:

@Module(includes = ContextModule.class)
public class NetworkModule {

    @Provides
    @AlachiqApplicationScope
    public HttpLoggingInterceptor loggingInterceptor() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(String message) {
                Timber.e(message);
            }
        });
        interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        return interceptor;
    }

    @Provides
    @AlachiqApplicationScope
    public RxJavaCallAdapterFactory rxAdapter() {
        return RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
    }


    @Provides
    @AlachiqApplicationScope
    public Cache cache(File cacheFile) {
        return new Cache(cacheFile, 10 * 1000 * 1000); //10MB Cahe
    }

    @Provides
    @AlachiqApplicationScope
    public File cacheFile(@ApplicationContext Context context) {
        return new File(context.getCacheDir(), "okhttp_cache");
    }

    @Provides
    @AlachiqApplicationScope
    public OkHttpClient okHttpClient(HttpLoggingInterceptor loggingInterceptor, Cache cache) {
        return new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .cache(cache)
                .build();
    }
}

GithubApplicationComponent:

@MyAppApplicationScope
@Component(
        modules = {
                UserInformationModule.class,
                NetworkServiceModule.class,
                PicassoModule.class,
                JobManagerModule.class,
                SocketModule.class,
                HandlerModule.class,
                ActivityModule.class
        }
)
public interface GithubApplicationComponent {
    GithubService getGithubService();

    JobManager getJobManager();

    Picasso getPicasso();

    Socket getSocket();

    Handler getHandler();
}

我的完整LogCat:

java.lang.NoClassDefFoundError: com.myapp.androidapp.Dagger.Modules.NetworkModule_LoggingInterceptorFactory
at com.myapp.androidapp.Dagger.Components.DaggerGithubApplicationComponent.initialize(DaggerGithubApplicationComponent.java:87)
at com.myapp.androidapp.Dagger.Components.DaggerGithubApplicationComponent.<init>(DaggerGithubApplicationComponent.java:76)
at com.myapp.androidapp.Dagger.Components.DaggerGithubApplicationComponent.<init>(DaggerGithubApplicationComponent.java:0)
at com.myapp.androidapp.Dagger.Components.DaggerGithubApplicationComponent$Builder.build(DaggerGithubApplicationComponent.java:210)
at com.myapp.androidapp.Alachiq.onCreate(Alachiq.java:124)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1017)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4717)
at android.app.ActivityThread.access$1600(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1419)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

0 个答案:

没有答案