pro*_*m85 15 android gradle android-gradle-plugin gradle-task
我在我的项目中使用了很多模块(本地和在线的模块,大多数时候都是20个),我可以说通常不会检查或重新编译它们.我可以将它们全部包含在.jar可以加快构建时间的文件中,但我更喜欢以下内容:
.jar为我的所有模块构建并重用它们的东西.jar文件中.我想要更快的构建时间,但我不想构建.jar文件并手动将它们添加到我的项目中.
关于如何以及如果可能的任何想法?我可以通过一些设置或通过gradle任务或类似的方式来实现吗?
让我考虑一下验证库,它存在于.jar中,我们应该下载它们.在其他情况下,您可以提供多种类型的产品口味.在此之后,只需为您的工作选择Build Flavors.
productFlavors {
fastDebug {
applicationIdSuffix ".jar"
}
regularDegub {
applicationIdSuffix ".regular"
}
....
// Other Configuration
}
dependencies {
...
// Jar Debug by adding only Jar
fastDegubCompile fileTree(dir: 'libs', include: '*.jar')
fastDegubCompile 'com.android.support:support-v4:23.1.1'
...
// Regular Debug with downloading all libraries
// Including only specific from project files
regularDegubCompile 'com.squareup.picasso:picasso:2.5.2'
regularDegubCompile 'com.android.support:support-v4:23.1.1'
regularDegubCompile files('libs/specific1.jar', 'libs/specific2.jar')
}
Run Code Online (Sandbox Code Playgroud)
| 更新|
因此,在一些解决方法之后,我看到Gradle将库收集到一些缓存中,在那里我可以看到源代码.但我仍然在寻找具有项目配置的正确验证库的方法.
现在我编写了用于从Gradle缓存位置收集文件的脚本.并将它们复制到新的位置,我们可以使用构建口味.这种方法非常快(200个库的时间少于7秒),但仍需要改进(见上文).
如果我没有时间,请进行下一次更新,请填写免费扩展解决方案.感谢您的理解.
// Task for calling from Gradle Scripts
// -----------------------------------
task gatheringJarFilesTask << {
println("Gathering Jars Start...")
gatheringJarFiles(gradleCacheLocation, foundedJarsList)
println("------------------------------")
println("Gathering Jars End! Start copying!")
copyFiles(projectJarsLocation, foundedJarsList)
}
// Constants, which might be optimized too
// -----------------------------------
def gradleCacheLocation = '/home/kasyangenka/.gradle/caches/modules-2/files-2.1'
def projectJarsLocation = '/home/kasyangenka/Projects/GradleScriptsTest/app/libs'
List<String> foundedJarsList = []
// Main Script Methods
// -----------------------------------
def gatheringJarFiles(baseDirPath, gatheredList) {
new File(baseDirPath).eachFile {file ->
println("-> Current file: " + file.getName())
if (file.isDirectory()) {
gatheringJarFiles(file.getAbsolutePath(), gatheredList)
}
def containsLib = (file.getName().contains(".jar")
|| file.getName().contains(".aar"));
if (containsLib) {
println("->> Adding Jar file: " + file.getAbsolutePath())
gatheredList.add(file.getAbsolutePath())
}
}
}
def copyFiles (destiny, List sourceList) {
sourceList.each {filePath ->
copy {
from filePath
into destiny
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
235 次 |
| 最近记录: |