androidc++android-ndkjava-native-interface

Android Wrap Shell Script Doesn't Work as Expected


I have a C library to be integrated with my project, but upon working, I got a stack corruption error. I decided that a malloc debug might help in my case, but can't seemed to configure it properly.

I have tried to follow this tutorial : https://developer.android.com/ndk/guides/wrap-script

I wrote my wrap script, which just contains the following line (I don't even add the malloc debug options yet) :

#!/system/bin/sh
exec "$@"

I put the script on the default resources/lib/{arch} folder and verified that it is indeed got packaged correctly into the apk in the lib folder.

But upon launching the app, it seemed to stuck, and just displayed an empty white screen (I have verified the app working properly without the wrapping shell script, at least until the stack corruption occurred).

I have noticed that the logcat print the following lines :

2019-05-24 16:35:00.524 1927-1942/? W/ActivityManager: Launch timeout has expired, giving up wake lock!
2019-05-24 16:35:00.680 1927-1942/? W/ActivityManager: Process ProcessRecord{e1f6d50 6975:my.package.name/u0a85} failed to attach
2019-05-24 16:35:00.681 1927-1942/? I/ActivityManager: Killing 6975:my.package.name/u0a85 (adj -10000): start time

I had tried using non rooted android 8.1 device, Android Pie, even with Pixel on Android Q, but the result is the same. I tried to move to emulator, but no avail, it fails with the same result. I had tried using both NDK 17c and NDK 19, both produced the same result. I'm working on windows, if that might relevant.

Any help is appreciated.


Solution

  • After trying various alternative, turns out the problem happened because of the different EOL format between windows (my workstation) and linux (the android device). After converting my wrap.sh file EOL fromat from Windows (CR LF) to Unix EOL format (LF), I managed to get it running.