[英]Dagger2 not generating Daggercomponent classes
Dagger2在Android工作室中沒有生成任何組件類我知道它是一個已知的問題,而我已經完成了幾乎所有方法在我的android工作室中實現並嘗試了各種教程但是每次我被擊中這里,它都無法構建dagger組件上課。 我也嘗試重建,清理漸變並使緩存無效,但它沒有幫助。 這是我的示例項目build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.g.daggerillkillu"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories{
maven{url "https://jetpack.io"}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
}
vehiclemodule.java
@Module
public class vehiclemodule {
@Provides
@Singleton
Motor providesMotor(){
return new Motor();
}
@Provides
@Singleton
Vehicle provideVehicle(){
return new Vehicle(new Motor());
}
}
vehicleComponent.java
@Singleton
@Component(modules = {vehiclemodule.class})
public interface VehicleComponent {
Vehicle provideVehicle();
}
Android工作室有什么問題,或者我做錯了什么?
您還需要擁有模塊並構建它們。 請查看完整的教程
https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.