While executing the Aws::InitAPI(Aws::SDKOptions) on Android the application is getting crashed.
Same code works fine for Windows.
I am simplifying the explanation by mentioning the exact steps I followed.
_Note: The SWIG part for generating the JNI Wrapper is test OK and its working fine. SO you can ignore that part while analysis._
_Why is Android failing to initialize? Have I missed anything while building the Android SDK libraries?_
Android
Clang 5.0
cmake -DCUSTOM_MEMORY_MANAGEMENT=0 -DBUILD_ONLY="cognito-identity;core;identity-management;s3;sts" -DTARGET_ARCH=ANDROID -DANDROID_ABI=armeabi-v7a ~/git/aws-sdk-cpp
--------- beginning of crash
2019-03-01 17:10:23.029 22640-22640/com.example.sample.awstester A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x1 in tid 22640 (sample.awstester)
2019-03-01 17:10:23.078 22718-22718/? E/propClient: PropClient failed to load
2019-03-01 17:10:23.110 22719-22719/? I/crash_dump32: obtaining output fd from tombstoned
2019-03-01 17:10:23.111 1191-1191/? I//system/bin/tombstoned: received crash request for pid 22640
2019-03-01 17:10:23.113 22719-22719/? I/crash_dump32: performing dump of process 22640 (target tid = 22640)
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: * *
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: Build fingerprint: 'Verizon/hero2qltevzw/hero2qltevzw:8.0.0/R16NW/G935VVRS8CRK2:user/release-keys'
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: Revision: '15'
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: ABI: 'arm'
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: pid: 22640, tid: 22640, name: sample.awstester >>> com.example.sample.awstester <<<
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: Cause: null pointer dereference
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: r0 00000001 r1 00000001 r2 d13ea1a4 r3 00000041
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: r4 ef9c9234 r5 00000000 r6 00000000 r7 ffd0d7f0
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: r8 0000004a r9 eef74000 sl ffd0d850 fp ffd0d548
2019-03-01 17:10:23.114 22719-22719/? A/DEBUG: ip d13dcbe4 sp ffd0d540 lr d102ddbc pc d114eac8 cpsr 600f0010
2019-03-01 17:10:23.153 22719-22719/? A/DEBUG: backtrace:
2019-03-01 17:10:23.153 22719-22719/? A/DEBUG: #00 pc 001f9ac8 /data/app/com.example.sample.awstester-K9sGZKePIlELp6UedDMOPw==/lib/arm/libaws-cpp-sdk-core.so (_ZN3Aws5Utils6Memory25InitializeAWSMemorySystemERNS1_21MemorySystemInterfaceE+84)
2019-03-01 17:10:23.153 22719-22719/? A/DEBUG: #01 pc 000d8db8 /data/app/com.example.sample.awstester-K9sGZKePIlELp6UedDMOPw==/lib/arm/libaws-cpp-sdk-core.so (_ZN3Aws7InitAPIERKNS_10SDKOptionsE+44)
2019-03-01 17:10:23.153 22719-22719/? A/DEBUG: #02 pc 00069b95 /data/app/com.example.sample.awstester-K9sGZKePIlELp6UedDMOPw==/lib/arm/libAWSServicesProviderD.so (_ZN19AWSServicesProviderC1Ev+56)
2019-03-01 17:10:23.153 22719-22719/? A/DEBUG: #03 pc 000695f5 /data/app/com.example.sample.awstester-K9sGZKePIlELp6UedDMOPw==/lib/arm/libAWSServicesProviderD.so (Java_com_testdomain_AWSServicesProviderWrapper_AWSServicesProviderWrapperJNI_new_1AWSServicesProvider+40)
The stack trace points to this function:
void InitializeAWSMemorySystem(MemorySystemInterface& memorySystem)
{
#ifdef USE_AWS_MEMORY_MANAGEMENT
if(AWSMemorySystem != nullptr)
{
AWSMemorySystem->End();
}
AWSMemorySystem = &memorySystem;
AWSMemorySystem->Begin();
#else
AWS_UNREFERENCED_PARAM(memorySystem);
#endif // USE_AWS_MEMORY_MANAGEMENT
}
Which is only called if you specify a memory manager in the SDKOptions. So, try disabling that and see if that's the problem.
If you're not using a memory manager, then I suspect something is broken in your packaging, as in the wrong lib/so is getting loaded.
Thank you so much @marcomagdy for your inputs. I made sure that no custom options are set.
Verified following,
I want to build the Android SDKs for ARMv7s and ARM abi's. Took care of this while building the SDKs too.
What am I missing?
After using this -DCUSTOM_MEMORY_MANAGEMENT=0 and re-generating the Android libraries, the error got changed. Now the application is getting crashed in
/data/app/com.example.sample.awstester-euMjrYwTpQTNqxTzSww1zQ==/lib/arm/libaws-cpp-sdk-core.so (_ZNKSt6__ndk18functionIFNS_10shared_ptrIN3Aws5Utils6Crypto22SymmetricCipherFactoryEEEvEEclEv+24)
--------- beginning of crash
2019-02-14 14:49:21.433 5775-5775/com.example.sample.awstester A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7 in tid 5775 (sample.awstester)
2019-02-14 14:49:21.467 6395-6395/? E/propClient: PropClient failed to load
2019-02-14 14:49:21.492 6396-6396/? I/crash_dump32: obtaining output fd from tombstoned
2019-02-14 14:49:21.496 959-959/? I//system/bin/tombstoned: received crash request for pid 5775
2019-02-14 14:49:21.497 6396-6396/? I/crash_dump32: performing dump of process 5775 (target tid = 5775)
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: * *
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: Build fingerprint: 'samsung/star2qlteue/star2qlteue:8.0.0/R16NW/G965U1UEU3ARL1:user/release-keys'
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: Revision: '14'
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: ABI: 'arm'
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: pid: 5775, tid: 5775, name: sample.awstester >>> com.example.sample.awstester <<<
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: Cause: null pointer dereference
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: r0 ffab9084 r1 00000007 r2 00000004 r3 00000000
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: r4 ffab9138 r5 00000000 r6 00000000 r7 ffab9270
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: r8 0000004a r9 ed27b000 sl ffab92d0 fp ffab8fc8
2019-02-14 14:49:21.498 6396-6396/? A/DEBUG: ip d002e22c sp ffab8fc0 lr cfc8b210 pc cfc8b65c cpsr 200f0010
2019-02-14 14:49:21.512 6396-6396/? A/DEBUG: backtrace:
2019-02-14 14:49:21.512 6396-6396/? A/DEBUG: #00 pc 000c665c /data/app/com.example.sample.awstester-euMjrYwTpQTNqxTzSww1zQ==/lib/arm/libaws-cpp-sdk-core.so (_ZNKSt6__ndk18functionIFNS_10shared_ptrIN3Aws5Utils6Crypto22SymmetricCipherFactoryEEEvEEclEv+24)
2019-02-14 14:49:21.512 6396-6396/? A/DEBUG: #01 pc 000c620c /data/app/com.example.sample.awstester-euMjrYwTpQTNqxTzSww1zQ==/lib/arm/libaws-cpp-sdk-core.so (_ZN3Aws7InitAPIERKNS_10SDKOptionsE+1380)
2019-02-14 14:49:21.512 6396-6396/? A/DEBUG: #02 pc 00069b45 /data/app/com.example.sample.awstester-euMjrYwTpQTNqxTzSww1zQ==/lib/arm/libAWSServicesProviderD.so (_ZN19AWSServicesProviderC1Ev+72)
2019-02-14 14:49:21.512 6396-6396/? A/DEBUG: #03 pc 00069595 /data/app/com.example.sample.awstester-euMjrYwTpQTNqxTzSww1zQ==/lib/arm/libAWSServicesProviderD.so (Java_com_testdomain_AWSServicesProviderWrapper_AWSServicesProviderWrapperJNI_new_1AWSServicesProvider+40)
Can anyone help in understanding the cause of this?
@marcomagdy I read on other GITHub issue post #342. A question was asked 'is anywhere else in your application using libcurl or openssl?' and answer to this was 'if you are, you have to tell the SDK not to via the SDKOptions.'.
My application is getting crashed while InitAPI is getting called on Android, the same code works fine on Windows. My application also uses liburl internally for other REST calls. Reading this post, I modified following in my code, but no luck,
_HttpOptions httpOptions;
httpOptions.initAndCleanupCurl = false;
httpOptions.installSigPipeHandler = false;
m_SDKOptions.httpOptions = httpOptions;_
_CryptoOptions cryptoOptions;
cryptoOptions.initAndCleanupOpenSSL = false;_
_/*Added CryptoOptions because in log I saw app crashed @ line# 75 (inside if condition below) in Aws.cpp file, but no luck
if(options.cryptoOptions.sha256Factory_create_fn)
{
Aws::Utils::Crypto::SetSha256Factory(options.cryptoOptions.sha256Factory_create_fn());
}
*/_
_sdkOptions.cryptoOptions = cryptoOptions;_
Make Aws::InitAPI(..) the first thing your application calls when it starts. And similarly Aws::ShutdownAPI() the last thing your application calls.
In other words, don't call init right before you need to call some AWS functionality. Do it at the very beginning.
Thank you @marcomagdy . The calls of Aws::InitAPI(..) is the first to be called in my C++ library and Aws::ShutdownAPI() the last one. Initialization of classes which uses libCurl is after the AWS initialization.
The SDK also initializes the crypto libs (in addition to libcurl). It should be called early in your application not just your library.
Also, make sure that you are not linking two different versions of the crypto/ssl libs. Ones brought in by the SDK and others directly by your application.
@marcomagdy Thanks again. I might be writing too much, but its just to help understand the details.
Application is divided in 3 layers,
The very first call I make to my static lib project is to initialize the AWS using InitAPI(..) method and till then nothing is instantiated from my static library project.
Once its initialized, I make call to APIs like _authenticateUser(...), listS3Bucket(...)_ of my library.
Somehow, everything works fine on Windows, but Android its crashing.
Did you meant that the libCurl is internally initializing or using OpenSSL libraries?
I haven't deployed any other library (.so or .a) apart from AWS SDK libs , libCurl and my own business logic library in apk package.
Just For your knowledge, the intention behind having this architecture is to avoid repetitive business logic on multiple platforms.
I don't know much about the SDK, but can you try setting the following option?
cryptoOptions.sha256Factory_create_fn = nullptr;
To see what happens if that if statement is not entered.
@martinkbrown I already tried setting up the value to nullptr just considering if by default it's holding some value then this would reset it back. But no luck.
@marcomagdy : Further to this, today I tried by removing entire libCurl dependency from my project and rebuilding the application, but same place its getting crashed still.
Anything you can help in?
As suggested by @marcomagdy I made changes in my application to make the 'Aws::InitAPI(sdkOptions);' at the very beginning before making any call (be it AWS or any other library) and the call got succeeded. In my application I was using making the call to get the user signed-in to Azure AD using Microsoft's IDP log-in page and then was initializing the AWS library.
So conclusion is, 'InitAPI' has to be called at very beginning of application launch and 'ShutdownAPI' just before closure of application.
P.S. Thanks @marcomagdy :)
Most helpful comment
Make Aws::InitAPI(..) the first thing your application calls when it starts. And similarly Aws::ShutdownAPI() the last thing your application calls.
In other words, don't call init right before you need to call some AWS functionality. Do it at the very beginning.