代码之家  ›  专栏  ›  技术社区  ›  Mon

Apache http客户端Android库的Android问题

  •  0
  • Mon  · 技术社区  · 8 年前

    这是我正在使用的库: https://github.com/clickntap/Vimeo

    这是我的gradle配置:

    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    useLibrary  'org.apache.http.legacy'
    
    defaultConfig {
        applicationId "my.app.package"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.0-alpha"
    }
    

    以下是我添加库的方式:

    compile 'com.clickntap:vimeo:1.10'
    

    但我在上收到以下错误 Vimeo.addVideo()

    java.lang.NoClassDefFoundError: org.apache.http.impl.client.HttpClientBuilder
    

    WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for debug as it may be conflicting with the internal version provided by Android.
    WARNING: Dependency org.json:json:20140107 is ignored for debug as it may be conflicting with the internal version provided by Android.
    

    所以我搜索了一下,发现我可以做这样的事情:

    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile('com.clickntap:vimeo:1.10') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'org.json'
    }
    

    但现在我收到这个错误仍然存在 维梅奥。添加视频()

    java.lang.NoSuchMethodError: org.apache.http.entity.FileEntity.<init>
    

    请帮助:(

    附笔。 下面是第一个场景的堆栈跟踪:

    Caused by: java.lang.NoClassDefFoundError: org.apache.http.impl.client.HttpClientBuilder
                    at com.clickntap.vimeo.Vimeo.apiRequest(Vimeo.java:218)
                    at com.clickntap.vimeo.Vimeo.beginUploadVideo(Vimeo.java:122)
                    at com.clickntap.vimeo.Vimeo.addVideo(Vimeo.java:138)
                    at my.app.package.VimeoActivity$6.subscribe(VimeoActivity.java:163) // my activity
                    at io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
                    at io.reactivex.Single.subscribe(Single.java:2702)
                    at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
                    at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:451)
                    at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
                    at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52) 
                    at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                    at java.lang.Thread.run(Thread.java:841) 
    

    这是第二个场景,其中 httpclient-android

    Caused by: java.lang.NoSuchMethodError: org.apache.http.entity.FileEntity.<init>
                    at com.clickntap.vimeo.Vimeo.apiRequest(Vimeo.java:247)
                    at com.clickntap.vimeo.Vimeo.uploadVideo(Vimeo.java:126)
                    at com.clickntap.vimeo.Vimeo.addVideo(Vimeo.java:140)
                    at my.app.package.VimeoActivity$6.subscribe(VimeoActivity.java:163) // my activity
                    at io.reactivex.internal.operators.single.SingleCreate.subscribeActual(SingleCreate.java:39)
                    at io.reactivex.Single.subscribe(Single.java:2702)
                    at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
                    at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:451)
                    at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
                    at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52) 
                    at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
                    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                    at java.lang.Thread.run(Thread.java:841) 
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   Ioannis Sermetziadis    8 年前

    Android版本<6嵌入了Apache HTTP Client 4.0的分支。测试版快照( https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

    HttpClientBuilder 在httpclient:4.3上引入。

    useLibrary 'org.apache.http.legacy' 加载旧的httpclient库 compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'

    我建议使用第二种场景中的依赖项,但删除 使用图书馆组织。阿帕奇。http。传统' .

    httpcomponents:httpclient

    使现代化

    如果您的代码或任何依赖项明确使用httpclient android库中已替换的API,以避免与android SDK的旧版httpclient版本冲突,则此解决方案将无法工作。

    在上面的示例中,Vimeo库直接使用 FileEntity EntityBuilder 已使用。所以我能看到的唯一方法是修改库源代码,使其与httpclient android库和一般android兼容。