Due to importing other people's projects and changing the version number of gradle, the project always reported an error. Finally, it was found that the problem was in ButterKnife when I looked up the data. Some people had NullPointerException, and my error was as follows:
gradle version number
classpath 'com.android.tools.build:gradle:3.1.0'
The solution is as follows:
- Add the following code to build.gradle of Project:
buildscript { repositories { jcenter() google() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { classpath 'com.android.tools.build:gradle:3.1.0' classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-SNAPSHOT' } } allprojects { repositories { jcenter() google() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } }
- Add the following code to build.gradle of Module:
apply plugin: 'com.android.library' apply plugin:'com.jakewharton.butterknife' android { compileSdkVersion 25 buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 17 targetSdkVersion 25 versionCode 1 versionName "1.0" //This is to be added javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' }
- Add the following code to build.gradle of app:
In dependencies, add:
implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
Note: Module and app can be added, especially those with inheritance relationship. Complex and implementation cannot be mixed