How do I install H2? - android

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)
{
}

Related

How do I include extensions with a custom build of Firefox for Android (Fennec)?

I'm trying to include an extension in a custom build of Firefox for Android (Fennec) so that when the user installs the APK, the Fennec browser already has the extension installed.
I'm using a baseline of Fennec v48.0b6. It might be worth drawing attention to the fact that this is beta build, although I don't expect it should make a difference.
The simple way this should work
Documentation for such a process does seem to exist but I'm having trouble getting it to work. The Mozilla Wiki has a guide to this. It, and other hints surrounding the solution I've found, indicate that I need a 'distribution' folder somewhere in the Firefox workspace. I have a folder structure as follows:
firefox-48.0b6
custom-dist
assets
distribution
preferences.json
extensions
my-extension.xpi
where 'firefox-48.0b6' is the root folder containing all of the source directories such as b2g, browser, chrome, mobile, and so on. This matches the sample directory structure provided by Mozilla.
I've added the following line to my mozconfig:
ac_add_options --with-android-distribution-directory="/data/workspaces/firefox/firefox-48.0b6/custom-dist"
which correctly tracks the absolute distribution location. If this path doesn't point to a distribution then I get an error when I run mach configure, so it must be being read.
The extension's XPI name needs to match the ID (as indicated on the same Mozilla Wiki page) given in the extension's install.rdf file. I've changed the install.rdf file and the XPI name so that they match.
Having done all of this I still don't see my extension in the list of add-ons when I install the APK.
What I've done to try to get this to work
I've tried a few additional things (none of which have solved my problem):
Changing the MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER flag to False in mobile/android/moz.configure. This is mentioned in the Mozilla Wiki. Bugzilla seems to indicate that there is a bug still present in this version so this is probably not worth further enquiry.
Having read the comments (specifically comment 2) on the linked bug from the above point, I've tried setting changing the MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER=1 to MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER= in mobile/android/confvars.sh so that it's not read as a truthy value.
I've tried deleting MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER from confvars.sh altogether.
Tried putting the distribution folder into objdir-droid/dist/bin as indicated in this StackOverflow question and answer. It's notable that this is not mentioned on the Mozilla Wiki. From this Bugzilla bug report it looks like it relates to an old method of doing things.
Where I'm stuck
Ultimately, I still don't have a build of Firefox for Android that has the extension included by default. There are a couple of points that might be the source of the problem, but I don't know enough about the process to say for sure, namely:
I'm using a beta build of Firefox for Android as my baseline. Will this cause problems for the purposes of including a distribution?
I push the APK directly to /system/priv-app rather than installing it (either within the Android OS itself or by using adb install). Does this make a difference as to whether the distribution is applied?
What have I missed that will get this working?
Edit
I've since realised that I also need a minimal preferences.json file in the distribution directory. However, including this hasn't solved the problem...
I have the same problem with you.
After extracting the apk file into a folder, I found that my xpi file is not included.
Maybe there is a bug related to fennec packaging scripts about option "--with-android-distribution-directory"? Maybe dig more into the scripts implementation is another choice. Also we can try to install the xpi ourselves by referencing the following js script which is implemented in fennec:
mozilla-central/mobile/android/chrome/content/browser.js
installDistroAddons: Task.async(function* () {
const PREF_ADDONS_INSTALLED = "distribution.addonsInstalled";
try {
let installed = Services.prefs.getBoolPref(PREF_ADDONS_INSTALLED);
if (installed) {
return;
}
} catch (e) {
Services.prefs.setBoolPref(PREF_ADDONS_INSTALLED, true);
}
let distroPath;
try {
distroPath = FileUtils.getDir("XREAppDist", ["extensions"]).path;
let info = yield OS.File.stat(distroPath);
if (!info.isDir) {
return;
}
} catch (e) {
return;
}
let it = new OS.File.DirectoryIterator(distroPath);
try {
yield it.forEach(entry => {
// Only support extensions that are zipped in .xpi files.
if (entry.isDir || !entry.name.endsWith(".xpi")) {
dump("Ignoring distribution add-on that isn't an XPI: " + entry.path);
return;
}
new Promise((resolve, reject) => {
AddonManager.getInstallForFile(new FileUtils.File(entry.path), resolve);
}).then(install => {
let id = entry.name.substring(0, entry.name.length - 4);
if (install.addon.id !== id) {
Cu.reportError("File entry " + entry.path + " contains an add-on with an incorrect ID");
return;
}
this.pendingAddonInstalls.add(install);
install.install();
}).catch(e => {
Cu.reportError("Error installing distribution add-on: " + entry.path + ": " + e);
});
});
} finally {
it.close();
}
})
I know that the IceCat mobile browser for Android is such a derivative that includes preinstalled extensions. Keep in mind that they're based on the ESR channel so you might need to mess with their build scripts a bit, but I'd take a look at their implementation. Here's the project page:
https://www.gnu.org/software/gnuzilla/
If that's no good then maybe take a look at the TOR firefox distribution (I'm pretty sure they include noscript by default).

Boost.Asio on Android failing with Service Not Found (Boost 1.53; NDK r8e)

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");

app won't recognize function in non-android jar

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.

Android Project will not work with external JAR or Project Reference

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".

Issue with Uncompressing the .7z file in the Android evn

Getting "system.entrypointnotfoundexception: loadlibrary" While trying to use SevenZipLib.dll to uncompress the .7z file containing media contents/file in the Android evn.
Context:
-The whole program is written in c# as a MONO Android Project. No Build/Deployment Error/warnings.
While running the apk, its throwing "system.entrypointnotfoundexception: loadlibrary".
-Also tested the same code as windows project (not mono) - uncompressing in the windows evn.
Assumptions for the issue:
7zip internally might be using COM components & Mono frame work is not supporting.
Question:
Has anyone come across similar issue? Please suggest some alternative dll/framework which can be used by my apk for uncompressing the .7z file.
Assuming that SevenZipLib.dll is the SevenZipLib Library on CodePlex, the problem is SevenZipLib\SevelZipLib\SevenZipArchive.cs:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern SafeLibraryHandle LoadLibrary(
[MarshalAs(UnmanagedType.LPTStr)] string lpFileName);
The project contains numerous P/Invokes into kernel32.dll (LoadLibrary(), GetProcAddress(), FreeLibrary()), ole32.dll (PropVariantClear()), oleaut32.dll (SafeArrayCreateVector()), and more.
In short, this library is intimately tied to Windows, and isn't going to work on a non-Windows platform in any meaningful fashion, not without a lot of work.
If you need 7z support in a Mono for Android application, you'll need to look into a different library. It looks like the 7-zip SDK includes C# source for reading LZMA files that doesn't rely on P/Invoke, so perhaps that would work?

Categories

Resources