【问题标题】:ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project: Add app module to android application错误:无法解析“:app@debug/compileClasspath”的依赖关系:无法解析项目:将应用模块添加到android应用程序
【发布时间】:2019-12-16 12:01:50
【问题描述】:

我创建了一个 android 应用程序并希望将其作为模块添加到其他应用程序。我尝试使用以下方法导入应用程序:文件->新建->导入模块->(浏览要导入的应用程序)->(更改模块名称)->完成

导入应用程序后发生以下变化:

setting.gradle

import ':app'
import ':ocr'

build.gradle(Module:app)

implementation project(path: ':ocr')

模块被添加到项目中。

但是当我尝试 sync 项目时,它显示以下错误:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :ocr.
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :ocr.
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :ocr.
ERROR: Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :ocr.
ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :ocr.

我试图四处寻找问题,但无法解决。谁能告诉问题出在哪里或如何解决?

【问题讨论】:

  • 确保 ocr 模块中的 build.gradle 有“apply plugin: 'com.android.library'”而不是“apply plugin: 'com.android.application'”
  • 是的,我更改了“应用插件:'com.android.library'”而不是“应用插件:'com.android.application'”,但它引发另一个错误为错误:原因:java。 lang.NullPointerException。因为我使用的是firebase ocr,所以我需要在设置中添加“应用插件:'com.google.gms.google-services'”和“类路径'com.google.gms:google-services:4.2.0'”,gradle

标签: android android-gradle-plugin build.gradle android-module


【解决方案1】:

解决方案:

official migration guide中所述,遇到此错误时:

您的应用包含库依赖项不包含的构建类型

android {
  buildTypes {
      release {
          ...
      }
      dexOptions {
          ...
        // release & debug is in project ocr
        matchingFallbacks = ['release', 'debug']
      }
      debug {
          ...
      }
    }
}

【讨论】:

    猜你喜欢
    • 2018-06-26
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多