我有一个依赖于子项目B(aauto-sdk)的现有项目A。 B以前是使用某种魔术来构建的,该魔术可以从github下载并执行Right Thing,但是默认的github项目不再可用,我必须使用较旧的版本。考虑上游不起作用。我决定将项目克隆到其自己的目录中,然后将该项目目录添加为模块(like this)。这个想法只是将项目B的已知工作状态复制到项目A的文件树中,从而避免了使项目A与无法预测的github项目保持同步。
到那时,我会收到如下构建错误消息:
构建输出
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:releaseCompileClasspath'.
> Could not resolve project :aauto-sdk.
Required by:
project :app
> Unable to find a matching configuration of project :aauto-sdk: None of the consumable configurations have attributes.
它带有如下所示的同步错误:
同步
CONFIGURE SUCCESSFUL in 1s
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :aauto-sdk.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :aauto-sdk.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :aauto-sdk.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :aauto-sdk.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :aauto-sdk.
Show Details
Affected Modules: app
经过大量的搜索,我意识到此子项目可能在某些方面有些不寻常:
buildTypes
定义,而主项目模块定义了release
构建类型,这似乎导致了上述错误。publishing
部分,它可以完成许多Maven任务。因此子项目build.gradle具有以下行:
$ PROJECT_DIR / aauto-sdk / build.gradle
...
task buildAar(dependsOn: [collectResources, makePublicTxt, buildJar,
makeProguardTxt], type: Zip) {
from outDir
include 'AndroidManifest.xml', 'R.txt', 'public.txt', 'proguard.txt',
'classes.jar', 'res/**'
archiveName 'aauto.aar'
destinationDir buildDir
}
task clean {
doLast {
delete buildDir
}
}
task build(dependsOn: buildAar)
...
我怀疑,如果我可以让Gradle在适当的时候在子项目的build.gradle中执行build
任务,然后让我的根项目使用生成的.aar文件,那可能就很好了。也许。我希望。
以下是我的根项目的当前模块级build.gradle文件中的一些相关摘录:
$ PROJECT_DIR / app / build.gradle
android {
...
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.google.android.kk"
minSdkVersion 16
targetSdkVersion 28
versionCode 38
versionName "2.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
flatDir {
dirs 'libs'
}
jcenter()
google()
repositories {
maven {
url "https://jitpack.io"
}
}
}
...
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:5.11.0"
}
}
dependencies {
...
implementation project(path: ':aauto-sdk')
...
}
implementation project(path: ':aauto-sdk')
行似乎不足。我该如何进行这项工作?
如果您需要更详细的代码或重现问题的能力,则此处的github repo and branch与上面的代码相对应。