让我想想验证库,它存在于 .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')
}
| 更新 |
所以经过一些解决方法后,我看到 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
}
}
}