dart 使用OpenCV构建APK的问题

polhcujo  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(186)

我最近合并了OpenCV SDK for Android,并在调试中运行良好,现在我正试图使用Flutter构建一个APK。
每当我使用flutter build apk --flavor prod命令时,我都会得到错误:

ERROR:C:\Users\Wesley\.gradle\caches\transforms-3\a70cc01f707cb65bbfec9756913c8264\transformed\jetified-opencv_android_module-3.1.0-fix3-runtime.jar: 
R8: Type org.opencv.BuildConfig is defined multiple times: 
C:\Users\Wesley\.gradle\caches\transforms-3\a70cc01f707cb65bbfec9756913c8264\transformed\jetified-opencv_android_module-3.1.0-fix3-runtime.jar:org/opencv/BuildConfig.class, 
C:\Mobile App\Mobile-App\mobile-app\build\sdk\intermediates\runtime_library_classes_jar\prodRelease\classes.jar:org/opencv/BuildConfig.class

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyProdReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete, origin: C:\Users\Wesley\.gradle\caches\transforms-3\a70cc01f707cb65bbfec9756913c8264\transformed\jetified-opencv_android_module-3.1.0-fix3-runtime.jar:org/opencv/BuildConfig.class

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 13s
Running Gradle task 'assembleProdRelease'...                       74.7s
Gradle task assembleProdRelease failed with exit code 1

看到这些文件都在缓存和构建文件夹中,我首先尝试了无效缓存,接下来我尝试删除.gradle文件夹,然后我尝试删除构建文件夹,然后我尝试了这些组合,同时重新同步gradle文件,清理和重建。
我在app/build.gradle中实现了OpenCV sdk,如下所示:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation platform('com.google.firebase:firebase-bom:29.0.4')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation project(path: ':openCV:sdk')
}

我在项目中使用OpenCV对象没有问题,调试时一切正常。我甚至尝试过将我的口味复制到OpenCV build.gradle中,但这没有任何作用。下面是我的buildTypes和flavorites的样子:

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            debuggable false

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            shrinkResources false

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

flavorDimensions "appMode"
    productFlavors {
        qa {
            dimension "appMode"
            //applicationIdSuffix ".debug"
            manifestPlaceholders = [appName: "@string/app_name_qa"]
        }
        prod {
            dimension "appMode"
            manifestPlaceholders = [appName: "@string/app_name"]
        }
    }

我以为我知道如何处理这样的错误,但似乎没有任何工作。

eanckbw9

eanckbw91#

经过进一步的挖掘,我发现我的一个包正在使用OpenCV,因此在构建时不知道从哪里提取引用。我相信有一种方法可以排除从包中提取的内容,但我没有使用该包,所以我只是删除了它。

相关问题