|
17 | 17 |
|
18 | 18 | #include <jni.h> |
19 | 19 |
|
| 20 | +// Provide C-compatible type aliases for JNI types. |
| 21 | +// When Swift modules have C++ interoperability enabled, jni.h is parsed |
| 22 | +// in C++ mode where JNIEnv is defined as a struct (JNIEnv_). However, |
| 23 | +// SwiftJava modules are compiled without C++ interop, causing JNIEnv |
| 24 | +// to be a pointer type. This mismatch causes type errors. |
| 25 | +// |
| 26 | +// These typedefs provide consistent C-style pointer types that work |
| 27 | +// regardless of the C++ interoperability mode. |
| 28 | +// See: https://github.com/swiftlang/swift-java/issues/391 |
| 29 | +#ifdef __cplusplus |
| 30 | +// Android NDK uses JNINativeInterface instead of JNINativeInterface_ |
| 31 | +#ifdef __ANDROID__ |
| 32 | +typedef const JNINativeInterface *CJNIEnv; |
| 33 | +#else |
| 34 | +typedef const JNINativeInterface_ *CJNIEnv; |
| 35 | +#endif |
| 36 | +typedef _jobject *Cjobject; |
| 37 | +typedef _jclass *Cjclass; |
| 38 | +typedef _jstring *Cjstring; |
| 39 | +typedef _jarray *Cjarray; |
| 40 | +typedef _jobjectArray *CjobjectArray; |
| 41 | +typedef _jbooleanArray *CjbooleanArray; |
| 42 | +typedef _jbyteArray *CjbyteArray; |
| 43 | +typedef _jcharArray *CjcharArray; |
| 44 | +typedef _jshortArray *CjshortArray; |
| 45 | +typedef _jintArray *CjintArray; |
| 46 | +typedef _jlongArray *CjlongArray; |
| 47 | +typedef _jfloatArray *CjfloatArray; |
| 48 | +typedef _jdoubleArray *CjdoubleArray; |
| 49 | +typedef _jthrowable *Cjthrowable; |
| 50 | +#else |
| 51 | +typedef JNIEnv CJNIEnv; |
| 52 | +typedef jobject Cjobject; |
| 53 | +typedef jclass Cjclass; |
| 54 | +typedef jstring Cjstring; |
| 55 | +typedef jarray Cjarray; |
| 56 | +typedef jobjectArray CjobjectArray; |
| 57 | +typedef jbooleanArray CjbooleanArray; |
| 58 | +typedef jbyteArray CjbyteArray; |
| 59 | +typedef jcharArray CjcharArray; |
| 60 | +typedef jshortArray CjshortArray; |
| 61 | +typedef jintArray CjintArray; |
| 62 | +typedef jlongArray CjlongArray; |
| 63 | +typedef jfloatArray CjfloatArray; |
| 64 | +typedef jdoubleArray CjdoubleArray; |
| 65 | +typedef jthrowable Cjthrowable; |
| 66 | +#endif |
| 67 | + |
20 | 68 | #endif /* CSwiftJavaJNI_h */ |
0 commit comments