Pra*_*eep 2 android android-gradle-plugin android-viewbinding
我使用的是 Android Studio 4.0.1 版。
当我添加 viewBinding 时,出现错误。
在 gradle 中添加 viewBinding 时出错。
buildFeatures {
viewBinding = true
}
Run Code Online (Sandbox Code Playgroud)
build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "1.2.0"
resValue("string", "growingio_project_id", "8979dc98cc52320f")
resValue("string", "growingio_url_scheme", "growing.1f3e3791e1d6aee5")
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibilityVersion
targetCompatibility rootProject.ext.targetCompatibilityVersion
}
buildFeatures {
viewBinding = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: "*.jar")
implementation deps.swipeRevealLayout
implementation deps.glide
implementation deps.growingio
implementation(deps.rxbus) {
exclude group: 'com.jakewharton.timber', module: 'timber'
}
implementation deps.androidasync
implementation deps.timber
}
Run Code Online (Sandbox Code Playgroud)
错误 :
无法在 com.android.build.gradle.internal.dsl.BaseAppModuleExtension 类型的对象上找到参数 [build_6zjavhoqnf2k7dfs2qrq542f3$_run_closure1$_closure5@6cd00094] 的方法 buildFeatures()。
为什么会出现这个错误?
我该如何解决这个错误?
要buildFeatures在您的应用中使用,您build.gradle必须使用android gradle 插件 4.0.x
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
Run Code Online (Sandbox Code Playgroud)
然后你可以使用:
android {
//...
buildFeatures {
viewBinding true
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是android gradle 插件 3.6,则可以使用:
android{
//....
viewBinding {
enabled = true
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
900 次 |
| 最近记录: |