Bri*_*6ko 2 android dagger dagger-2
正如标题所说,Dagger2没有生成Dagger*前缀类.我在这里看了一些其他类似的帖子,但似乎没有任何效果.
我克隆此回购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'
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
Epi*_*rce 15
如果你使用
apply plugin: 'com.neenbedankt.android-apt'
Run Code Online (Sandbox Code Playgroud)
然后而不是
annotationProcessor "com.google.dagger:dagger-compiler:2.7"
Run Code Online (Sandbox Code Playgroud)
做
apt "com.google.dagger:dagger-compiler:2.7"
Run Code Online (Sandbox Code Playgroud)
但Android-apt在AS 3.0中不起作用,所以你需要annotationProcessor代替每一个apt.
如果你使用科特林,则必须更换annotationProcessor同kapt,并添加apply plugin: 'kotlin-kapt'到您的build.gradle文件
| 归档时间: |
|
| 查看次数: |
5200 次 |
| 最近记录: |