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
The default location for third party jars is normally the libs folder at the base of your project, i.e. <PATH-TO-PROJECT>.
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:
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.
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
Related
I have a Intellij plugin project that I can successfully build without using the PsiMethod class. I've generated this project using this intellij plugin guide
As soon as I add in code using PsiMethod class
(from the Intellij SDK code_samples directory)
The intellisense cannot find any GOTO information for the class.
I can then switch my project settings module from JAVA_1.8.0 to
by adding it into the platform settings SDKs:
This now adds intellisense, and gives me the ability to navigate to the PsiMethod class by CMD+click.
However, If I try and run my "plugin" gradle configratuion. it halts with an error running :runIde.
Running compileJava command from bash I get:
$ ./gradlew compileJava
> Task :compileJava FAILED
/Users/cody/IdeaProjects/plugintest/src/main/java/com/plugintest/TestClass.java:104: error: cannot find symbol
PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
^
symbol: class PsiMethod
location: class ParticleContainerManager
/Users/cody/IdeaProjects/plugintest/src/main/java/com/plugintest/TestClass.java:104: error: cannot find symbol
PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
^
symbol: class PsiMethod
location: class ParticleContainerManager
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
The gradle source sets in intellij are as follows:
And when I CMD+Click the PsiMethod class, it shows the following JAR source:
This source is in the following parent folder:
How can I add this source into my gradle configuration? shouldn't it be autodetecting what my projects intellisense is tapping into?
Do I need to change something in the gradle.* files inside the project directory?
EDIT:
Using Yann's Answer:
I've added the following line to my build.gradle file:
intellij {
version '2019.2'
plugins 'java'
}
and it works!
Please make sure to add Java plugin as separate dependency. This is now necessary starting with 2019.2: https://blog.jetbrains.com/platform/2019/06/java-functionality-extracted-as-a-plugin/
Setup / Problem
I've create a custom Android module for Titanium to display Gif animations inside Ti. The module source code can be found here:
https://github.com/m1ga/com.miga.gifview
The actual module is working fine but when I use it with a second module (with the same problem) I receive the following error:
java.util.zip.ZipException: duplicate entry:
org/appcelerator/titanium/gen/bindings.json
The problem is inside the gifimageview.jar file:
My two modules each have a bindings.json file inside the /gen folder that contains the same information as the bindings/gifview.json. So if I remove it manually in one module I can use both modules (because there is only one bindings.json now).
Question
How can I advise the compiler not to create this file or change the name? When I compile the module with ant I see this in the output:
compile:
[javac] Compiling 3 source files to /home/miga/dev/ti.gif/android/build/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] Note: [KrollBindingGen] Running Kroll binding generator.
[javac] Note: [KrollBindingGen] Succesfully loaded existing binding data: /home/miga/dev/ti.gif/android/build/classes/org/appcelerator/titanium/gen/bindings.json
[javac] Note: [KrollBindingGen] Found binding for proxy GifView
[javac] Note: [KrollBindingGen] Found binding for module Tigifview
[javac] Note: [KrollBindingGen] Generating JSON: file:/home/miga/dev/ti.gif/android/build/classes/org/appcelerator/titanium/gen/bindings.json
[copy] Copying 1 file to /home/miga/dev/ti.gif/android/build/classes
There it is creating the bindings.json
What I've tried
Adding
org.eclipse.jdt.apt.processorOptions/kroll.jsonFile=migagifview.json
to the settings file: https://github.com/m1ga/com.miga.gifview/blob/master/android/.settings/org.eclipse.jdt.apt.core.prefs
didn't work
My setup
javac -version: javac 1.8.0_91
CLI version 5.0.6
Titanium SDK version 5.2.2.GA
Android-23
This was a confirmed bug and is fixed in 6.1.0
Issue details:
https://jira.appcelerator.org/browse/TIMOB-23502
So, I'm trying to get into LWJGL, and part of this is loading 3D models, and I thought I'd use JAssimp for this. The readme specifies two steps, building a native component, and a .jar component. The jar was just an ant build, and so it happened without incident. The part that's difficult is the native library. I've been trying to link it, without success. I've included the assimp include directories, included Java's headers, and linked to JAssimp's assimp.lib. However, I still get these errors:
jassimp.obj : error LNK2019: unresolved external symbol _aiImportFile referenced in function _Java_jassimp_Jassimp_aiImportFile#20
jassimp.obj : error LNK2019: unresolved external symbol _aiReleaseImport referenced in function _Java_jassimp_Jassimp_aiImportFile#20
jassimp.obj : error LNK2019: unresolved external symbol _aiGetErrorString referenced in function _Java_jassimp_Jassimp_aiImportFile#20
C:\Users\Kevin\Downloads\assimp-3.1.1-win-binaries\port\jassimp\jassimp-native\src\Release\Jassimp.dll : fatal error LNK1120: 3 unresolved externals
Googling around leads to mostly the same question, but with no answers, and one guy on facepunch that apparently found a solution, but pulled an https://xkcd.com/979/ and never mentioned how. Obviously, I've missed linking to some library, but I'm not sure what else to link to, Assimp only provided me one, and I'm not sure what else I need. Am I installing it wrong?
For anyone else who stumbles across this with the same problem, the answer is to do it the old-fashioned way and compile the C++ Assimp yourself. This will give you, (among other things) a new assimp.lib. Link with this instead of the one provided, and the error will go away.
How To Build
I) buiid the primary shared object libassimp.so: issue these commands in AssImp/assimp-3.2
a. cmake CMakeLists.txt -G 'Unix Makefiles'
b. make
c. results in AssImp/assimp-3.2/lib
II) build the native library by issuing this command in jassimp-native/src:
a. $ gcc jassimp.cpp -I/usr/lib/jvm/java-7-openjdk-amd64/include/ \
-I/usr/lib/jvm/java-7-openjdk-amd64/include/linux \
-I/$HOME/AssImp/assimp-3.2/include \
-L/$HOME/AssImp/assimp-3.2/lib/libassimp.so -shared -fPIC -o libjassimp.so
libjassimp.so is required at runtime and must be located in java.library.path:
b. sudo cp /$HOME/AssImp/assimp-3.2/port/jassimp/jassimp-native/src/libjassimp.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/
III) Java binding
The java library is built using ant. Executing "ant" in the port/jassimp
directory should be sufficient to build the library including the docs.
The java build is configured to create java 1.6 classes
The Jassimp.jar file generated by the "ant" call has to be incorporated
in your build.xml file:
<target name="init">
<property name="imports" value="${libs}/jogl-all.jar:${libs}/gluegen-rt.jar:${libs}/jassimp.jar" />
<target name="compile" depends="prepare">
<compilerarg line="-Xlint -cp ${imports}" />
All of the above is the good news; I successfully built my code.
The bad news is that upon execution I received the following error:
java: symbol lookup error: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libjassimp.so: undefined symbol: aiImportFile
I'm on Windows.
I downloaded the source to a java project (Plovr) and I can build it with ant using cygwin.
But just opening it in Eclipse means it will never build again. If I open it in Eclipse and then close it again, it will no longer build. I also can't add files that were written in Eclipse.
Output:
javacc:
compile:
[javac] Compiling 7 source files to C:\Users\Bryana\plovr\pulled\plovr-master\build\classes
[javac] C:\Users\Bryana\plovr\pulled\plovr-master\closure\closure-stylesheets\build\genfiles\java\com\google\common\css\compiler\ast\GssParserCC.java:345: error: cannot access Type
[javac] public CssBooleanExpressionNode buildBoolExpressionNode(CssBooleanExpressionNode.Type type,
[javac] ^
[javac] bad class file: C:\Users\Bryana\plovr\pulled\plovr-master\build\classes\com\google\common\css\compiler\ast\CssBooleanExpressionNode$Type.class
[javac] bad signature: ▒3i
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
BUILD FAILED
Using: jdk1.7.0_40 , Apache Ant(TM) version 1.9.2 , Eclipse Juno Service Release 2
Found this: http://suneelgv.wordpress.com/2011/02/17/java-lang-classformaterror-invalid-constant-pool-index-63-bad-class-file/ referring to that http://mail-archives.apache.org/mod_mbox/cayenne-user/200804.mbox/%3C0JZC008038T159#mail.uni-rostock.de%3E.
In your case the filterset or similar on-the-fly modification during copying - accidentally including class files - might not do any harm with Unix but convert line endings on Windows.
I have a file xxx.proto. I downloaded the protobuf compiler and installed it. Then I issued this command
protoc --java_out=./ xxx.proto
and it generated my xxx.java
Now I want to compile this file into a class file which I can use with Scala.
javac xxx.java
Which gives me this error
xxx.java:7: package com.google.protobuf does not exist
com.google.protobuf.ExtensionRegistry registry) {
^
xxx.java:12450: package com.google.protobuf.Descriptors does not exist
private static com.google.protobuf.Descriptors.Descriptor
^
xxx.java:12453: package com.google.protobuf.GeneratedMessage does not exist
com.google.protobuf.GeneratedMessage.FieldAccessorTable
...
...
...
100 errors
Now I guessed, it doesnt have the package.
So I copied the class files of package com.google.protobuf into the same folder where xxx.java exists. Note - I didnt compile this package. I downloaded the jar from another extension which had the jar files. So I extracted them. Now my current path where xxx.java resides has com/google/protobuf/ *.class of protobuf library.
I issued the javac command again.
This time I got a different set of errors -
xxx.java:10: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:215: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:608: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
^
xxx.java:1017: cannot find symbol
symbol : class MessageOrBuilder
location: package com.google.protobuf
extends com.google.protobuf.MessageOrBuilder {
..... 100 errors
I even tried to compile the source files which came with google protobufs. The generated java classes are giving the same errors.
Any ideas what to do ??
Answer
Okay. Thanks everyone.
The main problem is that protocol buffers compiler package from google doesnt by default create the java library. I assumed that it does and installs it. It actually does if you are running Maven. But i didnt have maven
So i compiled the code in /java/src and used the jar.
^
When compiling, you need to have protobuf lib on your classpath. All those missing packages and classes are from protobuf lib.
Find protobuf jar and use
javac -cp path/to/protobuf.jar xxx.java
You may need to use version 2.4.1 (or 2.4+, at least) of the protobuf kit, including making sure that you update protoc (the protobuf compiler) and recompile your proto definition using the new protoc. (In other words, everything has to be the same version:
the protobuf-vn.n.n.jar file;
the protoc compiler; and
the output of compiling your .proto files with protoc.
One I got everything synched, I began to move forward with a Clojure project I'm looking at. You may be encountering the same version skew problem.
protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto
you can download protoc.exe (new release) from>>.
https://code.google.com/p/protobuf/downloads/detail?name=protoc-2.5.0-win32.zip&can=2&q=
in your *.proto file you correctly config
option java_package = "com.example.package";
option java_outer_classname = "class name";
One can install the protobuf jar file using the ubuntu a
apt-get install libprotobuf-java
This will copy the protobuf-java-2.4.1.jar under /usr/share/java/
Hope this helps