In my Android application, I have both imported the OpenCV library, as well as integrated a live edge detection library, which in turn uses OpenCV on its own. Originally, this created a conflict between the two versions of OpenCV, but I was able to resolve that.
I am now trying to do a production release for the first time since this change, and I am encountering the following error during my release build (in the mergeDex...Release stage):
Type org.opencv.calib3d.Calib3d is defined multiple times: .../OpenCVSDK/build/.transforms/73aaad4d2991f9ad7ec3aa9b43023dc9/transformed/release/org/opencv/calib3d/Calib3d.dex, .../app/build/intermediates/external_libs_dex/prodSbirRelease/mergeExtDexProdSbirRelease/classes3.dex
Why is this suddenly an issue now, with a release build, when it was (and continues to be) fine with debug builds? And how can I fix it?
Here is my app build.gradle:
plugins {
id 'com.android.application'
id 'com.google.android.gms.oss-licenses-plugin'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
signingConfigs {
debug {
storeFile file('.../ReleaseKeyStore')
storePassword '...'
keyAlias 'key0'
keyPassword '...'
}
release {
storeFile file('.../ReleaseKeyStore')
storePassword '...'
keyAlias 'key0'
keyPassword '...'
}
}
compileSdk 31
defaultConfig {
minSdk 26
targetSdk 31
versionCode 3
versionName "0.9.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
// Based on https://www.geeksforgeeks.org/how-to-change-the-default-generated-apk-name-in-android-studio/
// and https://stackoverflow.com/questions/25104323/how-to-customize-the-apk-file-name-for-product-flavors
applicationVariants.all{
variant ->
variant.outputs.each{
output->
def name = "ImageCapture-${variant.flavorName}-${variant.versionName}.apk"
output.outputFileName = name
}
}
}
flavorDimensions "environment", "product"
productFlavors {
local {
dimension "environment"
resValue "string", "app_name", "LOCAL Image Capture"
}
dev {
dimension "environment"
resValue "string", "app_name", "DEV Image Capture"
}
prod {
dimension "environment"
resValue "string", "app_name", "Image Capture"
}
sbir {
dimension "product"
}
nci {
dimension "product"
}
}
androidComponents {
onVariants(selector().all(), { variant ->
switch (variant.name) {
case "localSbirDebug":
case "devSbirDebug":
case "localSbirRelease":
case "devSbirRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.dev"
break
case "prodSbirDebug":
case "prodSbirRelease":
variant.applicationId = "ai.dlanalytics.imagecapture"
break
case "localNciDebug":
case "devNciDebug":
case "localNciRelease":
case "devNciRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.nci.dev"
break
case "prodNciDebug":
case "prodNciRelease":
variant.applicationId = "ai.dlanalytics.imagecapture.nci"
break
}
})
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst '**/*.so'
resources {
excludes += ['META-INF/DEPENDENCIES', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/license.txt', 'META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/notice.txt', 'META-INF/ASL2.0', 'META-INF/*.kotlin_module']
}
}
buildFeatures {
viewBinding true
mlModelBinding true
}
namespace 'ai.dlanalytics.imagecapture'
}
dependencies {
implementation 'com.github.adityaarora1:LiveEdgeDetection:master-SNAPSHOT'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.activity:activity:1.4.0"
implementation "androidx.fragment:fragment:1.4.1"
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation "com.google.android.gms:play-services-location:19.0.1"
implementation 'com.google.api-client:google-api-client:1.32.2'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.android.volley:volley:1.2.1'
implementation 'androidx.navigation:navigation-fragment:2.4.2'
implementation 'androidx.navigation:navigation-ui:2.4.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.camera:camera-camera2:1.2.0-alpha01"
implementation "androidx.camera:camera-lifecycle:1.2.0-alpha01"
implementation "androidx.camera:camera-view:1.2.0-alpha01"
implementation "androidx.camera:camera-extensions:1.2.0-alpha01"
implementation "com.github.bumptech.glide:glide:4.11.0"
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation platform('com.google.firebase:firebase-bom:30.0.1')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
implementation "androidx.work:work-runtime:2.7.1"
implementation project(path: ':OpenCVSDK')
// implementation 'org.bytedeco:opencv:4.5.5-1.5.7'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-ml-modeldownloader'
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
And my project build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "https://www.jitpack.io" }
google() // Google's Maven repository
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
}
}
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://www.jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I'm relatively new to Android builds, so please let me know what other helpful information I can provide.