获取编译错误:package com.twilio.sdk不存在 [英] Getting compile error: package com.twilio.sdk does not exist

查看:189
本文介绍了获取编译错误:package com.twilio.sdk不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的java中的新蜜蜂。
我在ubuntu 12.04机器上。



我正在尝试使用java的Twilio API从uiautomator测试用例发出语音电话,并按照说明提供请访问 https://www.twilio.com/docs/java/install 。我下载了 twilio-java-sdk-3.4.2-with-dependencies.jar twilio-java-sdk-3.4.2.jar http://search.maven.org/#browse|1260284827(预制)。



我在uiautomator java项目中使用Twilio API。我可以构建和运行这个uiautomator java项目,而不实现Twilio API代码。但是,如果我尝试使用Twilio API库,我会收到一个编译时错误,它找不到包



我在做的步骤:



1->打开java项目在eclipse中



2->添加Twilio java库 twilio-java-sdk-3.4.2-with-dependencies.jar OR twilio-java-sdk-3.4.2.jar 通过 BuildPath->配置构建路径 - >添加外部JAR



我有以下代码来测试是否可以使 TwilioRestClient 对象。我有与uiautomator的其他测试功能,他们工作正常没有这段代码。考虑以下方法除了其他测试方法。



test.java

  //假设导入所有其他必需的库
import com.twilio.sdk.TwilioRestClient;

public class testClient extends UiAutomatorTestCase {

public void testMethodGetClient(){
try {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID,AUTH_TOKEN );
log.info(client:+ client.getAccountSid());
} catch(Exception e){
log.info(e.toString());
}
}
}

我没有任何参考在 comiple / build 命令之前的代码中出现错误。要相信,如果我做客户端。,eclipse向我显示了可用于客户端对象的所有方法。那么,我可以在这里假设我的进口是成功的吗?
然后我去终端并执行以下命令创建 build.xml 文件:



ubuntu终端

  $> android创建uitest-project -n JARNAME -t 1 -p&PATH-TO-PROJECT> 
$> ant clean build
构建文件:< PATH-TO-PROJECT> /build.xml

-check-env:
[checkenv] Android SDK工具版本22.3.0
[checkenv]安装在< ANDROID-SDK-PATH>

-pre-clean:

clean:
[删除]删除目录< PATH-TO-PROJECT> / bin

-check-env:
[checkenv] Android SDK工具版本22.3.0
[checkenv]安装于< ANDROID-SDK-PATH>

-build-setup:
[getbuildtools]使用最新的Build Tools:19.0.0
[echo]解决< PACKAGE-NAME> ...的构建目标...
[getuitarget]项目目标:Android 4.2.2
[getuitarget] API级别:17
[echo] ----------
[echo]创建输出目录如果需要,
[mkdir]创建的目录:< PATH-TO-PROJECT> / bin
[mkdir]创建目录:/< PATH-TO-PROJECT> / bin / classes

-pre-compile:

编译:
[javac]将33个源文件编译为< PATH-TO-PROJECT> / bin / classes
[ javac]< PATH-TO-PROJECT> /test.java:15:package com.twilio.sdk不存在
[javac] import com.twilio.sdk.TwilioRestClient;
[javac] ^
[javac]&PATH-TO-PROJECT> /test.java:42:找不到符号
[javac]符号:class TwilioRestClient
[javac ]位置:class< packagename> .Telephony
[javac] TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID,AUTH_TOKEN);
[javac] ^
[javac]&PATH-TO-PROJECT> /test.java:42:找不到符号
[javac]符号:class TwilioRestClient
[javac ]位置:class< packagename> .Telephony
[javac] TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID,AUTH_TOKEN);
[javac] ^
[javac] 3错误

BUILD FAILED
< ANDROID-SDK-PATH> /tools/ant/uibuild.xml:183:编译失败;详细信息请参见编译器错误输出。

总时间:1秒

上述命令将创建.jar如果我没有testMethodGetClient方法。所以,我为$ code> package找不到错误,但大多数建议通过添加外部Jars或提供类路径添加库。我尝试了两个,我得到相同的错误。所以,我来到这里并将其发布为一个新问题。



非常感谢任何帮助。




Rumit

解决方案

bgossit的答案帮助我走正确的方向。但是,这一点还不够。所以,回答我的问题,我自己解释一点额外的步骤,我不得不做。



我的第一个瓶颈被解决了,那就是成功编译项目。但是,我仍然无法在Android设备上运行该项目。我正在将此评论标记为答案,因为问题是针对错误。我为运行时错误提出了一个新问题。



我发现uiautomator的' android创建项目'命令创建一个'$ code'内部调用'< ANDROID_SDK> /sdk/tools/ant/uibuild.xml '来构建项目并创建最终的jar 。默认情况下,这个' uibuild.xml '中的'编译'没有' classpath '被引用为jar。这似乎是Android几个其他StackOverflow问题/答案中提到的错误。



为我工作的解决方案:


  1. 创建' libs '目录与您的'code> src '目录,将外部jar放入' libs '目录中。 注意:这只是一个好习惯。理想情况下,您可以将任何名称添加到libs目录中,并将其放在任何地方。


  2. 添加' classpath '属性转换为< ANDROID_SDK> /sdk/tools/ant/uibuild.xml 编译 $ c>。





 < classpath> ; 
< fileset dir =$ {jar.libs.dir}includes =*。jar/> <! - 到libs的路径 - >
< / classpath>


