【问题标题】:Android Studio does not show the res directoryAndroid Studio 不显示 res 目录
【发布时间】:2020-10-22 22:00:17
【问题描述】:

我在 Android Studio (4.0.1) 中签出了一个 Android 项目。 build.gradle 包含以下 sourceSets 块(如下所示的 sn-p)。这是为了防止某些值资源文件包含在打包的 aar 中(我只想在 aar 中包含 values-en-rUS 和 values-es-rUS)。

aar 被正确打包,并且只包含 values-en-rUS 和 values-es-rUS,正如预期的那样。

sourceSets {

        main {
            def resSrc = fileTree(dir: 'src/main/res').matching { exclude { details ->
                (!details.file.canonicalPath.matches('.*values-(en|es)-rUS.*')
                        && details.file.canonicalPath.matches('.*values-.*'))
            } }
            
            ...
            res.srcDirs = [ resSrc ]
            ...

        }
    }

However, Android Studio does not show me the res directory (the entire directory!) anymore in the "Project" sidebar when "Android" is selected, and the Java code files can no longer resolve the ids or layouts (例如findViewById(R.id.bottom_sheet_layout) -- 它们显示为红色波浪线)。

在这种情况下,我怎样才能让 Android Studio 继续显示 res 目录?

谢谢。

【问题讨论】:

    标签: android android-studio build.gradle


    【解决方案1】:

    试试这个:

    sourceSets {
    
        main {
            def resSrc = fileTree(dir: 'src/main/res').matching { exclude { details ->
                (!details.file.canonicalPath.matches('.*values-(en|es)-rUS.*')
                        && details.file.canonicalPath.matches('.*values-.*'))
            } }
    
            res.srcDirs = [resSrc, 'src/main/res']
    
        }
    }
    

    注意:如果两个或多个资源目录包含相同的资源文件,则资源合并时会出错。

    欲了解更多信息:https://developer.android.com/studio/write/add-resources

    【讨论】:

    • 谢谢,但这不是我所期望的。我想设置 res.srcDirs 以便它从我的“src/main/res”中排除一些文件,而不是合并两个资源目录。我找不到如何执行拆分而不是合并
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多