File tree Expand file tree Collapse file tree 3 files changed +35
-12
lines changed
Demo/app/src/main/java/com/pureswift/swiftandroid Expand file tree Collapse file tree 3 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ fun EmbeddedAndroidViewDemo() {
2828 // widget.ImageView
2929 AndroidView (factory = { ctx ->
3030 ImageView (ctx).apply {
31- val drawable = ContextCompat .getDrawable(ctx, R .drawable.ic_launcher_background )
31+ val drawable = ContextCompat .getDrawable(ctx, R .drawable.ic_launcher_foreground )
3232 setImageDrawable(drawable)
3333 }
3434 })
Original file line number Diff line number Diff line change @@ -16,12 +16,7 @@ import com.pureswift.swiftandroid.ui.theme.SwiftAndroidTheme
1616class MainActivity : ComponentActivity () {
1717
1818 init {
19- loadNativeLibrary()
20- }
21-
22- private fun loadNativeLibrary () {
23- System .loadLibrary(" Foundation" )
24- System .loadLibrary(" SwiftAndroidApp" )
19+ NativeLibrary .shared()
2520 }
2621
2722 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -44,11 +39,7 @@ class MainActivity : ComponentActivity() {
4439class MainActivityHello {
4540
4641 init {
47- loadNativeLibrary()
48- }
49-
50- private fun loadNativeLibrary () {
51- System .loadLibrary(" SwiftAndroidApp" )
42+ NativeLibrary .shared()
5243 }
5344
5445 external fun sayHelloName (): String
Original file line number Diff line number Diff line change 1+ package com.pureswift.swiftandroid
2+
3+ import android.util.Log
4+
5+ class NativeLibrary private constructor() {
6+
7+ companion object {
8+
9+ @Volatile
10+ var shared : NativeLibrary ? = null
11+
12+ fun shared (): NativeLibrary {
13+ return shared? : synchronized(this ){
14+ val instance = NativeLibrary ()
15+ shared = instance
16+ return instance
17+ }
18+ }
19+ }
20+
21+ init {
22+ loadNativeLibrary()
23+ }
24+
25+ private fun loadNativeLibrary () {
26+ try {
27+ System .loadLibrary(" SwiftAndroidApp" )
28+ } catch (error: UnsatisfiedLinkError ) {
29+ Log .e(" NativeLibrary" , " Unable to load native libraries: $error " )
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments