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

问题描述

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



我正在尝试使用java的Twilio API从uiautomator测试用例发出语音电话,并按照说明提供请访问。我下载了 twilio-java-sdk-3.4.2-with-dependencies.jar twilio-java-sdk-3.4.2.jar



问候,



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.

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不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:42