Android Studio无法识别源文件夹 [英] Android studio doesn't recognise source folders

查看:587
本文介绍了Android Studio无法识别源文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是标准的Android Studio目录结构,并且创建了不同的构建类型:

I'm using a standard Android Studio directory structure and I created different build types:

buildTypes {
    debug {
        runProguard false
        packageNameSuffix ".debug"
        signingConfig signingConfigs.debug
    }
    preview.initWith(buildTypes.debug)
    preview {
        packageNameSuffix ".preview"
    }
    release {
        runProguard false
        signingConfig signingConfigs.release
    }
}

一切正常,但是AS无法识别所有源文件夹. 仅将maindebug下的文件夹标记为源,将previewrelease下的文件夹显示为普通文件夹 实际上,这些文件夹中没有错误检查

everything compiles fine, but AS doesnt recognize all of the source folders. Only folders under main and debug are marked as source, folders under preview and release are displayed as normal folders In effect there is no error checking in those folders

我检查了.iml文件,并且未添加sourceFolder标记.

I checked the .iml file and sourceFolder tags were not added.

如果我手动编辑项目iml文件,请添加以下行:

If I edit the project iml file manually adding the lines:

 <sourceFolder url="file://$MODULE_DIR$/src/preview/java" isTestSource="false" />
 <sourceFolder url="file://$MODULE_DIR$/src/preview/res" type="java-resource" />

似乎工作正常.

...直到我与gradle文件同步-删除了上面的行.

...until I sync with my gradle file - which removes the above lines.

这是gradle插件中的错误,还是我做错了什么?

Is this a bug in gradle plugin, or am I doing something wrong?

推荐答案

您必须在构建变体列表中进行切换,然后AS会选择适当的源集.

You have to switch it in the build variants list, then AS will pick up the appropriate source sets.

这篇关于Android Studio无法识别源文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