Skip to content

Commit f288876

Browse files
Fix jvm native lib handling
1 parent 9403b8f commit f288876

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

.github/workflows/pullrequest.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ jobs:
2323
- name: Install dependencies
2424
shell: bash
2525
run: |
26-
cat /proc/mounts | grep /tmp
2726
sudo apt-get update
2827
sudo apt-get install -y cmake swig ninja-build clang clang-tools libc++-dev libc++abi-dev
29-
file /lib/x86_64-linux-gnu/libc++.so
3028
- name: Setup Android SDK
3129
uses: android-actions/setup-android@v3
3230
- name: Setup Android NDK
@@ -37,13 +35,13 @@ jobs:
3735
echo "ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/27.2.12479018" >> $GITHUB_ENV
3836
echo "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
3937
40-
# - name: KTLint Check
41-
# run: |
42-
# ./gradlew ktlintCheck
43-
#
44-
# - name: Detekt Check
45-
# run: |
46-
# ./gradlew detekt
38+
- name: KTLint Check
39+
run: |
40+
./gradlew ktlintCheck
41+
42+
- name: Detekt Check
43+
run: |
44+
./gradlew detekt
4745
4846
- name: Test
4947
shell: bash

crypto-jvm-lib/src/main/kotlin/de/gematik/openhealth/crypto/internal/interop/NativeLoader.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ fun loadNativeLibrary() {
4949

5050
val libResUrl = ClassLoader.getSystemResource("$hostOs-$hostArch/$libName")
5151

52-
println("Debug: libResUrl " + libResUrl.path)
52+
val cacheFilePath = getCacheDir() + File.pathSeparator + libName
53+
val cacheFile = File(cacheFilePath)
54+
cacheFile.parentFile.mkdirs()
55+
libResUrl.openStream().copyTo(cacheFile.outputStream())
5356

54-
val tempLib = File.createTempFile("lib", libName)
55-
println("Debug: tempLib " + tempLib.absolutePath)
56-
tempLib.deleteOnExit()
57-
libResUrl.openStream().copyTo(tempLib.outputStream())
58-
59-
System.load(tempLib.absolutePath)
57+
System.load(cacheFile.absolutePath)
6058
}
6159
}
60+
61+
private fun getCacheDir(): String {
62+
val os = System.getProperty("os.name").lowercase()
63+
val userHome = System.getProperty("user.home")
64+
65+
return when {
66+
os.contains("win") -> System.getenv("LOCALAPPDATA") ?: "$userHome\\AppData\\Local"
67+
os.contains("mac") -> "$userHome/Library/Caches"
68+
else -> System.getenv("XDG_CACHE_HOME") ?: "$userHome/.cache"
69+
} + File.pathSeparator + "de.gematik.openhealth.crypto"
70+
}

0 commit comments

Comments
 (0)