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

查看:79
本文介绍了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下的文件夹被标记为source,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天全站免登陆