0

我正在使用 Viper MVP 代码架构 -

当我编译代码时,我收到了这个错误-

    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)

这是我的 Gradle 文件-

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"
}

这是我的根级 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'
}

编辑

  • LoginMvpPresenter 类

    包 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> {
    
    }
    
4

1 回答 1

0

由于我不知道您的依赖关系图的结构或您如何注入这些依赖关系,我只能给您一个通用示例。另外,我不确定它如何与您在界面上指定的泛型一起使用。

您正在尝试提供一个没有实现的接口。您需要定义要返回的对象,该对象在Module. 由于这个接口是一个Presenter我假设它被用于 Activity 或 Fragment。

在您Activity创建一个内部类,如下所示:

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

然后也作为内部接口创建一个组件。

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

现在您的活动知道如何创建依赖项以及在哪里注入它,您需要做的就是注入您的类,您可以像这样从您那里onCreate完成Activity

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

现在您可以使用@Inject注释并将您的演示者声明为您的Activity类的一个字段。

于 2017-07-27T12:29:17.293 回答