Skip to content

Gleefre/and-jni

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 

Repository files navigation

and-jni

CFFI bindings to JNI for android.

and stands for android and … .

Quick start

Clone repository to you local-projects directory and load it:

(ql:quickload :and-jni)

On android you will need to load libandroid.so:

;; SBCL
(sb-alien:load-shared-object "libandroid.so")
;; With cffi
(cffi:define-foreign-library libandroid
  (:android "libandroid.so"))
(cffi:load-foreign-library 'libandroid)

To get list of created JavaVMs:

(and-jni:get-created-vms)

On android there will be exactly one VM loaded per process. However, if you are running from shell, you are out of luck: there is no VM loaded and you can’t use JNI.

After you get handle for VM:

(defparameter *vm* (car (and-jni:get-created-vms)))

you need to attach you current thread to the VM:

(and-jni/cffi:attach-current-thread *vm*)

Two values are returned: return code and JNI environment.

You can also get JNI envrionment with get-environment:

(defparameter *env* (and-jni/cffi:get-environment *vm*))

In the end you should detach your thread:

(and-jni/cffi:detach-current-thread *vm*)

See the JNI spec to learn what you can do with JNI environment. https://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html .

Bugs & Contributions

Feel free to report bugs or make suggestions by filing an issue on github.

Feel free to submit pull requests on github as well.

License

Copyright 2023 Gleefre

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

CFFI bindings to JNI for android.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published