-1
私はAndroidプロジェクトでdaggerを使用しようとしています。投稿された依存関係をインポートした後で、私は という注釈を使用することができましたが、ダガーインタフェースは@Component
を使用できません。私のインターフェースは「MyComponentの」と呼ばれている場合、例えば、私は次のようにそれを使用したい とき:daggerインターフェイスを呼び出すために必要な依存関係
DaggerMyComponent.build()
私はDaggerMyComponentが定義されていないと私はそれを使用しないことを見出しました。私Gradle
ファイルを見ていると、任意の薄い不足している
のGradleがあれば私に教えてください:gradle.Appプロジェクト
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //added apt for source code generation
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven{
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.pc_amr.dagger_1"
minSdkVersion 16
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'
}
}
}
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.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger-android:2.11'
compile 'com.google.dagger:dagger-android-support:2.11' // if you use the support libraries
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
}
インタフェースコンポーネント
@Module
public class VehicleModule {
@Singleton
@Provides
Motor provideMotor(){
return new Motor();
}
@Singleton
@Provides
Vehicle provideVehicle(){
return new Vehicle(new Motor());
}
}
メイン:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VehicleComponent component = DaggerVehicleComponent//Not recognised
}
}
あなたが見ることができますあなたのモジュールとコンポーネントの宣言? – pdegand59
@ pdegand59 Daggerに必要な依存関係が正しいかどうかを私に教えてください。 – LetsamrIt
あなたはVehicleComponentインターフェースを忘れてしまいました。そのインターフェースには '@ Component'で注釈が付けられています。 – pdegand59