I am writing an app to connect to a database on a server (AS400 server using SQL to talk to the database). IBM supplies a java toolbox to access the server in a jar called jt400android.
I have a test function:
protected void ConnectionTest()
{
AS400 system = new AS400("jc400");
try
{
system.connectService(AS400.RECORDACCESS);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
AS400 is a function included in the jt400android.jar in com.ibm.as400.access.* that handles socket protocol, connections, and authentication to an AS400 machine. (I've resorted to this method as JDBC is apparently not a good way to go).
The code compiles just fine, no errors or warnings, but when I run the apk on my AVD, I get this error
03-12 22:44:30.300: E/dalvikvm(484): Could not find class 'com.ibm.as400.access.AS400', referenced from method jcpaper.android.jc400droid.MainActivity.ConnectionTest
I've searched the forums and tried the following suggestions:
added the jar to Java Build Path > Libraries (did this to make the code compile)
checked jar on Java Build Path > Order and Export
included a copy of the jar in [project folder]/libs
Each time I end up with the same could not find class error.
I'm running Eclipse for mobile (Juno v1) on Windows XP, building for Android 2.3.3.
Any suggestions on what's happening here?
The JTOpen Lite/JTLite libraries might provide a better way of connecting to your server. These libraries are new from IBM and are designed for specific use on Android devices.
JTOpen Lite - IBM Developer Works
JTOpen Lite Javadoc
Make sure that you add the .jar to the build path and export the libraries properly.
The record level access method that you are trying to use is an older method for connecting applications to DB2 databases, so you will probably have a harder time finding information about it.
Related
I have an Android native library (C++ code base) called:
libserverapp.so
And I cannot get the Android build to find it:
"DllNotFoundException: serverapp"
I am using an internal build system, but when I parse the output of the build process, I can see many calls of the form:
android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++.exe -march=armv7-a
After building my Android app, I inspect the resulting APK (renaming to .zip and extracting), and can see my library file here:
lib/armeabi-v7a/libserverapp.so
I can confirm that "ARMv7" is the target architecture in the Android Player settings, and I access the library, in C#, via:
[DllImport("serverapp", CallingConvention = CallingConvention.Cdecl)]
private static extern void run_sim(StringBuilder matchInput, StringBuilder results, int randomSeed);
I have built a Windows DLL of the C++ code, to use in the Editor, and everything works great. However, when I move to Android, the .so cannot be found. The import settings for libserverapp.so are:
Platform: Android; CPU: ARMv7; Path: Assets/Plugins/Android/libserverapp.so; Type: Native
Given that the final APK includes the .so where I expect it to be (lib/armeabi-v7a/), I assume my Unity settings are correct? Also, I am not using IL2CPP for the Android build.
Finally, when I do an object dump of the library file (using arm-linux-androideabi-objdump.exe), the file format of the library file is "elf32-littlearm".
I feel that the issue here is simply finding the .so, not the functionality within it. Any ideas on what's going on here?
Thanks!
I ended up solving the problem. I mentioned that was using an internal build system. Well, there seems to be a bug in it. I ported things over to official Android NDK makefiles, and then it "just worked". So in this case, the library could be found, but its contents weren't valid.
I'm new to Android development.
I'm porting a PC application to RealWear's HMT1 Android device. I don't want to rewrite my code, so I'm going to try using Hibernate with H2db, both of which SHOULD work on Android.
Unfortunately, I haven't found any instructions on how to install H2 on Android. H2 is a .jar file, and so far I've only worked with APK's through Android studio.
How do I install H2 on Android?
As pointed out in the comment above, H2 can't be installed on Android as is. I suppose one could take the source code and recompile it for Android but the cost in time and aggravation outweigh the benefits.
Nor can Hibernate be easily used, especially its JPA implementation. Hibernate looks for connection/configuration information in the META-INF directory of the .jar file. I have no idea if such a directory exists or can be placed in an APK such that Hibernate can find it. Moreover, the Dalvik VM has significant differences from Oracle's Java VM, and much of Hibernate's functionality may not even be available on Android.
I had chosen Java for development because of its "Write Once, Run Anywhere" philosophy, but Google seems to have rejected that philosophy. It seems to be "Write Once, Run Anywhere But Android, Where You Have To Write It Again."
add graddle
dependencies {
compile 'com.h2database:h2:1.4.196'
runtimeOnly 'com.h2database:h2:1.4.196'
}
h2 works perfectly in Adnroid, just add the dependency to gradle.app.
Then you must indicate on what database you are going to work:
try{
Class.forName("org.h2.Driver");
}
catch(ClassNotFoundException e){System.out.println(e);}
try{
CONN_STR = "jdbc:h2:/data/data/com.example.example/data/dbfile;FILE_LOCK=FS;PAGE_SIZE=1024;CACHE_SIZE=8192";
conn = DriverManager.getConnection(CONN_STR);
}
catch (SQLException ex)
{
}
I am trying to build a cross-platform application for Android and iOS and have chosen to use Boost to simplify communication and to parse the JSON from the response. Everything works fine in iOS, but Android fails with "service not found" error, or "host not found (authoritative)" if I change the query to query(server, "");.
I pulled the code out of my application and simplified it to what was throwing the error and this is what I have:
...
#include <boost/asio.hpp>
boost::asio::io_service io_service;
std::string server = "<server_address>";
// Get a list of endpoints corresponding to the server name.
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(server, "http");
boost::system::error_code ec;
boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query,ec);
if (ec)
{
return env->NewStringUTF(ec.message().c_str());
}
I am using Android NDK r8e (64-bit) and Boost version 1.53 (latest releases as of writing). I have used https://github.com/MysticTreeGames/Boost-for-Android with slight modification to work with the 64-bit NDK (see https://github.com/MysticTreeGames/Boost-for-Android/pull/28) for building the required Boost libraries.
I will be modifying this to work with async_resolve, which is what the iOS version is using, once I can get this part working.
Edit:
I noticed I had forgotten to update the Android Manifest file, so I added
<uses-permission android:name="android.permission.INTERNET"></uses-permission>, but I still get the same errors. Am I simply missing something else in the manifest?
It means that the OS can't figure out which port stands for http. On most POSIX-compliant systems this mapping is done in /etc/services file, and if http line is missing there, you'll get "service not found" error.
I don't know whether Android has this file or not (older versions didn't support it at all, the services were hardcoded in bionic), but if you get the above error, the only workaround is to set the desired port manually:
tcp::resolver::query query(tcp::v4(), yourHost, "80");
I'm facing a problem and would really appreciate your help...
Android SDK: 4.0
Phonegap: 1.8.1
Pusher: 1.12
I have created an Android project using Phonegap that needs to receive server notifications through Pusher.
I'm running it in Eclipse and AVD emulator, but the problem is that every time I try to establish a connection to pusher, I get an Unavailable state from the bind to state_change.
I have tested the connection to Internet in the emulator browser and it works fine. I have also tested that the server is responding and that the Pusher key is the right one by testing my code on Firefox.
This are the steps I have followed:
I have included the WebSocket.java and WebSocketFactory.java files in the src folder.
I have included websocket.js file in my js folder and included a reference in the index.html file.
I have included a reference to http://js.pusher.com/1.12/pusher.js in the index file.
I have included the following line in my Android App.java file: this.appView.addJavascriptInterface(new WebSocketFactory(this), "WebSocketFactory");
This is the code I'm using to connect to Pusher:
// Connect
var pusher = new Pusher(CONFIG.PUSHER.APP_KEY);
pusher.connection.bind('state_change', connectionStateChange);
function connectionStateChange(state) {
alert(state.current);
}
Is there something I'm missing? Any ideas on why the connection is not working or about where to check?
Thanks for your help.
Chadid
For version 2.x of pusher-js and above the library will work within PhoneGap without any additional requirements or setup. Simply include the library and use it - no need for WebSocket.java or WebSocketFactory.java.
For version 1.x this blog post and associated code demonstrates how to get Pusher working on PhoneGap:
http://blog.pusher.com/2012/7/5/pusher-on-phonegap-for-android
I have a semester long project that I have been working on in Android with a four person group. It is due tomorrow. I was planning on using JDBC for Android, but I have run into an ugly problem I had seen before. No matter what I do, my Android will not recognize external references. For awhile I avoided the problem by copying source code into my project.
However, with JDBC, I need a JAR Driver to in order to connect to the MySQL Database. So you are aware, I am adding the JAR by:
Creating a folder
Importing the JAR into that folder
Adding the JAR to the BuildPath in the Android Project.
I also tried adding an external Java Project by adding it to the BuildPath. There were no Compile errors, but I got ClassNotFound errors when the code executed on my (Ice Cream Sandwich) phone. The project is in Android 2.2. I have heard making an Android Library project will solve this, but I am not interested in that solution as it defeats the purpose of the project reference in my case.
With the JDBC Driver, the following RuntimeException was thrown in my project here:
private final static String driver = "com.mysql.jdbc.Driver";
private final static String userName = "sqluser";
private final static String passwd = "sqlpw";
public Query() {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// System.err
// .println("error in DB connection: can not find the DB driver");
throw new RuntimeException("Driver not found");
}
The code works fine as a Java Application.
Any solution that works would be highly appreciated. Since the project is due tomorrow, it doesn't have to be the most elegant approach. Also (not that it matters), my project is connected to a SVN repository via SubClipse. Thanks in advance!
I'm unsure which folder you are putting the JAR in but for android projects you must put them inside of the folder "libs".