ViewBinding无权限访问ViewBinding

ViewBinding

活到老学到学,我做到了
学完Java学Kotlin
学完Kotlin又填坑

一、起因

由于kotlin-android-extensions被废弃了,所以之前用kotlin写的代码都要面临着修改的问题。尝试过还是用findByViewId吧,完全没有问题。就是代码量增加了好多,并且影响到工作量率了。还是不能接受。

当在所有android {中添加了

buildFeatures {
        viewBinding true
    }

然后同步。一定要记得同步。

二、无权访问ViewBuilding

编写binding代码时

binding = ActivityAccountDisableBinding.inflate(layoutInflater)
setContentView(binding.root)

报了一个错误

Cannot access 'android.viewbinding.ViewBinding' which is a supertype of 'com.qeebike.account.databinding.ActivityAccountDisableBinding'. Check your module classpath for missing or conflicting dependencies

无权访问,在


viewBinding

已经看到viewbinding已经加载了,但是为何没有权限了。问了好多度娘,狗爸,Bing哥。但是还是不行,没有找到答案。

三、 瞎猫碰到死老鼠

对比了其他项目一切都是正常配置的,可其他项目就没有问题。最后无脑尝试复制配置后。将gradle.properties中的内容

## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
 org.gradle.parallel=true
#Mon Jan 16 14:18:22 CST 2017
org.gradle.jvmargs=-Xmx1536m
android.injected.testOnly=false

修改为

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableD8=true
android.injected.testOnly=false
android.useAndroidX=true
android.enableJetifier=true

问题解决。似乎与某个配置有关。!_!

Cannot access 'android.viewbinding.ViewBinding' which is a supertype of ''. Check your module classpath for missing or conflicting dependencies.

// END 问题是解决了,如果有人知道原因,记得留言告知下。多谢。

你可能感兴趣的:(ViewBinding无权限访问ViewBinding)