Android Studio need to rebuild project before each run

前端 未结 5 1802
灰色年华
灰色年华 2020-12-09 09:37

Recently the android studio shows Error Java cannot find Symbol or each run. i have to go to built and rebuilt the project before each run. Is there any way to fix it? i do

5条回答
  •  孤城傲影
    2020-12-09 09:53

    In my case, I had changed the sourceSets:

    android {
        sourceSets {
            main {
                res.srcDirs =
                        [
                                'src/main/res',
                                'src/main/res/layouts',
                                'src/main/res/layouts/content',
                                'src/main/res/layouts/layout',
                                'src/main/res/layouts/fragment',
                                'src/main/res/layouts/dialog',
                                'src/main/res/layouts/appbar',
                        ]
            }
        }
    }
    

    and locate some *.xml to layouts/layout directory...

    finally I got the problem, don't place file in layouts/layout directory, so I created an activity directory and cut that files to activity directory, and finally edit the gradle this way:

    android {
        sourceSets {
            main {
                res.srcDirs =
                        [
                                'src/main/res',
                                'src/main/res/layouts',
                                'src/main/res/layouts/activity',
                                'src/main/res/layouts/content',
                                'src/main/res/layouts/layout',
                                'src/main/res/layouts/fragment',
                                'src/main/res/layouts/dialog',
                                'src/main/res/layouts/appbar',
                        ]
            }
        }
    }
    

提交回复
热议问题