Dagger2不生成匕首*类
如标题所示,Dagger2不生成Dagger *前缀类。我看了一些其他类似的帖子,但似乎没有任何工作。Dagger2不生成匕首*类
我克隆此回购https://github.com/ecgreb/mvpc,已失效Android Studio中的缓存和重新启动它,我删除$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'
}
Application类。
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;
}
}
如果使用
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
。
工作。但是在设置指南https://github.com/google/dagger中,他们使用'annotaionProccessor'。此外,生成的类名是'DaggerMvpcApplication_ApplicationComponent'我认为他们不赞成这个约定,它不应该是'DaggerApplicationComponent'吗? – Bri6ko
这个类的名称发生是因为你的接口是一个“内部类”('public static interface') – EpicPandaForce
这很有道理。 – Bri6ko
对于任何在您的项目中使用Jack Compiler时遇到此类问题的人,您可能已经看到没有任何解决方案可行,原因与Dagger2本身相关。最新版本不适合杰克,我的经理直到2.2版本的Dagger2才开始工作。
我也面临同样的问题。你是如何解决它的? http://imgur.com/a/9uOxX –
我在Gradle依赖关系中坚持使用Dagger2的旧版本2.2来解决它。如果你想用Jack作为Dagger的编译器,那么现在就没有别的选择了。 –
我在Java 8上使用2.2与Jack编译器,它根本不起作用。 –
你能分享你的ApplicationComponent类 – AJay
https://github.com/antoniolg/androidmvp你可以在这里看到整个代码。 @AJay – Bri6ko
这个回购没有'匕首'代码。它唯一的mvp – AJay