android butterknife 未显示生成 butterknife 在 Android Studio4.1.2 中生成注入
android butterknife not showing Generate butterknife generate injections in Android Studio4.1.2
我正在尝试在更新的 android studio 4.1.2 中使用黄油刀,但在 生成 [=27= 中没有得到 生成黄油刀注入 ]选项。
我已经添加了插件:Android ButterKnife Zelezny
构建gradle(项目)
/
/ Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块)
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.a.b"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-auth'
//butterknnife
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
添加所有这些并重新启动后 android studio 在生成中没有获得 butterknife 注入选项
所有依赖声明看起来都很好。请进行干净的构建以解决问题。
仅供参考,您不需要应用 butterknife 插件和
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
你只需要在应用程序中有以下依赖项build.gradle
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
经过尝试和搜索,我发现 Butterknife 已被弃用,因此不会显示
生成 butterknife 注入
单击 R.layout.abc.xml.
时从 生成 选项
解决方案 1
但它仍然有效,只是你必须像下面那样手动声明它
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.iv_upload)
ImageView ivUpload;
@BindView(R.id.textView)
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abc);
ButterKnife.bind(this);
}
}
解决方案 2
作为@CommonsWare 在评论中推荐使用其他东西,
View binding 是当前领先的选择。
我正在尝试在更新的 android studio 4.1.2 中使用黄油刀,但在 生成 [=27= 中没有得到 生成黄油刀注入 ]选项。
我已经添加了插件:Android ButterKnife Zelezny
构建gradle(项目) /
/ Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块)
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.a.b"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-auth'
//butterknnife
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}
添加所有这些并重新启动后 android studio 在生成中没有获得 butterknife 注入选项
所有依赖声明看起来都很好。请进行干净的构建以解决问题。
仅供参考,您不需要应用 butterknife 插件和
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
你只需要在应用程序中有以下依赖项build.gradle
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
经过尝试和搜索,我发现 Butterknife 已被弃用,因此不会显示
生成 butterknife 注入
单击 R.layout.abc.xml.
解决方案 1
但它仍然有效,只是你必须像下面那样手动声明它
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.iv_upload)
ImageView ivUpload;
@BindView(R.id.textView)
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.abc);
ButterKnife.bind(this);
}
}
解决方案 2
作为@CommonsWare 在评论中推荐使用其他东西,
View binding 是当前领先的选择。