Describe the bug
I'm getting crash on connecting to MQTT using ALPN.
06-02 09:47:27.824 17143-17143/com.appcard.androidterminal E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.appcard.androidterminal, PID: 17143
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.appcard.androidterminal-2/base.apk"],nativeLibraryDirectories=[/data/app/com.appcard.androidterminal-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libconscrypt_jni.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:988)
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)
at com.amazonaws.mobileconnectors.iot.AWSIotSslUtility.getSocketFactoryWithKeyStore(AWSIotSslUtility.java:69)
at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.connect(AWSIotMqttManager.java:803)
at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.connectUsingALPN(AWSIotMqttManager.java:735)
To Reproduce
A code sample or steps:
mMqttManager = new AWSIotMqttManager(thingName, thingUrl);
mMqttManager.setMaxAutoReconnectAttempts(-1);
KeyStore clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(CERTIFICATE_ID,
keystorePath, KEYSTORE_NAME, KEYSTORE_PASSWORD);
mMqttManager.connectUsingALPN(clientKeyStore, mqttCallback);
Which AWS service(s) are affected?
AWS IoT
Environment Information (please complete the following information):
Additional context
Connect on port 8883 works fine.
Can you please share more context around the snippet? The snippet you have shared works fine for me and does not reproduce the error.
Crash happens in NativeCryptoJni.init(), on this line:
System.loadLibrary("conscrypt_jni");
There are other JNI libs used in the project.
Path to them defined in app build.gradle
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
defaultConfig includes
ndk {
abiFilters "armeabi"
}
May this be the reason?
I would strongly suspect that to be the case. Modifying the default source set configuration to point to different directory for prebuilt .so files changes the place where Gradle looks to gather file for each component of the source set and being unable to locate libconscrypt_jni.so throws up the stack trace you shared. Could you try to reproduce this issue in the following sample app with the setting that you have for jni libraries :
https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSub
You can replace the connect method in the sample app with connectUsingALPN without having to change anything else. Thanks!
@desokroshan Can't build the sample app in Android Studio 3.4.1. Getting this error:
Gradle sync failed: Plugin with id 'com.android.application' not found.
Please suggest.
@beersheba I have created a PR, referenced above, updating the gradle version in the sample to the latest. Can you please try it out confirm if it works?
@beersheba I have created a PR, referenced above, updating the gradle version in the sample to the latest. Can you please try it out confirm if it works?
Yes, branch update-pubsub-sample can be built on my side
@desokroshan crash is reproduced with AndroidPubSub project.
It happens on adding
ndk {
abiFilters "armeabi"
}
to defaultConfig of build.gradle
@desokroshan can you please check it and provide an update?
@beersheba Can you elaborate on why you need this directive? I am not very familiar with it so can't comment on a workaround for handling this. What is clear though is that it's obstructing linker from locating the required binaries.
Because I develop for armeabi device and use JNI libs (*.so).
All my libs reside in src/main/jniLibs/armeabi directory.
I use this directive since Gradle 4, otherwise, my libs are not available to use.
Unfortunately, Google currently only has support for four architectures on their conscrypt_jni.so library. Exclusively filtering for 'armeabi' will not include any binary in your APK, causing your app to be unable to locate the library. I would suggest removing the abiFilter to allow the binaries to be zipped with APK and seeing if an armeabi device is compatible with any.
@raphkim thank you very much!
I found a workaround:
and connectUsingALPN works )
Most helpful comment
Unfortunately, Google currently only has support for four architectures on their conscrypt_jni.so library. Exclusively filtering for 'armeabi' will not include any binary in your APK, causing your app to be unable to locate the library. I would suggest removing the abiFilter to allow the binaries to be zipped with APK and seeing if an armeabi device is compatible with any.