question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android unit tests with Conscrypt

See original GitHub issue

I am unable to run android unit tests when using org.conscrypt:conscrypt-android:2.0.0 as my dependency. I am running into following error when trying to add OpenSSLProvider as a Security Provider :

java.lang.UnsatisfiedLinkError: no conscrypt_jni in java.library.path

	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at org.conscrypt.NativeCryptoJni.init(NativeCryptoJni.java:28)
	at org.conscrypt.NativeCrypto.<clinit>(NativeCrypto.java:65)
	at org.conscrypt.OpenSSLProvider.<init>(OpenSSLProvider.java:60)
	at org.conscrypt.OpenSSLProvider.<init>(OpenSSLProvider.java:53)
	at org.conscrypt.OpenSSLProvider.<init>(OpenSSLProvider.java:49)

Since unit tests run on the local machine, it fails to link native libraries that are compiled for different platform(mac in my case)? Is there a workaround/solution available for this?

PFA a simple android project where running the unit test reproduces the issue ConscryptRepro.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
icksonbcommented, Mar 26, 2021

I tried this:

dependencies {
    ...
    compileOnly 'org.conscrypt:conscrypt-openjdk-uber:2.5.1'
    runtimeOnly 'org.conscrypt:conscrypt-android:2.5.1'
    testImplementation 'org.conscrypt:conscrypt-openjdk-uber:2.5.1'
    ...
}

and it worked for me.

1reaction
flooeycommented, Mar 28, 2019

Ah, I see the problem. Yeah, as far as I know (or have been able to find on the Internet), there isn’t a simple solution to this.

As you note, the local unit tests run on your local machine in a JVM, rather than in an Android environment. As a result, the Android dependency (which is packaged differently and such) doesn’t work out of the box, but the OpenJDK dependency does. (If you change your dependency to org.conscrypt:conscrypt-openjdk-uber:2.0.0 in the sample project, you can see that it works.)

Unfortunately, I wasn’t able to find a good way to deal with that. The main things people mentioned were:

  • Skip the local unit tests and only use Android unit tests, so you never deal with this situation
  • Rewrite the classpath for your tests in gradle to remove the Android dependency and replace it with the OpenJDK one
  • Use LD_LIBRARY_PATH to point the library loader at the Android library, which will probably work (since we don’t use much from the NDK) but doesn’t really come with any guarantees

Sadly, I don’t think this is something we can improve on the Conscrypt side. Fundamentally, native library loading works differently in Android and on a JVM, and we need to package things so they work on Android in the Android distribution. If you find that one of those solutions works well for you, though, we could add some docs that show how it’s done to help future users.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conscrypt - Android Open Source Project
The Conscrypt module accelerates security improvements and improves device security without relying on OTA updates. It uses Java code and a native library ......
Read more >
Include Unit and Functional Tests | Android Open Source Project
Unit tests can be executed standalone, but functional tests should be executed by using Trade Federation itself; they require an Android device.
Read more >
Android Platform Testing | Android Open Source Project
A platform test typically interacts with one or more of the Android system services, or Hardware Abstraction Layer (HAL) layers, exercises the ...
Read more >
Test Development Workflow | Android Open Source Project
Stay organized with collections Save and categorize content based on your preferences. To integrate tests into a platform continuous testing ...
Read more >
Self-Instrumenting Tests Example | Android Open Source Project
This specifies the Trade Federation test class to use to execute the test and passes in the package on the device to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found