Android Studio和OpenCV“编译错误”,“无法解析可设置样式的符号”

1 android opencv android-studio

我正在使用Android Studio版本3.3和OpenCV版本4.0.1

在android studio中设置openCV后,当我运行该应用程序以检查openCV是否成功加载时,发生错误,提示“编译失败”。我检查了问题,然后看到错误“无法解析符号“可样式化”。

我已经尝试过清洁和重建项目。我还更新了gradle脚本的sdk版本。

这是我的应用程序gradle脚本:


android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.homesafe.test"
        minSdkVersion 21
        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'
        }
    }
    sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
}

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(':openCVLibrary401')
}
Run Code Online (Sandbox Code Playgroud)

这是我的openCV gradle脚本:


android {
    compileSdkVersion 28
    //buildToolsVersion "x.y.z" // not needed since com.android.tools.build:gradle:3.0.0

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['../../jni']
            java.srcDirs = ['src']  // TODO Use original files instead of copied into build directory
            aidl.srcDirs = ['src']
            res.srcDirs = ['/build/master_pack-android/opencv/modules/java/android_sdk/android_gradle_lib/res']
            manifest.srcFile 'AndroidManifest.xml'
        }
    }
}

dependencies {
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我不知道这是什么问题。有什么帮助吗?非常感谢!

goe*_*mic 5

您需要替换以下行:

res.srcDirs = ['/build/master_pack-android/opencv/modules/java/android_sdk/android_gradle_lib/res']
Run Code Online (Sandbox Code Playgroud)

有了这个:

res.srcDirs = ['res']
Run Code Online (Sandbox Code Playgroud)