OpenCV 4.1.0 Android SDK无法找到匹配的配置Android Studio

时间:2019-04-15 15:33:17

标签: android gradle android-gradle build.gradle

我正在尝试将OpenCV 4.1.0 Android sdk导入到我的android studio项目中,并获得gradle构建错误(使用OpenCV 4.0.1 Android SDK成功构建)。

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'

1 个答案:

答案 0 :(得分:1)

基于gradle,看来您正在尝试将opencv构建为应用程序。您应将opencv作为模块(库)并包含在您的实际应用中。

有一个将opencv与android集成的指南。 https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c