App using NDK (native code) falls. How can i find out why? - android

My app is using NDK (4r-crystax in my case) to proccess images from a camera. Problem is, it falls after few minutes of work. I guess there can be some memory leaks or something like that, but i dont know how to find out where the problem is. This is a log around this error:
04-14 23:07:37.133: INFO/NATIVE CODE(14895): Detection percentage counted.
04-14 23:07:37.163: DEBUG/MDDetectorView(14895): Some debug info
04-14 23:07:37.193: DEBUG/dalvikvm(14895): GC_EXTERNAL_ALLOC freed 19 objects / 872 bytes in 27ms
04-14 23:07:37.283: INFO/NATIVE CODE(14895): Image to proccess loaded.
04-14 23:07:37.493: INFO/ActivityManager(92): Process com.motiondetector (pid 14895) has died.
04-14 23:07:37.493: DEBUG/CameraService(67): Client::~Client E (pid 67, client 0xad08)
04-14 23:07:37.503: INFO/WindowManager(92): WIN DEATH: Window{46590698 com.motiondetector/com.motiondetector.MDMenuActivity paused=false}
04-14 23:07:37.513: ERROR/CameraService(67): getClientFromCookie: client appears to have died
Any ideas? Are there any usefull tools to help me find answer?
Is possible that Android kill on screen activity during proccessing a native code?

If you're using NDK r5 or greater, you can use the ndk-gdb script to run your program and connect to it via GDB. If your native code is crashing, it should drop you into the GDB command line, where you can examine the area of code that's causing the problem.

Related

Find memory use order in Android NDK JNI so file

Nearby I noticed that my Android app often crash because of OOM.
I use Android Studio 3.2.3 Profiler, so I find that native heap are up to 300M.
I want to find the memeory use by every C++ so files, BUT I can not find a tool to accomplish my work.
Any advice is appreciated
adb shell dumpsys mypackage
App Summary
Pss(KB)
------
Java Heap: 11568
Native Heap: 202176
Code: 18576
Stack: 2716
Graphics: 84772
Private Other: 11300
System: 43414
TOTAL USS: 331108
TOTAL: 343727 TOTAL SWAP PSS: 30795

Crash when attempting to show an audience network rewarded video

