2017-08-02 27 views
1

我在我的Android项目的多项目设置:ConfigurationsContainer是空在多项目设置

- android 
    - app 
    - lib1 
    - util 

util我定义的配置:

task createTestJar(type: Jar) { 
    classifier = 'test' 
    from "$projectDir/build/intermediates/classes/test/debug" 
} 

configurations { 
    archives 
    archives.transitive = true 
} 

artifacts { 
    archives createTestJar 
} 

我想引用它在lib1

// doesn't work 
testCompile project(path: ':util', configuration: 'archives') 

我得到这个错误的上述行:

Error:com.android.builder.dependency.level2.JavaDependency cannot be cast to com.android.builder.dependency.level2.AndroidDependency Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)

  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) -Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

// says can't find 'archives' in configuration container 
testCompile project(':util').configurations.archives.artifacts.files 
// works if I manually create the jar beforehand 
testCompile fileTree(dir: "$rootDir/utils/build/libs", include: ['*.jar']) 

我试图打印出哪些配置我util模块已经在lib1

project(':util').configurations.forEach { 
    println("${it.name}") 
} 

而且我得到空的结果。当我在util模块中打印时,我可以看到一个长列表,其中包含我的archives配置。

任何想法为什么发生这种情况?我听说有一些默认任务是由Android的java插件所没有的? BTW都lib1util已应用这些插件:

apply plugin: 'com.android.library' 
apply plugin: 'kotlin-android' 
+0

你把这个项目称为'util',但在你的代码使用'utils'和'shared-utils'。这是一个简单的错字在帖子中还是它也出现在您的代码?原则上你的第一个例子应该是正确的,也许你可以指定它不工作,如果错字不应该是唯一的原因。你的第二个例子和你的调试代码都会遇到同样的问题,即执行顺序。如果'util'项目的*配置阶段*(以及因此构建文件评估)位于您的''lib'项目之后,则配置将不存在,因为它们是在您应用插件后创建的。 –

+0

@ lu.koerfer oops他们是错别字。它们实际上都是我的repo中的'shared-utils',我忘了在复制时重命名其中的一些。我已经为第一个例子添加了err消息!谢谢! – nb1q

回答

0

以供将来参考,原来我错过了这条线在android {}块:

publishNonDefault true

+0

如果这可以解决您的问题,请将答案标记为已接受。 –