2017-02-10 130 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' 

}