簡體   English   中英

Android應用程式上缺少org / apache / http / client / methods / HttpUriRequest

[英]Missing org/apache/http/client/methods/HttpUriRequest on Android app

我正在嘗試從我的Android應用程序使用Telegrambot(由於某些項目要求,使用4.4)。 我實現了一個簡單的機器人,但是當我嘗試運行它時,出現以下錯誤:

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest

    at com.mypackage.Model.communication.remote.telegram.TelegramBotTest.initialize(TelegramBotTest.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

我嘗試過

compile 'org.apache.httpcomponents:httpclient-android:4.3.3'

但沒有成功。 我必須包括什么適當的依賴項? 這些是我為支持電報而包含的依賴項:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.6'
compile 'org.telegram:telegrambots:2.4.4.5'

-更新:我也收到以下警告:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
Warning:WARNING: Dependency org.json:json:20160810 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160810 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.3 is ignored for release as it may be conflicting with the internal version provided by Android.

我已經用這種方式解決了。 在依賴項上,我添加了以下內容:

// *** Telegram dependencies ***
compile 'org.json:org.json:chargebee-1.0'
compile 'org.apache.httpcomponents:httpcore:4.4.6'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile files('libs/commons-logging-1.2.jar')    
compile "org.telegram:telegrambots:3.3"

在android部分中,我添加了以下內容:

configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
    compile.exclude group: "commons-logging", module: "commons-logging"
}

現在,我可以在沒有運行時異常的情況下執行TelegramBot代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM