正如标题所述,Dagger2并不生成Dagger*前缀类。我在这里看了一些类似的帖子,但似乎没有效果。
我克隆了这个回购https://github.com/ecgreb/mvpc,使Android的缓存失效并重新启动,我删除了$Project/.gradle和$Home/.gradle/caches,清理和重建了这个项目,但仍然无法工作。
在一些使用Dagger2的项目中也发生了这种情况。
我是不是遗漏了什么?
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.example.ecgreb.mvpc"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile "com.google.dagger:dagger:2.7"
annotationProcessor "com.google.dagger:dagger-compiler:2.7"
provided 'javax.annotation:jsr250-api:1.0'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.assertj:assertj-core:1.7.1'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
}申请课。
package com.example.ecgreb.mvpc;
import android.app.Application;
import com.example.ecgreb.mvpc.controller.LoginActivity;
import javax.inject.Singleton;
import dagger.Component;
public class MvpcApplication extends Application {
@Singleton @Component(modules = { LoginModule.class }) public interface ApplicationComponent {
void inject(LoginActivity loginActivity);
}
private ApplicationComponent component;
@Override public void onCreate() {
super.onCreate();
//DaggerApplicationComponent IS NOT BEING GENERATED
component = DaggerApplicationComponent.builder().build();
}
public ApplicationComponent component() {
return component;
}
}发布于 2016-11-18 17:49:04
如果您使用
apply plugin: 'com.neenbedankt.android-apt'然后,代替
annotationProcessor "com.google.dagger:dagger-compiler:2.7"做
apt "com.google.dagger:dagger-compiler:2.7"不过,Android在3.0版就不能工作了,所以你需要用annotationProcessor代替所有的apt。
如果使用Kotlin,则必须将annotationProcessor替换为kapt,并将apply plugin: 'kotlin-kapt'添加到build.gradle文件中。
发布于 2017-04-02 09:01:44
对于在您的项目中使用Jack时遇到此类问题的任何人,您可能已经看到这些解决方案都不起作用,原因是与Dagger2本身有关。最新的版本不能很好的工作杰克,我的经理,以使它工作到2.2版本的Dagger2。
https://stackoverflow.com/questions/40682684
复制相似问题