how to include sqlite4java in android project - java

I am trying to use sqlite4java in my android project. the following screenshot shows my project's setup:
As you can see i have copied the jar-file into my libs folder and included it in the build path. I have also copied the docs and the src-file as per the docs for sqlite4java. The zip-file i downloaded also contains a library-file called libsqlite4java-android-i686.sothat i included in the libs directory. what i get when i try to run my project (it will compile without complaining) is the follwing error message:
03-04 07:37:13.251: W/System.err(2419):
com.almworks.sqlite4java.SQLiteException: [-91] cannot load library:
java.lang.UnsatisfiedLinkError: Couldn't load sqlite4java-android-i686
from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data
/app/de.redhouse24.android-2.apk"],nativeLibraryDirectories=[/data
/app-lib/de.redhouse24.android-2, /system/lib]]]: findLibrary returned
null
As you can see the file sqlite4java-android-i686.socannot be found. Being wiley, i renamed the libsqlite4java-andriod-i686.so file to sqlite4java-android-i686.so, which is why my project structure shows that name for the file. TBH, i renamed it because i found the suggestion in this discussion:
https://code.google.com/p/sqlite4java/issues/detail?id=42
I also tried to include the so-file in the build path, but that just stopped my project from compiling.
My question: What do i need to do to use sqlite4java in my android project?
Im using a mac and eclipse with adt, if that makes any difference.

First of all, renaming the library will not help you. Do not rename the library, leave the name as it was.
Second, you only have the 686-lib there.
If you intent to run your app on something other than an atom-based device, you will have to add the so-files for the other architectures as well.
Each architecture's so-files resides in a sub-directory under the libs directory, like this:
libs/x86
libs/armeabi
libs/armeabi-v7a
Put your libsqlite4java-android-i686.so file there, and also possible other .so files it might need as a dependency, and it should work.
Including the sources and docs into the libs-folder somewhat eludes me. That will only bloat your final apk file, which should be avoided.
Your users will be thankful.

Related

Export to JAR with external JavaPOS Files

I've currently finished my project, but can't get it to work when it is exported. I use JAXB to read and write XML Files and also have dependencies on other external Folders, which are needed to use a POS-Printer.
I've managed to link my external XML Save-Files with absolute paths, but not with relative paths. So that worked, although not the way i wanted. Yet, using the external class folder for the printer didn't work at all.
This means, that in my Eclipse Project Build Path i've added a class folder, which contains all of these needed files (which are not only jars, so adding them one by one wouldnt work). So exporting my project to a jar either includes all the files into the jar itself, or doesnt include them at all.
Everything works perfectly in Eclipse, but not when i export it.
My folder structure looks like this:
src
/model
/view
/control
data
/articles.xml
/...
JavaPOS <--- needed folder with all its files
/jpos.xml
/xerxers.jar
/swt-..-.dll
I've tried:
InputStreams is = getClass().getResourceAsStream(url);
absolute paths
manipulating the manifest file and/or jar structure
runnable and non runnable jars with nearly every combination of options
putting the files inside the library "by hand"
changing the build path of the project
My Question is:
How do i get my jar-file to know where these files are?
EDIT:
Do you think Maven or an Ant file could solve my problems? I don't have any experience with those.
The Problem was, that i had more than one JRE installed and that the one eclipse was using, had all the dll files, but the other ones didnt have it. So i had to add them manually, because reinstalling the drivers of the printer didnt change anything. Gotta fix that somehow, but right now it works and that is all i wanted.
Turns out i didn't even need that Folder, just needed one file out of it and the missing dlls.

UnsatisfiedLinkError, but library is in path

I'm a little confused by this error. I'm new to Java and the error seems pretty self explanatory, but I've checked my paths (even defined my own) and it still fails to find this library. Is there something I'm doing wrong? See directory screenshot and error screenshot below:
UPDATE
UPDATE 2
If I create a new NetBeans project this works fine. Same code and everything. If I create new IntelliJ project I get this error above. I must be missing something in IntelliJ
UPDATE 3
Found the solution. Adding dependencies is a bit different in IntelliJ. Thanks all for the help.
http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html
Obidisc4j is a .jar file. You just dont see its extension in the explorer.
Regular jar files are not loaded by System.loadLibrary. They are automatically loaded by the JVM's classLoader.
You are using a native library. It doen't matter if that library is in the classpath. There are 4 ways you can make the Java runtime load your shared library at runtime:
Call System.load to load the .so from an explicitly specified absolute path.
Copy the shared library to one of the paths already listed in java.library.path
Modify the LD_LIBRARY_PATH environment variable to include the directory where the shared library is located.
Specify the java.library.path on the command line by using the -D option.
Seems like your application is trying to find out a obidisc4j.dll (for Windows) or obidisc4j.so (for Linux). The file must be present on the PATH (but not the classpath). If you are not sure what PATH is your Java application searching in, you can write the following statement, before the point where the exception takes place, to find out the PATH.
System.out.println(System.getProperty("java.library.path"));
This will tell you about the paths where your DLL or SO file should be placed. You just need to place the file in ONE of those N-paths.

