Gradle org.apache.http库的重复类

u3r8eeie  于 2022-11-14  发布在  Apache
关注(0)|答案(1)|浏览(201)

在使用Apache http类构建我的gradle时,我遇到了重复类错误。以下是我遇到的一些错误:

Duplicate class org.apache.http.HttpHeaders found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.TruncatedChunkException found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.annotation.GuardedBy found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.annotation.Immutable found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.annotation.NotThreadSafe found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.annotation.ThreadSafe found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.auth.ContextAwareAuthScheme found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.AuthCache found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.RedirectStrategy found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.entity.DecompressingEntity found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.entity.DeflateDecompressingEntity found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.entity.GzipDecompressingEntity found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.protocol.RequestAcceptEncoding found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.protocol.RequestAuthCache found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.protocol.RequestClientConnControl found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.protocol.ResponseContentEncoding found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.utils.Idn found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.utils.JdkIdn found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.utils.Punycode found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.client.utils.Rfc3492Idn found in modules jetified-httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient-android:4.3.5.1) and jetified-org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2.jar (org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2)
Duplicate class org.apache.http.conn.HttpRoutedConnection found in modules jetified-httpclient-android-4.3.5.1.jar

这是我的成绩单:

android {
            compileSdkVersion 30
            buildToolsVersion "30.0.2"
            useLibrary 'org.apache.http.legacy'
        
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
        
            dexOptions {
                javaMaxHeapSize "4g"
            }

            ...
         defaultConfig {
            applicationId "com.myapp.android"
            //Oreo 8.0
            minSdkVersion 26
            // Android 11
            targetSdkVersion 30
}
        
            ...
        }
        
        dependencies {
            ...
            implementation ('org.apache.httpcomponents:httpclient-android:4.3.5.1') {
                exclude group: 'org.apache.http'
            }
            implementation('org.apache.httpcomponents:httpmime:4.3') {
                exclude group: 'org.apache.httpcomponents', module: 'httpclient'
             ...
            }
           
    implementation'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
        }

我需要访问以下类:HttpMultipartMode, MultipartEntityBuilder, ContentType, HttpPost, HttpRequestBase, HttpUriRequest。这就是为什么这个库的组合适合我。但是它在设备上运行之前就失败了。感谢任何支持!

h9a6wy2h

h9a6wy2h1#

用这个

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 23
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.5.0'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    
    implementation 'org.apache.httpcomponents:httpclient:4.2.6'
    implementation 'org.apache.httpcomponents:httpmime:4.5.6'
}

相关问题