In our game we are using the Facebook SDK for Unity (v7.5.0), together with rewarded video mediation from IronSource.
The underlying Facebook SDK for Android is v4.11.0.
When attempting to show a rewarded video, our game crashes with this exception:
E/JavaBinder( 1172): !!! FAILED BINDER TRANSACTION !!! (parcel size = 521496)
W/ActivityManager( 1172): Exception when starting activity com.moonactive.coinmaster/com.facebook.ads.AudienceNetworkActivity
W/ActivityManager( 1172): android.os.TransactionTooLargeException: data parcel size 521496 bytes
W/ActivityManager( 1172): at android.os.BinderProxy.transactNative(Native Method)
W/ActivityManager( 1172): at android.os.BinderProxy.transact(Binder.java:503)
W/ActivityManager( 1172): at android.app.ApplicationThreadProxy.scheduleLaunchActivity(ApplicationThreadNative.java:1088)
W/ActivityManager( 1172): at com.android.server.am.ActivityStackSupervisor.realStartActivityLocked(ActivityStackSupervisor.java:2540)
W/ActivityManager( 1172): at com.android.server.am.ActivityStackSupervisor.startSpecificActivityLocked(ActivityStackSupervisor.java:2661)
W/ActivityManager( 1172): at com.android.server.am.ActivityStack.resumeTopActivityInnerLocked(ActivityStack.java:3493)
W/ActivityManager( 1172): at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:2613)
W/ActivityManager( 1172): at com.android.server.am.ActivityStackSupervisor.resumeTopActivitiesLocked(ActivityStackSupervisor.java:5060)
W/ActivityManager( 1172): at com.android.server.am.ActivityStack.completePauseLocked(ActivityStack.java:1687)
W/ActivityManager( 1172): at com.android.server.am.ActivityStack.completePauseLocked(ActivityStack.java:1552)
W/ActivityManager( 1172): at com.android.server.am.ActivityStack.activityPausedLocked(ActivityStack.java:1474)
W/ActivityManager( 1172): at com.android.server.am.ActivityManagerService.activityPaused(ActivityManagerService.java:10204)
W/ActivityManager( 1172): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:547)
W/ActivityManager( 1172): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:4014)
W/ActivityManager( 1172): at android.os.Binder.execTransact(Binder.java:453)
D/ActivityManager( 1172): isAutoRunBlockedApp:: com.moonactive.coinmaster, Auto Run ON
W/ActivityManager( 1172): Force removing ActivityRecord{6a0b73e u0 com.moonactive.coinmaster/com.moon.coinmaster.android.GameActivity t756}: app died, no saved state
Is this a known bug that has been resolved? I could not find any bugs similar to this.
Android SDK target 26+ has changed the way activities can pass data around -- basically they limited the amount of data that can be passed.
Eventually Facebook will release an updated AudienceNetwork.aar file to resolve this issue.
However, the workaround is as follows:
Unity automatically builds your Android project targeting the latest and greatest SDK available. Most likely this is SDK 26 at this point. There is no option in the Unity Editor to override this setting, but there IS an option to override the Minimum SDK Version.
Open your Unity project
Go to File -> Build Settings. Make sure 'Android' is selected.
Click Player Settings, then on the right, click to expand Other Settings.
Take note of the "Minimum API Level". There will be some text and a number, like Android 4.1 'Jelly Bean' (API level 16). The number you want, in my example, is the 16.
Save and close your project.
Navigate to the root of your Unity project, then navigate to the Assets/Plugins/Android folder.
Edit the AndroidManifest.xml file there.
The first line should start out: <?xml ...
The second line should be something like <manifest xmlns:android...
Insert THIS line as the 3rd line:
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
Replace the "16" with whatever minimum Sdk version you want, from Step 4 above. Set the targetSdkVersion to 25, or 24, or whatever number you want -- it must be lower than 26.
Delete the Temp folder from your Unity project root.
Open Unity and rebuild your project.
If you're not on Unity, then just update your targetSdkVersion to 25 or lower -- updating the AndroidManifest.xml in your main project folder. As of this morning, Facebook's latest still shows 4.25.0 and still does not work if you target Android SDK 26.

Troubleshooting android app memory usage problems

I would like to know how I can troubleshoot high memory usage problems of my app on Android. I've search the internet and found out that the DDMS plugin is useful in taking a memory dump of the heap for my app. This however has been useless.
The app "Usage Timelines Free" is showing 94 MBs of memory used, while the DDMS heap dump shows me a total of 8.4 MBs, with the suspected leaks being the resource files.
When I generate a dump from adb (dumpsys meminfo), I get:
Shared Private Heap Heap Heap
Pss Dirty Dirty Size Alloc Free
------ ------ ------ ------ ------ ------
Native 20 8 20 54588 39431 1892
Dalvik 6732 9952 6396 10756 10028 728
Cursor 0 0 0
Ashmem 184 0 184
Other dev 11462 1172 11384
.so mmap 2467 2072 1156
.jar mmap 0 0 0
.apk mmap 48 0 0
.ttf mmap 2 0 0
.dex mmap 1037 0 0
Other mmap 41 16 32
Unknown 46352 292 46348
TOTAL 68345 13512 65520 65344 49459 2620
How can I know what is behind this huge memory consumption. My app is a foreground monitor service which runs forever, with a few activities which are accessed a few times per day.
Thanks.
Minimize your android data usage. Check the link :http://engineroots.games4punk.com/minimize-your-android-data-usage/
DDMS and got a heap memory dump. It only showed 8.4 MBs being used!
Then you are only using 8.4MB of heap space after a complete garbage collection (a net effect of creating the heap dump).
Note that if you ran this on Android 1.x/2.x, MAT will not report space consumed by bitmaps. Always try to dump the heap from an Android 3.0+ device or emulator.
When I generate a dump from adb (dumpsys meminfo), I get:
My guess is that you are running this on an Android 1.x/2.x device or emulator, and you have a lot of bitmap memory. Try running your heap dump and other tests on an Android 3.0+ environment.
Also, bear in mind that adb dumpsys meminfo does not perform a complete garbage collection, whereas dumping the HPROF file does. The Android garbage collector is optimized to minimize CPU utilization and therefore does not attempt to perform a complete garbage collection. Hence, at runtime, the heap is usually filled with garbage that will be reclaimed, as needed, by the GC engine.
You might also wish to read Dianne Hackborn's essay on this subject.

