2016-12-06 25 views
4

내 안드로이드 프로젝트에서 dagger2 및 Butterknife를 사용하는 방법을 배우고 Butterknife BindView 주석을 삽입 할 때까지 모든 것이 잘 작동합니다.Android Dagger2 및 Butterknife 충돌

오류 : (5, 57) 오류 : 기호 클래스 DaggerNetComponent

을 찾을 수없는 것은이 내 DaggerNetComponent 코드 :

public class App extends Application { 

private NetComponent mNetComponent; 

@Override 
public void onCreate() { 
    super.onCreate(); 

    mNetComponent = DaggerNetComponent.builder().appModule(new AppModule(this)).netModule(new NetModule("http://example.com/")) 
      .build(); 
} 

public NetComponent getNetComponent() 
{ 
    return mNetComponent; 
} 

}

이 내가 butterknife와 함께 내 시야를 주입하는 방법이다 :

public class MainActivity extends AppCompatActivity implements MainScreenContact.View { 

@BindView(R.id.listContact) 
ListView listView; 

ArrayList<CharSequence> list; 
ArrayAdapter<CharSequence> adapter; 

@Inject 
MainScreenPresenter mainPresenter; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ButterKnife.bind(this); 

BindView 주석을 제거하면 이 클래스에 terKnife를 바인딩하면 잘 작동하지만 사용하면 오류가 표시됩니다.

이 내 Gradle.app입니다

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 
apply plugin: 'android-apt' 


android { 
compileSdkVersion 25 
buildToolsVersion "24.0.3" 
defaultConfig { 
    applicationId "com.project.echo.contactmanagement" 
    minSdkVersion 14 
    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.0.0' 

//Retrofit 
compile 'com.squareup.retrofit2:retrofit:2.0.2' 
//OkHttp 
compile 'com.squareup.okhttp3:okhttp:3.2.0' 
compile 'com.squareup.okio:okio:1.7.0' 

//Gson 
compile 'com.google.code.gson:gson:2.6.2' 
compile 'com.squareup.retrofit2:converter-gson:2.0.1' 

//RxJava 
compile 'io.reactivex:rxjava:1.1.2' 
compile 'io.reactivex:rxandroid:1.1.0' 
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1' 

testCompile 'junit:junit:4.12' 

//Dagger 
apt 'com.google.dagger:dagger-compiler:2.2' 
compile 'com.google.dagger:dagger:2.2' 
provided 'javax.annotation:jsr250-api:1.0' 

//butterknife 
compile 'com.jakewharton:butterknife:8.1.0' 
apt 'com.jakewharton:butterknife-compiler:8.1.0' 
} 

제발 도와주세요, 어떤 대답은

apt 범위를 사용하는 경우

+0

ButterKnife 주석 처리가 실패하면 단검도 실패 할 수 있습니다. 'R.id.listContact'가'ListView '의 인스턴스를 가리키고 있는지 확인하고 청소와 재구성을 시도하십시오. 또한 다른 컴파일 타임 오류도 확인하십시오. –

+0

내 ButterKnife 주석은 실패하지 않으며 R.id.listContact는 ListView를 가리 킵니다. 코드를 삭제하고 다시 작성하려고했지만 오류가 계속 표시됩니다. ButterKnife 주석을 제거하면 오류가 사라집니다. – user1290932

+0

Dagger 2의 최신 버전과 ButterKnife의 최신 버전을 갖고 있습니까? 최소한 build.gradle을 포함하도록 게시물을 수정하십시오. 더 좋은 점은 문제를 재현하는 최소 프로젝트를 만드는 것입니다. 우리는이 두 가지 라이브러리를 프로젝트에서 함께 사용하고 있습니다. –

답변

14

내가 모두 종속성 같은 주석 플러그인을 사용하여이 문제를 해결할 수 있었다 : 다음 문제를 읽고

// Butter Knife 
compile 'com.jakewharton:butterknife:8.4.0' 
apt 'com.jakewharton:butterknife-compiler:8.4.0' 
// Dagger 2 
apt 'com.google.dagger:dagger-compiler:2.8' 
compile 'com.google.dagger:dagger:2.8' 
provided 'javax.annotation:jsr250-api:1.0' 

이 수정 내놓았다 :

https://github.com/JakeWharton/butterknife/issues/803

+0

예,이 방법이 유용합니다. 고맙습니다 ... – user1290932

+0

두 라이브러리의 버전이 변경되었습니다. –

0

, 당신은 추가 할 필요가 ... 감사 ... 감사합니다 빌드에서 다음 ~ android {은 다음과 같습니다.

android { 
    // ... 
    packagingOptions { 
     // Exclude file to avoid 
     // Error: Duplicate files during packaging of APK 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/ASL2.0' 
     exclude 'META-INF/services/javax.annotation.processing.Processor' // <-- that one 
    } 
} 

그리고 나는 단지 android-apt 만 적용해야한다고 생각합니다.

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 
//apply plugin: 'android-apt' 

는 그러나 또 다른 가능성은 레이아웃에 존재하는, 그래서 ButterKnife 지금 컴파일시 실패하지 않는 뷰를 결합하려고하는 것입니다.

+0

나는 이것을 시험해 보았지만, 그다지 효과가 없다. 여전히 오류가 난다. – user1290932

+0

그런 다음 "단검 구성 요소가 존재하지 않습니다"이상의 컴파일 오류 메시지를 확인하십시오. 어딘가에 있어야합니다. – EpicPandaForce

2

나는 해결책을 찾았지만, 이것이 완벽하다고 생각하지 않는다. 버터 나이프 버전을 8.1.0에서 8.0.1로 변경하면 모든 것이 잘 동작합니다. 내 gradle.app에서 변경

//butterknife 
compile 'com.jakewharton:butterknife:8.0.1' 
apt 'com.jakewharton:butterknife-compiler:8.0.1' 
+0

단검 버전을 2.8로 변경하는 것은 어떻습니까? –