File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,21 @@ import JavaRuntime
19
19
/// while this instance is live.
20
20
public class JavaObjectHolder {
21
21
public private( set) var object : jobject ?
22
+ #if canImport(Android)
23
+ public var environment : JNIEnvironment {
24
+ try ! JavaVirtualMachine . shared ( ) . environment ( )
25
+ }
26
+ #else
22
27
public let environment : JNIEnvironment
28
+ #endif
23
29
24
30
/// Take a reference to a Java object and promote it to a global reference
25
31
/// so that the Java virtual machine will not garbage-collect it.
26
32
public init ( object: jobject , environment: JNIEnvironment ) {
27
33
self . object = environment. interface. NewGlobalRef ( environment, object)
34
+ #if !canImport(Android)
28
35
self . environment = environment
36
+ #endif
29
37
}
30
38
31
39
/// Forget this Java object, meaning that it is no longer used from anywhere
You can’t perform that action at this time.
0 commit comments