Intellij Idea can't find class files from other source

I added a module to my project and marked its source file as a source. It does not show any errors in code by when I compile and run it it can't finds other module's class files
Caused by: java.lang.ClassNotFoundException: com.nabu.bloodworks.models.PlayerPosModel
Problem is it does not add path of .class files to class path. Why this happens? When I google it all I get is "mark src as source folder" and I already did that.
I am trying to use "Bloodworks" module both in my server and client. Server is a simple java server and it works as intended, can see and import bloodworks but client can't see it. Client is a libgdx application and I am trying to run desktop module. As you can see bloodworks/src is marked as blue and I added it to dependincies, am I missing something?
I suppose you should check export (for your module).
Otherwise desktop project won't be able to access that module after building.
Good luck.
I'm sure, it is too late to answer, but I had to follow a different approach for this error to resolve this issue. Simply exporting the jar or library didn't work for me.
I had to create this as global library and add that library to the module, then only the error is resolved. I didn't have to export this.

jsr305_annotations Folder inside apk file

I've had reports of problems with the installation of the apk.
I tried to extract the apk as a zip file and I found the folder
jsr305_annotations in the root APK
with inside
folder: v0_r47 -> file: V0_r47.gwt.xml
File: Jsr305_annotations.gwt.xml
I would like information about those files and folders and a method to make sure that they are not included in my applications
thanks
Using
Eclipse
Version: 3.8.2
Build id: M20130131-0800
Android Development Toolkit
Version: 22.0.1.v201305230001--685705
I'd seen those files included in an app as a result of including the library GoogleAdMobAdsSdk in a project (as available from here https://developers.google.com/mobile-ads-sdk/)
If you open that JAR file you can see those annotations folders and XML files are present.
If you don't include that library directly, you may be including another JAR which has those files.
I'd suggest checking the JAR files you include in your project (by opening them in a file that can open APK/Zip files) to find which one(s) include the file and look for an alternative library.
The javascript that comes with it looks like it will lock you out of your device and start making phone calls, mail, SMS, etc while it plays audio and shows a video. It also creates a *.css file and calls on varible uri. I didnt inspect every file but from the *.js file it dont look like I would want to run it. I found this in my Downloads folder, file name, "yourdownloadisready.apk", Im a tech. I cant imagine if a novice saw this.

Having trouble compiling and recreating a JAR file using Eclipse

I have a Java JAR file that was developed to run in the browser. It works fine. There doesn't appear to be any sort of build file associated with the source code I've been given and I'm attempting to create a project and/or build script.
The source code references some third party code. What I've done is unzipped the JAR file into a folder that has this structure:
\App\src\com
\App\src\META-INF
\App\src\applet
The "com" folder contains subfolders which contain the .CLASS files for the third party libraries. "applet" contains the .JAVA source code files (one folder, maybe 15 files).
The code appears to be written in 1.4 syntax (I manually attempted to compile some of the .JAVA files and it complained that some things were deprecated and/or required the older version).
I created a Java Project in Eclipse and pointed it to the \App folder. Then I went into the Properties for the project and went to Libraries and and clicked on "Add Class Folder" and added the \App\src\com folder. Then I went to "Order and Export" and moved this to the top. I also set the Java Compiler version to 1.4.
I am getting a large number of compiler errors, all of which seem to stem from the fact that it says it can't resolve an import. This import is the set of .CLASS files contained in the "com" subfolders. The namespace matches the directory structure.
This seems like it should be really straightforward, but I've tried various things and don't seem to be making any progress. Based on what I've read I'm sure it has something to do with the pathing but I'm at a loss at this point on how to fix it.
(I'm sure it goes without saying that I'm not a Java dev.)
Any thoughts or ideas as to where I'm going wrong?
Can you please try to right click on Eclipse's Navigator. Select Import>General>archive file> (Jar file that you want to import).
You should be getting the jar file correctly imported at this point. Do tell me if you face any problems.

Categories