Android Studio 3.2. Когда buildType = release -> Error: commons-logging определяет классы, которые конфликтуют с классами, которые теперь предоставляются Android

Android Studio 3.2

В моем проекте / app.build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'

В моем приложении / build.gradle

apply plugin: 'com.android.application'

def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(rootProject.file("app/keystore.properties")))

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 421
        versionName "2.1.421"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        // to fix problem when annotation not build on release
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ['resourcePackageName': "com.myproject"]
            }
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['KEY_ALIAS_RELEASE']
            keyPassword keystoreProperties['KEY_PASSWORD_RELEASE']
            storeFile file(keystoreProperties['STORE_FILE_RELEASE'])
            storePassword keystoreProperties['STORE_PASSWORD_RELEASE']
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            configBuildType(delegate, "Release instance name", "Release app name", "beta")
            signingConfig signingConfigs.release

        }
        debug {
            configBuildType(delegate, "Debug name instance", "Debug name, null)

            ext.betaDistributionReleaseNotes = defaultConfig.versionName + " " + name
            ext.betaDistributionEmailsFilePath = "app/beta_distribution_emails.txt"
        }
    } 
}

def configBuildType(buildType, instanceName, appName, appIdSuffix) {   
    buildType.resValue("string", "app_name", appName)
    buildType.applicationIdSuffix(appIdSuffix)
    buildType.buildConfigField("String", "INSTANCE_NAME", instanceName)
}
// must be version 4.5.2
def AAVersion = '4.5.2'

dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    annotationProcessor "org.androidannotations:ormlite:$AAVersion"

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:exifinterface:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'org.apache.httpcomponents:httpclient:4.5.6'
    // https://mvnrepository.com/artifact/commons-codec/commons-codec
    implementation group: 'commons-codec', name: 'commons-codec', version: '1.11'

    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.j256.ormlite:ormlite-android:5.1'
    implementation 'commons-io:commons-io:2.6'
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
    implementation "org.androidannotations:ormlite-api:$AAVersion"   

    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'
}

При buildType = debug проект успешно соберется и запустится. Хороший. Но когда buildType = release я получаю ошибку:

:app:compileReleaseSources
:app:lintVitalReleaseD:\myproject\app: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
D:\myproject\app: Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

   Explanation for issues of type "DuplicatePlatformClasses":
   There are a number of libraries that duplicate not just functionality of
   the Android platform but using the exact same class names as the ones
   provided in Android -- for example the apache http classes. This can lead
   to unexpected crashes.

   To solve this, you need to either find a newer version of the library which
   no longer has this problem, or to repackage the library (and all of its
   dependencies) using something like the jarjar tool, or finally, rewriting
   the code to use different APIs (for example, for http code, consider using
   HttpUrlConnection or a library like okhttp).

2 errors, 0 warnings
 FAILED

FAILURE: Build failed with an exception.
Стоит ли изучать PHP в 2023-2024 годах?
Стоит ли изучать PHP в 2023-2024 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
Поведение ключевого слова "this" в стрелочной функции в сравнении с нормальной функцией
В JavaScript одним из самых запутанных понятий является поведение ключевого слова "this" в стрелочной и обычной функциях.
Приемы CSS-макетирования - floats и Flexbox
Приемы CSS-макетирования - floats и Flexbox
Здравствуйте, друзья-студенты! Готовы совершенствовать свои навыки веб-дизайна? Сегодня в нашем путешествии мы рассмотрим приемы CSS-верстки - в...
Тестирование функциональных ngrx-эффектов в Angular 16 с помощью Jest
В системе управления состояниями ngrx, совместимой с Angular 16, появились функциональные эффекты. Это здорово и делает код определенно легче для...
Концепция локализации и ее применение в приложениях React ⚡️
Концепция локализации и ее применение в приложениях React ⚡️
Локализация - это процесс адаптации приложения к различным языкам и культурным требованиям. Это позволяет пользователям получить опыт, соответствующий...
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
0
0
295
1

Ответы 1

Добавьте в свое приложение / build.gradle

configurations {
    all {
        exclude module: 'commons-logging'
    }
}

Другие вопросы по теме