0

I am working with Viper MVP Code architecture -

When i compile the code i am getting this error-

    Error:(32, 10) error: com.tv.goin.activities.login.LoginMvpPresenter<com.tv.goin.activities.logi  n.LoginMvpView,com.tv.goin.activities.login.LoginMvpInteractor>   
cannot be provided without an @Provides- or @Produces-annotated method.
    com.tv.goin.activities.login.LoginMvpPresenter<com.tv.goin.activities.login.LoginMvpView,com.tv.goin.activities.login.LoginMvpInteractor> is injected at
    com.tv.goin.activities.login.LoginActivity.mPresenter
    com.tv.goin.activities.login.LoginActivity is injected at
    com.tv.goin.di.component.ActivityComponent.inject(activity)

Here is my Gradle file -

apply plugin: 'com.android.application'
//apply plugin: 'com.neenbedankt.android-apt'


android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        applicationId "com.tv.goin"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

    }
    buildTypes {
        debug {
            buildConfigField("String", "BASE_URL", "\"http://www.mocky.io/v2\"")
            buildConfigField("String", "API_KEY", "\"ABCXYZ123TEST\"")
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("String", "BASE_URL", "\"http://www.mocky.io/v2\"")
            buildConfigField("String", "API_KEY", "\"ABCXYZ123TEST\"")
        }
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // android support libraries
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-vector-drawable:$rootProject.supportLibraryVersion"
    compile "com.android.support:animated-vector-drawable:$rootProject.supportLibraryVersion"

    // font
    compile "uk.co.chrisjenx:calligraphy:$rootProject.calligraphyVersion"

    // network
    compile "com.amitshekhar.android:rx2-android-networking:$rootProject.rx2FastAndroidNetworking"

    // image
    compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"

    // parser
    compile "com.google.code.gson:gson:$rootProject.gsonVersion"

    // database
    compile "org.greenrobot:greendao:$rootProject.greenDaoVersion"

    // debug database
    debugCompile "com.amitshekhar.android:debug-db:$rootProject.debugDBVersion"

    // dependency injection
    compile "com.google.dagger:dagger:$rootProject.dagger2Version"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'javax.inject:javax.inject:1'

    // reactive
    compile "io.reactivex.rxjava2:rxjava:$rootProject.rxjava2Version"
    compile "io.reactivex.rxjava2:rxandroid:$rootProject.rxandroidVersion"

    // code generator for view
    compile "com.jakewharton:butterknife:$rootProject.butterKnifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterKnifeVersion"

    // swipe view
    compile "com.mindorks:placeholderview:$rootProject.placeholderviewVersion"

    // logger
    compile "com.jakewharton.timber:timber:$rootProject.timberVersion"

    // dependencies for local unit tests
    testCompile "junit:junit:$rootProject.ext.junitVersion"
    testCompile "org.mockito:mockito-core:$rootProject.mockitoVersion"
    testAnnotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"

    // UI Testing
    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion"
    androidTestCompile "org.mockito:mockito-core:$rootProject.mockitoVersion"
    androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version"
}

configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$supportLibraryVersion"
}

Here is my root level Gradle -

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
//        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 16
    targetSdkVersion = 25
    compileSdkVersion = 25
    buildToolsVersion = '25.0.2'

    // App dependencies
    supportLibraryVersion = '25.3.1'
    gsonVersion = '2.8.0'
    calligraphyVersion = '2.2.0'
    glideVersion = '3.7.0'

    rx2FastAndroidNetworking = '1.0.0'

    dagger2Version = '2.8'
    rxjava2Version = '2.0.6'
    rxandroidVersion = '2.0.1'
    butterKnifeVersion = '8.6.0'
    greenDaoVersion = '3.2.0'
    placeholderviewVersion = '0.6.1'
    debugDBVersion = '1.0.0'
    timberVersion = '4.5.1'

    //Test dependencies
    junitVersion = '4.12'
    espressoVersion = '2.2.2'
    mockitoVersion = '2.7.1'
}

EDIT

  • LoginMvpPresenter class

    package com.tv.goin.activities.login;

    import com.tv.goin.BaseClasses.MvpPresenter;
    import com.tv.goin.di.PerActivity;
    
    /**
     * Created by Shoeb on 26/7/17.
     */
    @PerActivity
    public interface LoginMvpPresenter<V extends LoginMvpView,
            I extends LoginMvpInteractor> extends MvpPresenter<V,I> {
    
    }
    
Avi Cherry
  • 3,996
  • 1
  • 26
  • 31
Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42

1 Answers1

0

As I do not know the structure of your dependency graph or how you're injecting these dependencies, I can only give you generic example. Also I am not sure of the top of my head how it works with the generics like you have specified on your interface.

You are trying to provide an interface which has no implementation. You need to define the object you are going to return that implements your interface in a Module. As this interface is a Presenter I am assuming it's being used in an Activity or Fragment.

In your Activity create an inner class like the following:

@dagger.Module
class Module { 
    @Provides
    public LoginMvpPresenter<Class> providesPresenter() {
        return new LoginMvpPresenterImpl();
    }
}

Then also as an inner interface create a component.

@dagger.Component {
    dependencies = AppComponent.class,
    modules = {
        Module.class
    }
}
interface Component {
    void inject(MyActivity activity);
}

Now your activity knows how to create the dependency and where to inject it all you need to do is inject your class which you can do from the onCreate of you Activity like so.

DaggerMyActivity_Component.builder()
   .appComponent(getAppComponent())
   .build()
   .inject(this);

Now you can use the @Inject annotation and declare your presenter as a field of your Activity class.

StuStirling
  • 15,601
  • 23
  • 93
  • 150