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

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

问题描述

我将主源设置为src/main/java.也是名为heroes的产品风味的src/heroes/java来源集和名为villains的产品风味的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中,如果我选择构建变体heroesDebug,则src/mainsrc/heroessrc/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时,我会在src/villains中看到红线和Cannot resolve symbol错误,其中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']
        }
    }
}

这将使所有目录可见,并且您仅应在重构时执行此操作,然后再删除它,因为您将看到重复的类异常.同样,这将创建一个带有多个java文件夹的怪异的Android项目视图.可能不是最好的解决方案,但对我有用

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天全站免登陆