主源集中的重构不会传播到非活动的构建变体 [英] Refactoring inside the main source set doesn't propagate to inactive build variants

查看:22
本文介绍了主源集中的重构不会传播到非活动的构建变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有主源集的src/main/java.还有一个名为 heroes 的产品风格的 src/heroes/java 源集和一个名为 heroes 的产品风格的 src/villains/java 源集恶棍.

I have src/main/java for the main source set. Also a src/heroes/java source set for a product flavor named heroes and a src/villains/java source set for a product flavor named villains.

那些只有一个构建类型,debug.这意味着构建变体窗格将包含 heroesDebugvillainsDebug.

Those have only a single build type, debug. Meaning the build variants pane will contain heroesDebug and villainsDebug.

现在,在 Android Studio 中,如果我选择构建变体 heroesDebugsrc/mainsrc/heroes 变为活动",而 <代码>src/villains停用".这意味着我可以在那些活动"源集上使用 ALT + 插入、代码完成以及 IDE 的其他此类功能.语法高亮之类的东西甚至不会显示在非活动"源集中的文件上.

Now, in Android Studio, if I select build variant heroesDebug, src/main and src/heroes become "active" while src/villains "deactivates". Meaning I can use ALT + Insert, code complete, and other such features of the IDE on those "active" source sets. Things like syntax highlighting won't even show on files inside an "inactive" source set.

这基本上没问题.但是如果我重命名或移动 src/main 中的许多类,这些类在 src/villains 中的许多地方导入,我就会遇到一个大问题.我注意到重构的包或类名反映在 src/heroes 中,但是当我切换到 villainsDebug 时,我会看到红线和 Cannot resolve symbol src/villains 中的错误,IDE 应该更新包或类的新名称或位置!

And that's mostly fine. But I'll have a huge problem if I rename or move a lot of classes in src/main that are imported in many places within src/villains. I've noticed that the refactored package or class names reflect in src/heroes but when I switch to villainsDebug, I'll see red lines and Cannot resolve symbol errors in src/villains where the IDE should've updated the new names or locations of packages or classes!

反之亦然——如果 villainsDebug 处于活动状态并且我重新整理了 src/main 中的一些代码,这些更改将传播到 src/villains 但如果我再次切换到 heroesDebug,这些更改将无处可见.

That also works in reverse — if villainsDebug is active and I reshuffle some code in src/main, the changes will propagate to src/villains but if I again switch to heroesDebug, those changes will be nowhere to be seen.

编辑

那么如何在 src/main 中获得更改以传播到所有其他非活动"构建变体的源集?

So how do I get changes in src/main to propagate to all the other source sets of "inactive" build variants?

推荐答案

尝试将其添加到您的应用 build.gradle 中:

try to add this in your apps build.gradle :

android{
...
    sourceSets{
        main{
            java.srcDirs = ['src', 'heroes', 'villains']
        }
    }
}

这将导致所有目录都可见,您应该只在重构时执行此操作,然后再将其删除,因为您将看到重复的类异常.此外,这将创建一个奇怪的 Android 项目视图,其中包含多个 java 文件夹.可能不是最好的解决方案,但它对我有用

this will cause all directories to be visible and you should do this only while refactoring and then remove this afterwards, because you will see duplicate class exceptions. Also this will create a weird Android project view, with multiple java folders. Probably not the best solution, but it worked for me

这篇关于主源集中的重构不会传播到非活动的构建变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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