我在Android Studio项目中有一堆代码,是从另一个项目中添加的。当我最初添加它时,我还没准备好开始使用它,所以我研究了如何排除源文件并将其添加到build.gradle
:
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/**'
}
}
}
现在我已经准备好开始使用其中一些类了。我想要做的是指定应包含的单个文件。遗憾的是,include语句似乎没有任何效果,因为gradle仍会报告某个包不存在。
事实上,似乎 include 并没有做任何事情。我希望它具有排除的相反效果。因此,如果我将配置更改为仅指定包含的文件,则仅包括那些文件。可悲的是,事实并非如此。
我也尝试过更明确地使用我的exclude
并指定应排除的20多个包以及我想要包含的各个类但它对我不起作用。以下是这方面的例子:
编辑:这有一个错误,我不打算exclude 'org/odk/collect/android/logic/**'
在那里。我也不需要明确排除包含。我将发布最终解决方案的内容。
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/activities/**'
exclude 'org/odk/collect/android/adapters/**'
exclude 'org/odk/collect/android/application/**'
exclude 'org/odk/collect/android/database/**'
include 'org/odk/collect/android/exception/**'
exclude 'org/odk/collect/android/external/**'
exclude 'org/odk/collect/android/listeners/**'
exclude 'org/odk/collect/android/logic/Drive*'
exclude 'org/odk/collect/android/logic/File*'
include 'org/odk/collect/android/logic/FormControlle'
exclude 'org/odk/collect/android/logic/FormDetails*'
exclude 'org/odk/collect/android/logic/H*'
exclude 'org/odk/collect/android/logic/P*'
exclude 'org/odk/collect/android/logic/**'
exclude 'org/odk/collect/android/picasa/**'
exclude 'org/odk/collect/android/preferences/**'
exclude 'org/odk/collect/android/provider/**'
exclude 'org/odk/collect/android/receivers/**'
exclude 'org/odk/collect/android/tasks/**'
exclude 'org/odk/collect/android/utilities/**'
exclude 'org/odk/collect/android/views/A*'
exclude 'org/odk/collect/android/views/D*'
exclude 'org/odk/collect/android/views/E*'
exclude 'org/odk/collect/android/views/H*'
include 'org/odk/collect/android/views/MediaLayout'
include 'org/odk/collect/android/views/ODKView'
exclude 'org/odk/collect/android/views/T*'
exclude 'org/odk/collect/android/widgets/**'
}
}
}
现在,我知道你可能想知道,为什么甚至在项目中首先拥有所有这些文件?你为什么不删除未使用的那些并在你准备实现它们时再添加它们?原因是我想保持这些文件的git历史记录完整,以便像{{1 }和blame
将代码行正确归因于原始作者。
annotate
示例错误:
include 'org/odk/collect/android/exception/**'
include 'org/odk/collect/android/logic/FormController.java'
include 'org/odk/collect/android/views/A*'
include 'org/odk/collect/android/views/MediaLayout*'
include 'org/odk/collect/android/views/ODKView*'
include 'org/odk/collect/android/widgets/**'
exclude 'org/odk/collect/android/**'
package org.odk.collect.android.logic does not exist
package org.odk.collect.android.exception does not exist
示例错误:
exclude 'org/odk/collect/android/**'
include 'org/odk/collect/android/exception/**'
include 'org/odk/collect/android/logic/FormController.java'
include 'org/odk/collect/android/views/A*'
include 'org/odk/collect/android/views/MediaLayout*'
include 'org/odk/collect/android/views/ODKView*'
include 'org/odk/collect/android/widgets/**'
答案 0 :(得分:1)
只需将其留在这里,以便以后再来。 This answer显示了如何使用HashSet
仅包含所需的文件。因此,例如,如果您只想包含FileA.java
和FileB.java
并排除其他所有内容,则可以使用以下配置:
sourceSets {
main {
java {
setIncludes(new HashSet(['com/somepackage/FileA.java',
'com/somepackage/FileB.java']))
}
}
}
答案 1 :(得分:0)
每个类不包含的exclude
有效。我没有运气包括在内。我宁愿只指定 include 的文件,所以如果有人知道怎么做,请发布另一个解决方案。我在那里留下了include
语句,但发表了评论,因此更明显的是我不会排除哪些文件。
这是一种非常冗长的做事方式。我并不怀疑有更好的方法。
sourceSets {
main {
java {
//needed until we integrate these classes
exclude 'org/odk/collect/android/activities/**'
exclude 'org/odk/collect/android/adapters/**'
exclude 'org/odk/collect/android/application/**'
exclude 'org/odk/collect/android/database/**'
// include 'org/odk/collect/android/exception/**'
exclude 'org/odk/collect/android/external/**'
exclude 'org/odk/collect/android/listeners/**'
exclude 'org/odk/collect/android/logic/Drive*'
exclude 'org/odk/collect/android/logic/File*'
// include 'org/odk/collect/android/logic/F*'
// exclude 'org/odk/collect/android/logic/FormDetails*'
exclude 'org/odk/collect/android/logic/H*'
exclude 'org/odk/collect/android/logic/P*'
exclude 'org/odk/collect/android/picasa/**'
exclude 'org/odk/collect/android/preferences/**'
exclude 'org/odk/collect/android/provider/**'
exclude 'org/odk/collect/android/receivers/**'
exclude 'org/odk/collect/android/tasks/**'
exclude 'org/odk/collect/android/utilities/**'
exclude 'org/odk/collect/android/views/Ar*'
// include 'org/odk/collect/android/views/AudioButton'
exclude 'org/odk/collect/android/views/D*'
exclude 'org/odk/collect/android/views/E*'
exclude 'org/odk/collect/android/views/H*'
// include 'org/odk/collect/android/views/MediaLayout*'
// include 'org/odk/collect/android/views/ODKView*'
exclude 'org/odk/collect/android/views/T*'
exclude 'org/odk/collect/android/widgets/A*'
exclude 'org/odk/collect/android/widgets/B*'
exclude 'org/odk/collect/android/widgets/D*'
exclude 'org/odk/collect/android/widgets/E*'
exclude 'org/odk/collect/android/widgets/G*'
exclude 'org/odk/collect/android/widgets/I*'
exclude 'org/odk/collect/android/widgets/L*'
exclude 'org/odk/collect/android/widgets/O*'
// include 'org/odk/collect/android/widgets/QuestionWidget'
exclude 'org/odk/collect/android/widgets/SelectMulti*'
exclude 'org/odk/collect/android/widgets/SelectOneAuto*'
// include 'org/odk/collect/android/widgets/SelectOneWidget'
exclude 'org/odk/collect/android/widgets/Si*'
exclude 'org/odk/collect/android/widgets/Sp*'
exclude 'org/odk/collect/android/widgets/St*'
exclude 'org/odk/collect/android/widgets/T*'
exclude 'org/odk/collect/android/widgets/U*'
exclude 'org/odk/collect/android/widgets/V*'
// include 'org/odk/collect/android/widgets/WidgetFactory'
}
}
}