请注意解决方案用于编译和构建我的项目,我仍然无法在Android设备上运行它,因为Android设备不会具有Twilio API jar。我正在寻找用Twilio jar / classes构建最终项目jar的方法。 软件包com.twilio.sdk的java.lang.ClassNotFoundException



问候,



Rumit


New-bee in java here. I'm on an ubuntu 12.04 machine.

I am trying the Twilio API using java to make voice calls from an uiautomator test case and following the instructions provided at https://www.twilio.com/docs/java/install. I downloaded both twilio-java-sdk-3.4.2-with-dependencies.jar and twilio-java-sdk-3.4.2.jar from http://search.maven.org/#browse|1260284827 (pre-built).

I am using Twilio API in an uiautomator java project. I am able to build and run that uiautomator java project without implementing the Twilio API code. But if I try to use the Twilio API library, I get a compile time errors that it could not find the package.

Steps I'm doing:

1-> Open the java project in eclipse

2-> Add the Twilio java library twilio-java-sdk-3.4.2-with-dependencies.jar OR twilio-java-sdk-3.4.2.jar via BuildPath->Configure Build Path->Add External JARs.

I have following line of code to test if I can make the TwilioRestClient object. I have other test functions with the uiautomator and they work fine without this piece of code. Consider the following method in addition to other test methods.

test.java

//Assume all other required libraries are imported
import com.twilio.sdk.TwilioRestClient;

public class testClient extends UiAutomatorTestCase {   

    public void testMethodGetClient(){
        try{
            TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");
            log.info("client: " + client.getAccountSid());
        }catch(Exception e){
            log.info(e.toString());
        }
    }
}

I do not get any reference errors in my code before the comiple/build command. To believe that, if I do client. ,eclipse shows me all the methods available for the client object. So, can I assume here that my import was successful? Then I go the terminal and execute below command to create the build.xml file:

ubuntu terminal

$> android create uitest-project -n JARNAME -t 1 -p <PATH-TO-PROJECT>
$> ant clean build
Buildfile: <PATH-TO-PROJECT>/build.xml

-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at <ANDROID-SDK-PATH>

-pre-clean:

clean:
   [delete] Deleting directory <PATH-TO-PROJECT>/bin

-check-env:
 [checkenv] Android SDK Tools Revision 22.3.0
 [checkenv] Installed at <ANDROID-SDK-PATH>

-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.0
     [echo] Resolving Build Target for <PACKAGE-NAME>...
[getuitarget] Project Target:   Android 4.2.2
[getuitarget] API level:        17
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: <PATH-TO-PROJECT>/bin
    [mkdir] Created dir: /<PATH-TO-PROJECT>/bin/classes

-pre-compile:

compile:
    [javac] Compiling 33 source files to <PATH-TO-PROJECT>/bin/classes
    [javac] <PATH-TO-PROJECT>/test.java:15: package com.twilio.sdk does not exist
    [javac] import com.twilio.sdk.TwilioRestClient;
    [javac]                      ^
[javac] <PATH-TO-PROJECT>/test.java:42: cannot find symbol
[javac] symbol  : class TwilioRestClient
[javac] location: class <packagename>.Telephony
[javac]             TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");
[javac]             ^
[javac] <PATH-TO-PROJECT>/test.java:42: cannot find symbol
[javac] symbol  : class TwilioRestClient
[javac] location: class <packagename>.Telephony
[javac]             TwilioRestClient client = new TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN");
[javac]                                           ^
    [javac] 3 errors

BUILD FAILED
<ANDROID-SDK-PATH>/tools/ant/uibuild.xml:183: Compile failed; see the compiler error output for details.

Total time: 1 second

The above command would create the .jar if I did not have the testMethodGetClient method. So, I serached for the articals for package not found errors, but most of them suggesting to add the library either via 'Add External Jars' or 'provide the class path'. I tried both and I get the same error. So, I came here and posting it as a new question.

Any help is greatly appreciated.

Regards, Rumit

解决方案

bgossit's answer did help me going to the right direction. However, that alone was not enough. So, answering my question by my self explaining a little extra step I had to do.

My first bottle neck is resolved, that is to compile the project successfully. However, I am still not able to run the project on an Android device. I am marking this comment as an answer as the question was for the complie error. I am puting a new question for the runtime error.

I found that the uiautomator's 'android create project' command creates a 'build.xml' which internally calls '<ANDROID_SDK>/sdk/tools/ant/uibuild.xml' to build the project and create the final jar. By default, the 'compile' target in this 'uibuild.xml' does not have a 'classpath' inlcuded for the jar. This seems to be the bug with Android as mentioned on couple of other StackOverflow questions/answers.

Solution that worked for me:

  1. Create the 'libs' directory at the same level as your 'src' directory and put your external jars into 'libs' directory. Note: This is just a good practice. Ideally you can give any name to the 'libs' directory and put it wherever you want.

  2. Add the 'classpath' attribute to the 'compile' target in <ANDROID_SDK>/sdk/tools/ant/uibuild.xml.

<classpath>
   <fileset dir="${jar.libs.dir}" includes="*.jar" /> <!-- path to 'libs' -->
</classpath>

PLEASE NOTE: Although, above solution worked to compile and build my project, I'm still not able to run it on the Android device as the Android device would not have Twilio API jar. I am looking for the ways to build the final project jar with Twilio jar/classes. java.lang.ClassNotFoundException for package com.twilio.sdk

Regards,

Rumit

这篇关于获取编译错误:package com.twilio.sdk不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