Сбой выполнения для задачи ‘: checkDebugDuplicateClasses’. Androidx и jetified оба включены, но по-прежнему получают ошибки

#java #android #gradle

#java #Android #gradle

Вопрос:

Как указано в названии, я получаю повторяющиеся ошибки класса при попытке реализовать dialogfragments. Следующая реализация вызывает ошибки, но это необходимая реализация для импорта фрагмента диалогового окна.

 implementation 'androidx.legacy:legacy-support-v4:1.0.0'
 
 java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.support.v4.media.MediaBrowserCompat found in modules jetified-main.jar (main.jar) and media-1.0.0-runtime.jar (androidx.media:media:1.0.0)
  Duplicate class android.support.v4.media.MediaBrowserCompat$CallbackHandler found in modules jetified-main.jar (main.jar) and media-1.0.0-runtime.jar (androidx.media:media:1.0.0)
  Duplicate class android.support.v4.media.MediaBrowserCompat$ConnectionCallback found in modules jetified-main.jar (main.jar) and media-1.0.0-runtime.jar (androidx.media:media:1.0.0)
  Duplicate class android.support.v4.media.MediaBrowserCompat$ConnectionCallback$ConnectionCallbackInternal found in modules jetified-main.jar (main.jar) and media-1.0.0-runtime.jar (androidx.media:media:1.0.0)
 

Большинство других подобных проблем решаются путем установки

 android.useAndroidX=true
android.enableJetifier=true
 

в файле gradle.properties. Тем не менее, я уже перешел на androidx и установил для обоих из них значение true, и моя проблема сохраняется.

Мой build.gradle

 // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
//        mavenCental()
//        maven {
//            url 'https://jitpack.io'
//        }
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

apply plugin: 'com.android.application'
apply plugin: 'idea'

dependencies {
    //for android rest
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'org.json:json:20160212'

    // may be empty used by the autobuilder
    //implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    //implementation 'androidx.appcompat:appcompat:1.0.0'
    compileOnly fileTree(dir: '../../ATAK/libs', include: '*.jar')
    compileOnly fileTree(dir: '../../ATAK/build/libs', include: '*.jar')
    compileOnly fileTree(dir: '../../MapCoreInterfaces/build/libs', include: '*.jar')
    compileOnly fileTree(dir: '../../ATAKMapEngine/build/libs', include: '*.jar')
    compileOnly fileTree(dir: '../../ATAKMapEngine/libs', include: '*.jar')

    // strictly for the plugin sdk
    compileOnly fileTree(dir: '../..', include: '*.jar')


    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    //implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.loopj.android:android-async-http:1.4.9'

}

def getSvnRevision() {
    new ByteArrayOutputStream().withStream { os ->
        def result = exec {
            executable = 'svn'
            args = ['info']
            standardOutput = os
            ignoreExitValue = true
        }
        def outputAsString = os.toString()
        def matchLastChangedRev = outputAsString =~ /Revision: (d )/
        def length = matchLastChangedRev.size()
        if (length > 0)
            ext.svnRev = "${matchLastChangedRev[0][1]}".toInteger()
        else
            ext.svnRev = 1
    }

    return svnRev
}

android {
    compileSdkVersion 28
    buildToolsVersion '29.0.2'

    dexOptions {
        jumboMode = true
    }

    lintOptions {
        checkReleaseBuilds true
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }


    signingConfigs {
        debug {
            storeFile file("android_keystore")
            storePassword "tnttnt"
            keyAlias "wintec_mapping"
            keyPassword "tnttnt"
        }

        release {
            storeFile file("android_keystore")
            storePassword "tnttnt"
            keyAlias "wintec_mapping"
            keyPassword "tnttnt"
        }
    }


    buildTypes {
        release {
            System.setProperty("atak.proguard.mapping", "../../ATAK/build/outputs/mapping/release/mapping.txt")
            minifyEnabled true
            proguardFile 'proguard-gradle.txt'
            signingConfig signingConfigs.release
        }
    }
    packagingOptions {
        exclude 'META-INF/INDEX.LIST'
    }

    sourceSets {
        main {
            defaultConfig.versionCode = getSvnRevision()
            defaultConfig.versionName = getSvnRevision()
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']


        }

        // Move the tests to tests/java, tests/res, etc...
        //instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')

    }

    defaultConfig {
        minSdkVersion 28
    }


}

//task clean(type: Delete) {
//    delete rootProject.buildDir
//}
 

Комментарии:

1. Попробуйте аннулировать кэш, перезапустить чистый проект, перестроить проект

2. Не повезло. Что-нибудь еще, что я должен попробовать?