Android Sqlite crash

The android-targeted code below compiles but crashes.
ENV:FlashDevelop 5, Windows7,Haxe 3.2,lime 2.9,openfl 3.6

package;
import openfl.display.Sprite;
import haxe.io.Path;
import lime.system.System;

class Main extends Sprite {
public function new () {
super ();
var dbfile = Path.join([System.applicationStorageDirectory, “localstorage.db”]);
var cnx = Sqlite.open(dbfile);
cnx.close();
}
}

class SObject extends sys.db.Object {
public var id:sys.db.Types.SId;
public var value:sys.db.Types.SInt;
}
-------project.xml --------

<?xml version="1.0" encoding="utf-8"?>
<app main="Main" file="sqliteTest" path="bin" />

<window background="#000000" fps="60" />
<window width="800" height="480" unless="mobile" />
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />

<source path="src" />
<haxelib name="openfl" />
<haxelib name="actuate" />

<icon path="assets/openfl.svg" />
<assets path="assets/img" rename="img" />

<android permission="android.permission.WAKE_LOCK" />
<android permission="android.permission.INTERNET" />
<android permission="android.permission.VIBRATE" />
<android permission="android.permission.ACCESS_NETWORK_STATE" />
<android permission="android.permission.WRITE_EXTERNAL_STORAGE" />
<android permission="android.permission.READ_EXTERNAL_STORAGE" />
------------------------android studio log----------- 03-02 11:31:32.265 9780-9868/com.sqliteTest E/HXCPP﹕ Called from ApplicationMain::main ApplicationMain.hx line 139 03-02 11:31:32.265 9780-9868/com.sqliteTest E/HXCPP﹕ Called from ApplicationMain::create ApplicationMain.hx line 51 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from lime.app.Application::exec lime/app/Application.hx line 221 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from lime._backend.native.NativeApplication::exec lime/_backend/native/NativeApplication.hx line 129 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from lime._backend.native.NativeApplication::handleApplicationEvent lime/_backend/native/NativeApplication.hx line 166 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from lime._backend.native.NativeApplication::updateTimer lime/_backend/native/NativeApplication.hx line 590 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from *::_Function_1_1 haxe/Timer.hx line 230 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from *::_Function_1_1 Main.hx line 28 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from sys.db.Sqlite::open C:\HaxeToolkit\haxe\std/cpp/_std/sys/db/Sqlite.hx line 185 03-02 11:31:32.270 9780-9868/com.sqliteTest E/HXCPP﹕ Called from sys.db._Sqlite.SqliteConnection::new C:\HaxeToolkit\haxe\std/cpp/_std/sys/db/Sqlite.hx line 29 03-02 11:31:32.270 9780-9868/com.sqliteTest E/Exception﹕ Null Function Pointer 03-02 11:31:32.330 9780-9780/com.sqliteTest V/SDL﹕ onPause() 03-02 11:31:32.330 9780-9780/com.sqliteTest V/SDL﹕ nativePause() 03-02 11:31:32.375 9780-9780/com.sqliteTest D/SensorManager﹕ unregisterListener:: Listener= org.libsdl.app.SDLSurface@41f5a060 03-02 11:31:32.375 9780-9780/com.sqliteTest D/Sensors﹕ Remain listener = Sending .. normal delay 200ms 03-02 11:31:32.375 9780-9780/com.sqliteTest I/Sensors﹕ sendDelay --- 200000000 03-02 11:31:32.375 9780-9780/com.sqliteTest D/SensorManager﹕ JNI - sendDelay 03-02 11:31:32.375 9780-9780/com.sqliteTest I/SensorManager﹕ Set normal delay = true 03-02 11:31:32.520 9780-9780/com.sqliteTest V/SDL﹕ onWindowFocusChanged(): false 03-02 11:31:32.530 9780-9780/com.sqliteTest V/SDL﹕ surfaceDestroyed() 03-02 11:31:32.530 9780-9780/com.sqliteTest W/SurfaceView﹕ CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false 03-02 11:31:32.695 9780-9780/com.sqliteTest W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection 03-02 11:31:32.720 9780-9780/com.sqliteTest V/SDL﹕ onDestroy()

I got around a similar crash by adding

#if android
	// Make SQLite work on android by statically compiling the library
	import hxcpp.StaticSqlite;
#end

to the top of my class. You may need to add hxcpp as a haxelib to your project too. This forces the SQLite lib to be statically compiled into your app,. You can then use SQLite as you normally would on any other platform.

2 Likes

Oh yeah,it works.Thank you!