Skip to content

Commit 7dd9928

Browse files
author
Eric Lange
committed
Android build working and tests passing
1 parent 5072937 commit 7dd9928

28 files changed

Lines changed: 23942 additions & 14 deletions

lib/sqlite3.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
var binary = require('node-pre-gyp');
22
var path = require('path');
3-
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
4-
var binding = require(binding_path);
3+
var binding;
4+
try {
5+
function stealth_require() { return require.call(null, ...arguments); }
6+
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
7+
console.log(binding_path)
8+
binding = stealth_require(binding_path);
9+
} catch(e) {
10+
binding = global.node_require('node_sqlite3.node');
11+
}
512
var sqlite3 = module.exports = exports = binding;
613
var EventEmitter = require('events').EventEmitter;
714

liquidcore/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild

liquidcore/android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

liquidcore/android/build.gradle

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 28
5+
defaultConfig {
6+
minSdkVersion 16
7+
targetSdkVersion 28
8+
versionCode 1
9+
versionName "1.0"
10+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
11+
externalNativeBuild {
12+
cmake {
13+
abiFilters "x86", "armeabi-v7a", "x86_64", "arm64-v8a"
14+
arguments "-DANDROID_STL=c++_static"
15+
}
16+
}
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
externalNativeBuild {
25+
cmake {
26+
path "src/main/cpp/CMakeLists.txt"
27+
}
28+
}
29+
}
30+
31+
configurations {
32+
liquidcore {}
33+
}
34+
35+
dependencies {
36+
implementation fileTree(dir: 'libs', include: ['*.jar'])
37+
implementation 'com.android.support:appcompat-v7:28.0.0'
38+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
39+
testImplementation 'junit:junit:4.12'
40+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
41+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
42+
43+
if (findProject(':LiquidCoreAndroid') != null) {
44+
liquidcore project(path: ':LiquidCoreAndroid', configuration: 'default')
45+
implementation project(':LiquidCoreAndroid')
46+
} else {
47+
liquidcore 'com.github.LiquidPlayer:LiquidCore:0.6.0'
48+
implementation 'com.github.LiquidPlayer:LiquidCore:0.6.0'
49+
}
50+
}
51+
52+
task extractAddOnLibsAndHeaders(type: Sync) {
53+
dependsOn configurations.liquidcore
54+
55+
from {
56+
configurations.liquidcore.collect {zipTree(it)}
57+
}
58+
include "jni/**/*.so", "include/**/*"
59+
into "build/liquidcore-addon"
60+
}
61+
62+
afterEvaluate {
63+
def addon = file('build/liquidcore-addon')
64+
if (!addon.exists()) {
65+
if (project.hasProperty("externalNativeBuildDebug")) {
66+
externalNativeBuildDebug.dependsOn extractAddOnLibsAndHeaders
67+
}
68+
if (project.hasProperty("externalNativeBuildRelease")) {
69+
externalNativeBuildRelease.dependsOn extractAddOnLibsAndHeaders
70+
}
71+
}
72+
}
73+
74+
// build a jar with source files
75+
task sourcesJar(type: Jar) {
76+
from android.sourceSets.main.java.srcDirs
77+
classifier = 'sources'
78+
}
79+
80+
task javadoc(type: Javadoc) {
81+
failOnError false
82+
source = android.sourceSets.main.java.sourceFiles
83+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
84+
classpath += configurations.compile
85+
}
86+
87+
// build a jar with javadoc
88+
task javadocJar(type: Jar, dependsOn: javadoc) {
89+
classifier = 'javadoc'
90+
from javadoc.destinationDir
91+
}
92+
93+
artifacts {
94+
archives sourcesJar
95+
archives javadocJar
96+
}
97+
98+
99+
apply plugin: 'com.github.dcendents.android-maven'
100+
101+
group='com.github.liquidplayer'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="org.liquidplayer.node">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
7+
<application
8+
android:usesCleartextTraffic="true">
9+
</application>
10+
11+
</manifest>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.liquidplayer.node_sqlite3;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
import org.liquidplayer.javascript.JSContext;
10+
import org.liquidplayer.javascript.JSException;
11+
import org.liquidplayer.node.Process;
12+
import org.liquidplayer.service.MicroService;
13+
14+
import java.util.concurrent.CountDownLatch;
15+
import java.util.concurrent.TimeUnit;
16+
17+
import static org.junit.Assert.*;
18+
19+
@RunWith(AndroidJUnit4.class)
20+
public class SQLite3Test implements JSContext.IJSExceptionHandler, Process.EventListener {
21+
private final CountDownLatch waitForService = new CountDownLatch(1);
22+
23+
@Test
24+
public void testModule() throws Exception {
25+
Context appContext = InstrumentationRegistry.getTargetContext();
26+
27+
MicroService service = new MicroService(appContext,
28+
MicroService.DevServer(),
29+
new MicroService.ServiceStartListener() {
30+
@Override public void onStart(MicroService service) {
31+
service.getProcess().addEventListener(SQLite3Test.this);
32+
}
33+
}, new MicroService.ServiceErrorListener() {
34+
@Override public void onError(MicroService service, Exception e) {
35+
fail(e.getMessage());
36+
waitForService.countDown();
37+
}
38+
});
39+
service.start();
40+
waitForService.await(60L, TimeUnit.SECONDS);
41+
}
42+
43+
@Override
44+
public void handle(JSException exception) {
45+
fail(exception.toString());
46+
}
47+
48+
@Override
49+
public void onProcessStart(Process process, JSContext context) {
50+
context.setExceptionHandler(SQLite3Test.this);
51+
}
52+
@Override public void onProcessExit(Process process, int exitCode) {
53+
waitForService.countDown();
54+
}
55+
56+
// Do nothing :- onProcessFailed will get captured in ServiceErrorListener
57+
@Override public void onProcessAboutToExit(Process process, int exitCode) {}
58+
@Override public void onProcessFailed(Process process, Exception error) {}
59+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="org.liquidplayer.node_sqlite3">
3+
4+
</manifest>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.4.1)
2+
3+
add_library(
4+
node-sqlite3.node
5+
SHARED
6+
sqlite3_shim.cpp
7+
${PROJECT_SOURCE_DIR}/../../../../../src/node_sqlite3.cc
8+
${PROJECT_SOURCE_DIR}/../../../../../src/database.cc
9+
${PROJECT_SOURCE_DIR}/../../../../../src/statement.cc
10+
)
11+
12+
include_directories(
13+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/include/node
14+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/include/v8
15+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/include/uv
16+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/include/cares
17+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/include
18+
${PROJECT_SOURCE_DIR}/../../../../../src
19+
${PROJECT_SOURCE_DIR}
20+
${PROJECT_SOURCE_DIR}/../../../../../node_modules/nan
21+
)
22+
23+
unset(EXTRA_CXX_FLAGS)
24+
list(APPEND EXTRA_CXX_FLAGS
25+
-Wno-deprecated-declarations
26+
-DNODE_WANT_INTERNALS=1
27+
)
28+
string (REPLACE ";" " " CPP_FLAGS_STR "${EXTRA_CXX_FLAGS}")
29+
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_FLAGS_STR}" )
30+
31+
32+
find_library(
33+
log-lib
34+
log)
35+
36+
add_library(
37+
node-lib
38+
SHARED
39+
IMPORTED
40+
)
41+
add_library(
42+
liquidcore-lib
43+
SHARED
44+
IMPORTED
45+
)
46+
set_target_properties(
47+
node-lib
48+
PROPERTIES IMPORTED_LOCATION
49+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/jni/${ANDROID_ABI}/libnode.so
50+
)
51+
set_target_properties(
52+
liquidcore-lib
53+
PROPERTIES IMPORTED_LOCATION
54+
${PROJECT_SOURCE_DIR}/../../../build/liquidcore-addon/jni/${ANDROID_ABI}/libliquidcore.so
55+
)
56+
target_link_libraries( # Specifies the target library.
57+
node-sqlite3.node
58+
node-lib
59+
liquidcore-lib
60+
${log-lib})

0 commit comments

Comments
 (0)