Một mục phía máy chủ trong kho dữ liệu GitHub của TopGit: kivy/pyjnius, 1.5k sao, nhóm Backend, Python. Access Java classes from Python
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
PyJNIus is a Python library for accessing
Java classes using the
Java Native Interface
(JNI).
PyJNIus is managed by the Kivy Team and can be
used with python-for-android.
It can also be used independently of Kivy, on desktop and mobile platforms.
[!WARNING]
The PyPI package name is now
pyjnius instead of jnius.
Installation
pip install pyjnius
Quick overview
>>> from jnius import autoclass
>>> autoclass('java.lang.System').out.println('Hello world')
Hello world
>>> Stack = autoclass('java.util.Stack')
>>> stack = Stack()
>>> stack.push('hello')
>>> stack.push('world')
>>> print(stack.pop())
world
>>> print(stack.pop())
hello
Usage with python-for-android
Get python-for-android
Compile a distribution with kivy (PyJNIus will be automatically added)
Then, you can do this kind of thing:
from time import sleep
from jnius import autoclass
Hardware = autoclass('org.renpy.android.Hardware')
print('DPI is', Hardware.getDPI())
Hardware.accelerometerEnable(True)
for x in range(20):
print(Hardware.accelerometerReading())
sleep(0.1)
When you use autoclass, it will discover all the methods and fields of the
class and resolve them. You may want to declare and use only what you
need. The previous example can be done manually as follows:
from time import sleep
from jnius import MetaJavaClass, JavaClass, JavaMethod, JavaStaticMethod
class Hardware(JavaClass, metaclass=MetaJavaClass):
__javaclass__ = 'org/renpy/android/Hardware'
vibrate = JavaStaticMethod('(D)V')
accelerometerEnable = JavaStaticMethod('(Z)V')
accelerometerReading = JavaStaticMethod('()[F')
getDPI = JavaStaticMethod('()I')
# use that new class!
print('DPI is', Hardware.getDPI())
Hardware.accelerometerEnable(True)
for x in range(20):
print(Hardware.accelerometerReading())
sleep(0.1)
You can use the signatures method of JavaMethod and JavaMultipleMethod, to inspect the discovered signatures of a method of an object
Each pair contains the list of accepted arguments types, and the returned type.
Troubleshooting
Make sure a Java Runtime Environment (JRE) is installed if you want to use
PyJNIus on desktop. A Java Development Kit (JDK) is required when building
PyJNIus from source. OpenJDK is known to work, and Oracle Java should
work as well. See the installation documentation
for details.
On Windows, make sure JAVA_HOME points to your Java installation, so PyJNIus
can locate the jvm.dll file allowing it to start Java. This shouldn't be
necessary on macOS and Linux, but in case PyJNIus fails to find it, setting
JAVA_HOME should help.
License
PyJNIus is MIT licensed, actively developed by a great
community and is supported by many projects managed by the
Kivy Organization.
Documentation
Documentation for this repository.
Support
Are you having trouble using PyJNIus or any of its related projects in the Kivy
ecosystem?
Is there an error you don’t understand? Are you trying to figure out how to use
it? We have volunteers who can help!
The best channels to contact us for support are listed in the latest
Contact Us document.
Contributing
PyJNIus is part of the Kivy ecosystem - a large group of
products used by many thousands of developers for free, but it
is built entirely by the contributions of volunteers. We welcome (and rely on)
users who want to give back to the community by contributing to the project.
Contributions can come in many forms. See the latest
Contribution Guidelines
for how you can help us.
Code of Conduct
In the interest of fostering an open and welcoming community, we as
contributors and maintainers need to ensure participation in our project and
our sister projects is a harassment-free and positive experience for everyone.
It is vital that all interaction is conducted in a manner conveying respect,
open-mindedness and gratitude.
Please consult the latest Code of Conduct.
Contributors
This project exists thanks to
all the people who contribute.
[Become a contributor].
Backers
Thank you to all of our backers!
🙏 [Become a backer]
Sponsors
Special thanks to
all of our sponsors, past and present.
Support this project by
[becoming a sponsor].
Here are our top current sponsors. Please click through to see their websites,
and support them as they support us.
kivy/pyjnius có 1.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/kivy/pyjnius. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
kivy/pyjnius có những chủ đề gì?
GitHub topics của kivy/pyjnius: "java", "jni", "jni-android", "jni-wrapper", "python". TopGit xếp repo vào nhóm Backend.
kivy/pyjnius còn đang phát triển không?
Commit gần nhất trên kivy/pyjnius là 3 tháng trước (theo timestamp GitHub). Repo có 328 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
kivy/pyjnius là gì?
kivy/pyjnius (kivy/pyjnius) là dự án Python trên GitHub. Theo mô tả gốc: Access Java classes from Python
kivy/pyjnius so với các dự án Backend khác thế nào?
kivy/pyjnius được TopGit xếp vào nhóm Backend, với 1.5k sao GitHub và viết bằng Python. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
kivy/pyjnius viết bằng ngôn ngữ gì?
kivy/pyjnius chủ yếu viết bằng Python. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao kivy/pyjnius được xếp vào nhóm Backend?
TopGit xếp kivy/pyjnius vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "java", "jni", "jni-android"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về pyjnius?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về pyjnius.