OpenCV 4.1.0 Android SDK 无法找到匹配的配置 Android studio
OpenCV 4.1.0 Android Sdk unable to find a matching configuration Android studio
我正在尝试将 OpenCV 4.1.0 Android sdk 导入到我的 android 工作室项目并出现 gradle 构建错误(使用 OpenCV 4.0.1 [=32= 构建成功] 开发工具包)。
Unable to find a matching variant of project :opencv:
- Variant 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found incompatible 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-runtime' and found incompatible value 'java-api'.
...
这是我的应用 build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ml.nopain.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':opencv')
}
还有我的 opencv build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "org.opencv"
minSdkVersion 15
targetSdkVersion 28
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
}
当我尝试导入 OpenCV 4.0.1 Sdk 时,gradle 构建成功且没有任何错误。
我可以尝试做些什么来解决问题?感谢您的帮助!
解决方案
感谢 Ranjan Kumar,我找到了解决这个问题的方法!只需将 'com.android.application' 更改为 'com.android.library'
根据 gradle 看来您正在尝试将 opencv 构建为应用程序。您应该将 opencv 作为模块(库)并包含在您的实际应用程序中。
有一份将 opencv 与 android 集成的指南。
https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c
我正在尝试将 OpenCV 4.1.0 Android sdk 导入到我的 android 工作室项目并出现 gradle 构建错误(使用 OpenCV 4.0.1 [=32= 构建成功] 开发工具包)。
Unable to find a matching variant of project :opencv:
- Variant 'debugApiElements':
- Required com.android.build.api.attributes.BuildTypeAttr 'release' and found incompatible 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-runtime' and found incompatible value 'java-api'.
...
这是我的应用 build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ml.nopain.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':opencv')
}
还有我的 opencv build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "org.opencv"
minSdkVersion 15
targetSdkVersion 28
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
}
当我尝试导入 OpenCV 4.0.1 Sdk 时,gradle 构建成功且没有任何错误。
我可以尝试做些什么来解决问题?感谢您的帮助!
解决方案 感谢 Ranjan Kumar,我找到了解决这个问题的方法!只需将 'com.android.application' 更改为 'com.android.library'
根据 gradle 看来您正在尝试将 opencv 构建为应用程序。您应该将 opencv 作为模块(库)并包含在您的实际应用程序中。
有一份将 opencv 与 android 集成的指南。 https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c