2017-02-10 173 views
-2

我正在嘗試使用butterknife。但我得到錯誤「無法解析符號'** ButterKnife'」。 我試圖手動導入butterknife.ButterKnife,但我得到了同樣的錯誤 和我的gradle修改並添加這些行: 項目一級...無法解析符號'ButterKnife'

dependencies { 
       classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
      } 

在模塊級...

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

dependencies { 

    compile 'com.jakewharton:butterknife-compiler:8.5.1' 
    apt 'com.jakewharton:butterknife-compiler:8.5.1' 

} 

我該怎麼辦? 在此先感謝。 這裏是我的代碼截圖在那裏我得到了錯誤 link for the screenshot

+0

你現在可以檢查... –

+0

嘗試清理和重建項目...... –

回答

1
apply plugin: 'com.android.application' 
android { 
    compileSdkVersion XX 
    buildToolsVersion "XX.0.0" 
    defaultConfig { 
     applicationId "com.xxxxx.xxx" 
     minSdkVersion xx 
     targetSdkVersion xx 
     versionCode x 
     versionName "x.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
    } 
} 


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


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.1' 
    testCompile 'junit:junit:4.12' 

    compile 'com.android.support:multidex:1.0.1' 
    compile 'com.google.code.findbugs:jsr305:2.0.1' 
    compile 'com.android.support:design:25.1.1' 
    compile 'com.jakewharton:butterknife:8.0.1' 

    apt 'com.jakewharton:butterknife-compiler:8.0.1' 
    testCompile 'junit:junit:4.12' 
} 
+0

仍具有相同的錯誤:/ –

+1

問題在這裏,我換成了: compile'c​​om.jakewharton:butterknife-compiler:8.5.1' by 編譯'com.jakewharton:butterknife:8.5.1' 它的工作 –

0
compile 'com.jakewharton:butterknife:7.0.1' 
+0

這是給我的另一個錯誤無法解析'com.jakewharton:butterknife:7.0.1' –

+0

我想我不會這樣做是因爲它是舊版本,對! –

+0

u能發送錯誤 – Maitri

0

試試這個,

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

仍具有相同的錯誤:/ –

0

請檢查official document here。 總之你的依賴看起來象下面這樣:

dependencies { 
    // ... other dependencies here 
    compile 'com.jakewharton:butterknife:8.5.1' 
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 
} 
+0

感謝回覆, 我檢查了官方文檔,並且我在第一次設置了這樣的依賴關係,但是我得到了同樣的錯誤 –

0

試試這個,

apply plugin: 'com.android.application' 
apply plugin: 'com.jakewharton.butterknife' 


buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' 
    } 
} 


android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 
    defaultConfig { 
     applicationId "com.tanamo.tutorial" 
     minSdkVersion 10 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 

    compile 'com.android.support:appcompat-v7:25.0.0' 
    compile 'com.android.support:support-v4:25.2.0' 

    compile 'com.jakewharton:butterknife:8.5.1' 
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' 

}