Skip to content

Commit cdbc01b

Browse files
authored
Merge pull request #1195 from Crisaldroid/android-sdk-below-24
Problem: JNI bindings not compatible with Android SDK < 24
2 parents 3e60ac2 + cf21427 commit cdbc01b

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

zproject_java.gsl

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ dependencies {
151151
compile 'org.zeromq:$(use.project)-jni:+'
152152
. endif
153153
. endfor
154-
compile 'org.scijava:native-lib-loader:2.3.2'
154+
compile 'org.scijava:native-lib-loader:2.3.4'
155155
testCompile 'junit:junit:4.12'
156156
testCompile 'org.hamcrest:hamcrest-all:1.3'
157157
}
@@ -763,6 +763,7 @@ popd
763763
. output "$(topdir)/src/main/java/org/zeromq/tools/ZmqNativeLoader.java"
764764
package org.zeromq.tools;
765765

766+
import java.io.IOException;
766767
import java.util.Set;
767768
import java.util.HashSet;
768769
import org.scijava.nativelib.NativeLoader;
@@ -771,16 +772,16 @@ public class ZmqNativeLoader {
771772

772773
private static final Set<String> loadedLibraries = new HashSet<>();
773774

774-
public static void loadLibrary(String libname) {
775+
public static void loadLibrary(String libname, boolean optional) {
775776
if (!loadedLibraries.contains(libname)) {
776777
try {
777-
if (System.getProperty("java.vm.vendor").contains("Android")) {
778-
System.loadLibrary(libname);
778+
NativeLoader.loadLibrary(libname);
779+
} catch (IOException e) {
780+
if (optional) {
781+
System.err.println("[WARN] " + e.getMessage() + " from jar. Assuming it is installed on the system.");
779782
} else {
780-
NativeLoader.loadLibrary(libname);
783+
System.exit(-1);
781784
}
782-
} catch (Exception e) {
783-
System.err.println("[WARN] " + e.getMessage() +" from jar. Assuming it is installed on the system.");
784785
}
785786
loadedLibraries.add(libname);
786787
}
@@ -797,7 +798,6 @@ $(project.GENERATED_WARNING_HEADER:)
797798
*/
798799
package org.zeromq.$(project.prefix:c);
799800

800-
import java.util.stream.Stream;
801801
import org.zeromq.tools.ZmqNativeLoader;
802802
. for project.use
803803
. if count (project->dependencies.class, class.project = use.project) > 0
@@ -807,28 +807,15 @@ import org.zeromq.$(use.project).*;
807807

808808
public class $(my.class.name:pascal) \
809809
. if count (my.class.constructor)
810-
implements AutoCloseable\
810+
implements AutoCloseable \
811811
. endif
812812
{
813813
static {
814-
Stream.of(
815814
. for project.use
816-
"$(use.prefix:c)",
815+
ZmqNativeLoader.loadLibrary("$(use.prefix:c)", true);
817816
. endfor
818-
"$(project.prefix:c)"
819-
)
820-
.forEach(lib -> {
821-
try {
822-
ZmqNativeLoader.loadLibrary(lib);
823-
} catch (Exception e) {
824-
System.err.println("[WARN] " + e.getMessage() +" from jar. Assuming it is installed on the system.");
825-
}
826-
});
827-
try {
828-
ZmqNativeLoader.loadLibrary("$(project.prefix:c)jni");
829-
} catch (Exception e) {
830-
System.exit (-1);
831-
}
817+
ZmqNativeLoader.loadLibrary("$(project.prefix:c)", true);
818+
ZmqNativeLoader.loadLibrary("$(project.prefix:c)jni", false);
832819
}
833820
public long self;
834821
. my.class.jni_void_new = 0

0 commit comments

Comments
 (0)