调试风味变体如何取决于发行代码

时间:2018-11-08 19:56:51

标签: android android-gradle

我正在发布一个多模块Android库。用例是我想针对我的库的发布AAR(受保护的)运行示例应用程序(处于调试状态)。最终目标是能够测试将要发布的确切工件。

我的模块及其所需的构建类型为:

:my-library (release)
:mock-server (debug)
:sample (debug)

:sample取决于:my-library:mock-server:mock-server也取决于:my-library

为此,我设置了一个味觉维度:

android {
  flavorDimensions "SOURCE_OR_BINARY"

  productFlavors {
    source {
      // indicates that project dependencies are used directly
    }
    binary {
      // dependencies added via here will be AARs
    }
}

dependencies{
  binaryImplementation(name: ':my-library', ext: 'aar')
  sourceImplementation project(':my-library')
  implementation project(':mock-server')
}

task prepareBinaryDependencies(dependsOn: [
        ":my-library:assembleRelease" // to generate AARs
]) {}

//
tasks.whenTaskAdded { task ->
    def taskName = task.name.toLowerCase()
    if (taskName.toLowerCase().contains("binary")) {
        // Prepare libs as binaries
        task.dependsOn prepareBinaryDependencies
        task.doFirst {
            prepareBinaryDependencies
        }
    }
}

这在命令行上与./gradlew一起正常工作,但是Android Studio通常在gradle同步期间报告Failed to resolve: :my-library-release:。如果我在命令行上执行./gradlew assemble然后同步Android Studio,则AS Gradle同步成功。

看来我在这里做错了。有没有更好的方法可以避免Failed to resolve Android Studio Gradle同步错误?

0 个答案:

没有答案