我在javaandroidstudio中实现了twilio可编程语音呼叫,就像他们在文档中描述的那样,但是在运行时遇到了一些错误
下面是我面临的错误:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:109)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:116)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:58)
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:102)
at com.twilio.Twilio.getRestClient(Twilio.java:122)
at com.twilio.base.Creator.create(Creator.java:45)
at com.systema.twilliovoicecalltest.MakePhoneCall.main(MakePhoneCall.java:33)
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.AppMainV2.main(AppMainV2.java:131)
我试图排除http库,比如
implementation (group: "com.twilio.sdk", name: "twilio", version: "7.34.1")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
implementation (group: "com.sparkjava", name: "spark-core", version: "2.7.1")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
implementation (group: "org.slf4j", name: "slf4j-simple", version: "1.7.21")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
当我尝试上述解决方案时,错误发生了变化:
>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ProtocolVersion
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:102)
at com.twilio.Twilio.getRestClient(Twilio.java:122)
at com.twilio.base.Creator.create(Creator.java:45)
at com.systema.twilliovoicecalltest.MakePhoneCall.main(MakePhoneCall.java:33)
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.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.ClassNotFoundException: org.apache.http.ProtocolVersion
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
以下是我的java代码:
public static void main(String[] args) throws URISyntaxException {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
String from = "+18572632XXX";
String to = "+92**********";
Call call = Call.creator(new PhoneNumber(to), new PhoneNumber(from),
new URI("http://demo.twilio.com/docs/voice.xml")).create();
System.out.println(call.getSid());
}
包括所有必要的库:
>implementation group: "com.twilio.sdk", name: "twilio", version: "7.34.1"</br>
>implementation group: "com.sparkjava", name: "spark-core", version: "2.7.1"</br>
>implementation group: "org.slf4j", name: "slf4j-simple", version: "1.7.21"</br>
因为我在这方面没有太多经验,请帮助我
1条答案
按热度按时间mwyxok5s1#
twilio开发者福音传道者。正如您所注意到的,android在使用javasdk时会遇到麻烦,因为它的一个依赖项是apachelibraryforhttp。不过,你要做的是使用我们的android sdk来打电话。
您可以在这里看到一个如何使用它的示例,也可以通过快速入门了解整个过程。
在您的示例中,您使用的javasdk在应用程序中存在安全问题,因为它现在将您的帐户凭据硬编码到最终的apk中。我在这篇博文中解释了为什么这不是一个好主意。
希望这对你有帮助。