View Binding popular solution

Notice! Notice! Notice! This is just a warning and does not affect the normal compilation and work of the code!
However,
for me who is a clean freak, it is absolutely unbearable! Can't bear it!

Let's not talk nonsense and look at the warning example first:

as warning prompt

How to do it?
what can we do about it?
What to do?

Baidu, Google!
Neither gave an actual solution.

Idea source: ViewBinding popular solution

In the end, I went out to find a solution based on the cause of the problem.

What is the cause of the problem?
AS did not specify which class to refer to, which caused it!

What about the solution?
Isn't it enough to configure a reference source for AS!

Here comes the focus!

After thinking and thinking, I finally know how to deal with it!

Here is the implementation of the solution:

Set the reference source path for him in the configuration build.gradle of the project view binding! (Usually in the app's build.gradle)

 sourceSets {
        main {
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
            jniLibs.srcDirs = ['libs']
            res.srcDirs = ['src/main/res']
            java {
                srcDirs = ['src/main/java']
//                exclude '/com.xiaozhu.xzdz.debug/'  // 不想包含文件的路径
            }
        }
        devDebug {
            java.srcDirs = ['src/main/java', 'build/generated/data_binding_base_class_source_out/devDebug/out']
        }
        prdDebug {
            java.srcDirs = ['src/main/java', 'build/generated/data_binding_base_class_source_out/prdDebug/out']
        }
    }

Graphic:

warning solution

Resolved example:

final preview
Don't you feel a lot better!

Guess you like

Origin blog.csdn.net/github_35033182/article/details/119817299