How to debug crashed android native library?

I am runing junit test for native library(C++), native library process crashed and logcat shows:
I/ActivityManager( 161): Force stopping package xxxxx uid=10043
I/ActivityManager( 161): Start proc xxxxx for added application xxxx: pid=1656 uid=10043 gids={1015}
I/TestRunner( 1656): started: testAddressBook(xxxxx.AddressBookTest)
F//system/bin/app_process( 1656): stack corruption detected: aborted
I/ActivityManager( 161): Process xxxxx (pid 1656) has died.
Where xxxxx is the process name.
I try to follow instruction on http://source.android.com/porting/debugging_native.html , but the instruction is confusing:
If it crashes, connect with aproto and run logcat on the device
What is aproto? I can't find it. Nor "stack" tool.
Any suggestion is appreciated!
-Henry
F//system/bin/app_process( 1656): stack corruption detected: aborted
That sounds like you're trashing a local variable. Here's a really popular way to do that:
char localVar[16];
sprintf(localVar, "And this is why sprintf is the devil");
That's not exactly what you asked for, but I hope it helps anyway.

Android phone reboots while executing my own developed application

I developed an Android application that uses many services, including GPS and orientation (compass). The genre of the application is AR (augmented reality) and I'm moving image views around the screen in real-time depending on the phone orientation. However, after a while, the phone freezes for a second and then reboots (Motorola Droid). I'm unable to find any useful log about this event. The log in the Eclipse is cleared after the phone reboots; I use "adb logcat" command to write the log to a file on my PC. The last meaningful rows of information are:
I/ActivityManager( 1272): Displayed activity com.zlatko/.Main: 2656 ms (total 2656 ms)
D/CameraHal( 1050): Zoom callback param1: 65536, param2: 1
D/CameraHal( 1050): processZoom/1:0. stopped=1
D/CameraHal( 1050): Stored Zoom Data/0/1:0
D/dalvikvm( 1272): GC freed 8444 objects / 453552 bytes in 268ms
D/dalvikvm( 1656): GC freed 13158 objects / 456056 bytes in 257ms
D/dalvikvm( 1656): GC freed 23844 objects / 787840 bytes in 98ms
D/dalvikvm( 1656): GC freed 22942 objects / 756408 bytes in 94ms
How can I find the reason for this frustrating behavior? The logs don't offer insight, there are no explicit exceptions thrown, the system is indeterminate (that means, I cannot conclude at what point in time exactly the phone reboots)...
Any recommendation?
The bugreport you linked to has a possible answer in the "KERNEL PANIC CONSOLE LOG" section:
<1>[ 1845.425445] Unable to handle kernel NULL pointer dereference at virtual address 00000000
<1>[ 1845.425811] pgd = cdfd4000
<1>[ 1845.426025] [00000000] *pgd=8d16d031, *pte=00000000, *ppte=00000000
<4>[ 1845.426879] Internal error: Oops: 817 [#1] PREEMPT
<4>[ 1845.427185] Modules linked in: tiwlan_drv sec modem_pm_driver netmux_linkdriver netmux
<4>[ 1845.428283] CPU: 0 Not tainted (2.6.29-omap1 #1)
<4>[ 1845.428497] PC is at SGXGetMiscInfoKM+0x310/0x348
<4>[ 1845.428680] LR is at List_PVRSRV_DEVICE_NODE_ForEach+0x1c/0x2c
Looks similar to this bug report for a Milestone and a post from May 22 2010 on this Motorola support forum.

Categories

Resources