korlibs-archive/krypto

"com.soywiz.krypto.SecureRandom.nextBytes" fails with the error "Method myPid in android.os.Process not mocked. See http://g.co/androidstudio/not-mocked for details"

Closed this issue · 1 comments

The error appears in Kotlin multi-platform project when I run the test where com.soywiz.krypto.SecureRandom.nextBytes is used via Task :<sub project name>:testDebugUnitTest

StackTrace

Method myPid in android.os.Process not mocked. See http://g.co/androidstudio/not-mocked for details.
java.lang.RuntimeException: Method myPid in android.os.Process not mocked. See http://g.co/androidstudio/not-mocked for details.
	at android.os.Process.myPid(Process.java)
	at com.soywiz.krypto.PRNGFixes.generateSeed(PRNGFixes.kt:314)
	at com.soywiz.krypto.PRNGFixes.access$generateSeed(PRNGFixes.kt:30)
	at com.soywiz.krypto.PRNGFixes$LinuxPRNGSecureRandom.engineNextBytes(PRNGFixes.kt:243)
	at java.base/java.security.SecureRandom.nextBytes(SecureRandom.java:754)
	at com.soywiz.krypto.SecureRandomJvmKt.fillRandomBytes(SecureRandomJvm.kt:13)
	at com.soywiz.krypto.SecureRandom.nextBytes(SecureRandom.kt:23)
	at kotlin.random.Random.nextBytes(Random.kt:253)
	at kotlin.random.Random.nextBytes(Random.kt:260)
	...

Library version - 2.4.12
Gradle version - 7.0.2
Java version - 11
Kotlin multi-platform plugin version - 1.6.0
Android library plugin - 4.1.2

Yeah, unfortunately that's expected. When running unittets for Android, it uses a mocked version of the android libraries that throw an exception instead of working. Not much we can do other than not running those unittests on CI. I guess we should actually run an emulator instead, but didn't prepare that just yet.