我正在尝试使用this逐步指南将OpenCV包含在我的Android Studio项目中。但是,将OpenCV添加为模块依赖项(指南中的第4步)后,Gradle项目同步失败,并出现以下错误:
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :openCVLibrary410.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :openCVLibrary410.
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :openCVLibrary410.
Show Details
Affected Modules: app
我发现this related question,并尝试通过添加调试字段来调整openCV build.gradle中的buildType,但是它没有任何改变。我还尝试如下调整应用程序的build.gradle
buildTypes {
release {
...
}
debug {
matchingFallbacks = ['release']
}
}
(和几个与此稍有不同的版本,因为我不确定我在那儿做什么),但没有一个帮助。我还尝试将OpenCV库的构建变体设置为发布而不是调试,但这会导致以下错误:
Unable to find a matching variant of project :openCVLibrary410:
- Variant 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Variant 'debugBundleElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-api' and found incompatible value 'android-bundle'.
- Variant 'debugMetadataElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
- Required org.gradle.usage 'java-api' but no value provided.
- Variant 'debugRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
- Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.
- Variant 'releaseApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
- Variant 'releaseBundleElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
- Required org.gradle.usage 'java-api' and found incompatible value 'android-bundle'.
- Variant 'releaseMetadataElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Metadata'.
- Required org.gradle.usage 'java-api' but no value provided.
- Variant 'releaseRuntimeElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'release'.
- Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required.
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found incompatible value 'Apk'.
- Required org.gradle.usage 'java-api' and found incompatible value 'java-runtime'.
有什么办法解决这个问题吗?
答案 0 :(得分:4)
我终于通过更改行来解决了这个问题
apply plugin: 'com.android.application'
在导入的OpenCV模块的build.gradle文件中
apply plugin: 'com.android.library'
并删除同一gradle文件中的defaultConfig字段。 我找到了此解决方案here。
答案 1 :(得分:0)
导入版本3.4.6比最新版本稍旧。 最新版本可能尚未稳定。
在我的环境中出现了相同的症状,但是使用3.4.6版本已解决。