[英]Dagger2 not generating Daggercomponent classes
Dagger2 is not generating any component classes in android studio i know its a known problem while i have gone through almost all ways to implement in my android studio and have tried on various tutorials but every time i got struck here, it fails to build the daggercomponent class . Dagger2在Android工作室中没有生成任何组件类我知道它是一个已知的问题,而我已经完成了几乎所有方法在我的android工作室中实现并尝试了各种教程但是每次我被击中这里,它都无法构建dagger组件上课。 I have also tried to rebuild ,clean gradles and invalidate caches but it does not help . 我也尝试重建,清理渐变并使缓存无效,但它没有帮助。 Here is my one of sample project build.gradle 这是我的示例项目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 vehiclemodule.java
@Module
public class vehiclemodule {
@Provides
@Singleton
Motor providesMotor(){
return new Motor();
}
@Provides
@Singleton
Vehicle provideVehicle(){
return new Vehicle(new Motor());
}
}
vehicleComponent.java vehicleComponent.java
@Singleton
@Component(modules = {vehiclemodule.class})
public interface VehicleComponent {
Vehicle provideVehicle();
}
Is there any problem in the android studio or i am doing something wrong? Android工作室有什么问题,或者我做错了什么?
You also need to have modules, and build them. 您还需要拥有模块并构建它们。 Please check this full tutorial 请查看完整的教程
https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2 https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.