Wiz*_*006 6 android gradle kotlin android-viewbinding
在我的项目中启用视图绑定后出现错误。
我尝试重新同步项目,使缓存无效。我的应用程序gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.learning.aboutme"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
viewBinding.enabled = true
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)
我的项目gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
我的活动 main.xml:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.learning.aboutme"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
viewBinding.enabled = true
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Run Code Online (Sandbox Code Playgroud)
在这里,机器人工作室给出一个警告android:contentDescription,textAlignment,lineSpacingMultiplier,text等
这是我的主要 activity.kt 文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
这里 android studio 说:无法访问android.viewbinding.ViewBinding哪个是com.learning.aboutme.databinding.ActivityMainBinding. 在ActivityMainBinding.inflate()
我尝试创建一个新项目并将我的文件移动到那里,但出现相同的错误(尝试移动activity_main.xml和相同的错误。
如何解决这个问题?
uwe*_*uwe 12
对我来说,当我添加时错误消失了
implementation 'com.android.databinding:viewbinding:4.0.1'
Run Code Online (Sandbox Code Playgroud)
到build.gradle文件。
此依赖项包含android.viewbinding.ViewBindingAndroidStudio 无法访问的类。
Rom*_*ych 12
就我而言,以下步骤(清除缓存)确实有帮助:
第 1 步:打开终端并转到终端中的项目路径。
步骤 2:可选点击此命令git clean -xfd或安全变体git clean。 请小心-xfd这一点,因为这会删除未跟踪的文件和.gitignore files
步骤 3:转到:文件 -> 使缓存无效/重新启动。
sus*_*vi 11
昨天面临同样的问题,确切的错误。对我来说解决方案是
并且错误消失了
确保
Run Code Online (Sandbox Code Playgroud)buildFeatures { viewBinding true }
| 归档时间: |
|
| 查看次数: |
1718 次 |
| 最近记录: |