Eclipse ADT - Native debug - android

On my Windows 7 platform, I have the latest version of adt bundle (20140321) and ndk (r9d) installed. The installation is as clean as it gets. The environment variables NDK_ROOT, PATH, etc. are all defined properly.
The application that I am working on has some native code that gets built with armeabi-v7a ABI. The app platform is andorid-19. Project settings define build as "ndk-build NDK_DEBUG=1."
From Eclipe, when I debug my application on my samsung tablet as "Android Java Application," everything works as expected. However, when I try to debug the app as "Android Native Application," I get the following error:
Attempting to connect debugger to 'com.mycomp.myapp' on port 8604
gdbserver output:
Cannot attach to lwp 28275: Operation not permitted (1)
Exiting
Verify if the application was built with NDK_DEBUG=1
The application runs fine on the device though.
I have looked at various messages on stackoverflow. However, I could not find any concrete step to fix this problem. Would appreciate if you can guide me in the right direction. Regards.

I have same problem. After wasting some time I found that when I return my simple function without any operation problem does not occurs.
void dmpBuffer(char* msg, unsigned char* buffer, int buffLen)
{
//return;
char szDumpBuffer[128];
for(int i=0; i<buffLen; i++)
sscanf(&szDumpBuffer[i*2], "%02X", buffer[i]);
LOGE("%s:%s", msg, szDumpBuffer);
}
maybe it is because of memory problems.
Update:
As I had Guessed it was memory problem.
My BIG mistake was using sscanf instead of sprintf!!!
My problem solved.

Related

Google Test: Android vs Linux EXPECT_DEATH Tests

I am running into a problem while working on unit testing my system that I don't even know how to approach debugging. My code operates either on a linux machine with mock input or on an android device. I am using Google Test to run unit tests on it. I have it set up so that a call to "$ make all" will run my unit tests on both the linux machine and through adb shell on my device. This part is working fine.
However, when I introduce a test with EXPECT_DEATH(...) in it, the linux build runs the same as usual but the android build stops at that test and appears to freeze (I have to Ctrl + C to stop execution). As I said, I'm not at all sure how to try to fix this problem as I can't seem to get any output or error messages from it.
If you have any suggestions please let me know. If there is critical information I'm leaving out about my build, comment and I can add that in.
Edit:
When I run the function that I'm expecting to die outside of EXPECT_DEATH the same behavior occurs. This indicates that the assert in the function is working and EXPECT_DEATH is not doing what it should to handle that.
Before: (Works fine on Linux build but not on Android build)
EXPECT_DEATH(pObj->fxn(deathlyParam), "");
After: (Same result on Android build; core dump error due to assert on Linux build which is what I would expect both times from the Android build)
EXPECT_EQ(pObj->fxn(deathlyParam), 0);
For reference, fxn() looks something like this:
int fxn(int param)
{
assert(param != deathlyParam);
...
}
In light of this, it looks more like assert is acting improperly and not causing the error it should be. Therefore, EXPECT_DEATH has nothing to expect.
OK I figured it out. The problem was indeed arising from the assert in my function and not from EXPECT_DEATH. I don't know if this is just a feature of the project I'm working on (which had been developed for some time before I got to it) or if it is true of any Android build but NDEBUG was undefined, as in a release build. When I added "APP_OPTIM := debug" to my Application.mk file, it worked perfectly.
I am still a little confused why an assert would seemingly halt execution when NDEBUG is undefined. Aren't asserts supposed to be ignored entirely in release builds?
Credit to this question and answer for the solution.

Provisioning Nymi band from Android app

I am trying to provision the Nymi band from my android app. I am using the sample code from the Nymi Android SDK 2.0 (Can be downloaded from here:). I removed all the code related to the Nymulator(Nymi band emulator). I want to test the provisioning with the real Nymi band. However,when I click the provision button, the app get crashed. I tried to debug it with the exception breakpoints and I got the "getsockopt errno 88" error in my debugger:
I am attaching the screenshot too.
I did some research on google , and found that the errno 88 is
#define ENOTSOCK 88 /* Socket operation on non-socket */
During the app launch, I see the following message in the Debug Console:
Connected to the target VM, address: 'localhost:8604', transport: 'socket'
which I think,the connection to socket is fine. I am not sure,what makes the socket connection go wrong later.
This is what I see in my LOgCat after I click the provision button:(I am posting only some part of the error message,because the error message in Logcat is way too long)
Edit: I added some breakpoints,and I found where the app is crashing. I found this code:
try {
System.loadLibrary("_nymi_sdk_net");
_loaded = true;
} catch (UnsatisfiedLinkError var6) {
return false;
}
At system.load library, I am getting the error.
Edit 2: I changed the libraries from net to native ,as net is for emulators and native is for device. This time new error occurs at the same line:System.loadLibrary("_nymi_sdk");
Screenshot:
(Disclaimer: I know nothing of this SDK or the band, and this answer is just a speculation. And I've deleted my earlier answer as it was a missed shot in the dark.)
There is a minor hint in the SDK's README.md:
Prerequisites:
Android Development:
[...]
To use the BasicExample app with a Nymi Band, the NCL library in Examples\BasicExample\libs must be replaces with the native library in
NCL\native\libs
You must remove all files and folders from BasicExample\libs and copy all files from NCL\native\libs there instead.
(I wonder why they didn't emphasize this much harder...)
So the libs folder should contain the following folders and files:

Unforunately OpenCV Manager has stopped in OpenCV 2.4.3 for android 4.2 ( Mac OSX 10.7)

I have a problem running openCV samples project (3 - 4). Everytime that I run the program, I found the problem "Unforunately OpenCV Manager has stopped" displays in my Android emulator.
The problem occurs everytime that I call
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
I followed this page
http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html
This is the Warning Message that I have
/Applications/eclipse-android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld:
warning: hidden symbol '__aeabi_atexit' in
./obj/local/armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced
by DSO
/Applications/eclipse-android/OpenCV-2.4.3-android-sdk/sdk/native/jni/../libs/armeabi-v7a/libopencv_java.so
Logcat (from OpenCV sample4):
gralloc_goldfish, org.opencv.samples.tutorial4 Emulator without GPU
emulation detected.
Note:
I set java compliance level to 1.6 since I have some problem compiling OpenCV c++ file.
(followed this page: 'Must Override a Superclass Method' Errors after importing a project into Eclipse)
I install adb with both OpenCV_2.4.3_binary_pack_armv7a.apk and OpenCV_2.4.3_Manager_2.0_armeabi-v7a.apk
I used Samsung Galaxy S as my cellphone emulator
I run into the same problem:
hidden symbol '__aeabi_atexit' armeabi-v7a/libgnustl_static.a(atexit_arm.o) is referenced by DSO
I am using the opencv test in jni, with an application that worked before I have added it.
I have tried to change the ARMv7-A machine to armeabi in the "Application.mk'
I have also tried to add all the paths mentioned above to the Project -> Properties -> C/C++ General -> Path and Symbols.
It didn't work.
Thanks to my team leader, I have found the solution:
in Application.mk, You need to change the APP_STL := gnustl_static
to APP_STL := gnustl_shared. This is because the lib apparantly was compiled in shared instead of static.
In addition, add to the loadlibrary area the lib: System.loadLibrary("gnustl_shared");
This should be done in a static area, as followed:
static {
try{
System.loadLibrary("gnustl_shared");
//To do - add your static code
}
catch(UnsatisfiedLinkError e) {
Log.v(TAG, "Native code library failed to load.\n" + e);
}
catch(Exception e) {
Log.v(TAG, "Exception: " + e);
}
}
That's it! it solved my problem...
Hope it helped.
Inbal
Your problem might simply be emulator itself, try to get an actually device to test on.
There are a lot of things that emulator can't handle.
If you use Android 4.2 than change to 4.0.3 or to 4.1. There is a bug about that: http://code.opencv.org/issues/2537
I had problems this days running the two tutorials too.
On my machine I installed OpenCV 2.4.3, Android-sdk-21 and Android-ndk-r8c, Eclipse Juno. I perform my tests on an Asus Transformer tf101g running Android 4.0.3.
When I ran the tutorials it failed with a strange ClassNotFoundException. Checking the project properties I realized that the two projects look for headers in a wrong place. Go to Project -> Properties -> C/C++ General -> Path and Symbols. Here you can see the include directories used in the jni file.
The NDKROOT environment variable was not set in my system and I had to manually set it to point to the NDK root folder.
Then I had to change the stl include from
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/include
to
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include
Hope this can help.
I too struggled with this for almost 4 hours, including downgrading target to 4.0.3 but did not work.
The solution was to download the latest openCV manager from google play to your device directly.
I got the same error and thought even though late,the solution might help for some in future.
The error "Unforunately OpenCV Manager has stopped" pops up if its version is not supported by the android device hardware(like armeabi-v7a (ARMv7-A + NEON) or Intel x86,etc). uninstall the current Manager and install the proper one.
Paste the following code before onCreate() Method:
static {
System.loadLibrary("opencv_java3");
}
it worked for me.

Problems with build.xml when using the Android ADK to communicate with an Arduino Mega ADK

So a few days ago I got my hands on an Arduino Mega ADK board, and the last couple of nights I have been setting up my development environment, getting to grips with the tools etc. The tools and libraries all work fine, for example I can get a program written in the Processing IDE to compile and run on an Asus Eee Pad Transformer TF101 running Android 4.03. But when I get it to try to compile and run one of the pre-written examples, it gives me a compiler error:
Android SDK Tools Revision 20
Installed at C:\NVPACK\android-sdk-windows
Project Type: Application
Project Target: Android 2.3.3
API level: 10
Library dependencies:
No Libraries
API<=15: Adding annotations.jar to the classpath.
Merging AndroidManifest files into one.
Manifest merger disabled. Using project manifest only.
No AIDL files to compile.
No RenderScript files to compile.
Generating resource IDs...
Generating BuildConfig class.
BUILD FAILED
C:\NVPACK\android-sdk-windows\tools\ant\build.xml:680: The following error occurred while executing this line:
C:\NVPACK\android-sdk-windows\tools\ant\build.xml:693: Compile failed; see the compiler error output for details.
Total time: 7 seconds
And that's all the console seems to output as well, which is rather frustrating! As far as I'm aware all of my SDK versions, tools and plugins are all up to date. I've tried this using a Linux partition I have on my hard drive and it produces the same error message, although it mentions a problem with the package com.Android.future.UsbAccessory. Given what I've seen, it seems that the problem is with the tools, either my directory structure doesn't match up to what the correct setup is, or something else is wrong :S. If anyone has had similar problems, some help would be smashing! (For the record, my setup was done using the instructions on the Arduino website, although I already had the Android SDK tools installed).
Will Scott-Jackson
It sounds like your haven't added in the support library to your project and/or you haven't downloaded it into your Android SDK.
The ADK1 demokit app targets API Level 10 (Android 2.3.3); That means you need to use the support libraries in your project and that's why the compiler is complaining about level 10 library dependencies not being available. The support libraries are a separate download in the SDK Manager, so you might not have them in your development environment.
In Android API Level 12 and higher, the USB Accessory protocol was added to the framework API, so there are two different ways to use the accessory protocol. So, you don't have to use the support libraries if you are targeting Honeycomb and higher versions, but you'll have to update the demokit app code to make this work.
Hope this helps.
So I've double checked my setup and started working on a project I had in mind, it seems to import the libraries appropriately. So far so good, but when I input:
ArduinoAdkUsb arduino;
void setup() {
arduino = new ArduinoAdkUsb(this);
//Other UI initialisation etc.
}
I get this error:
##name## ##version## by ##author##
FATAL EXCEPTION: Animation Thread
java.lang.NoClassDefFoundError: com.android.future.usb.UsbManager
at cc.arduino.ADKCommunication.<init>(Unknown Source)
at cc.arduino.ArduinoAdkUsb.<init>(Unknown Source)
at
processing.android.test.sketch_120730a.
sketch_120730a.setup(sketch_120730a.java:48)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:856)
After the app has been built and installed onto the Android tablet I am using. Any thoughts how I can over come this? From what I can tell, this has no problem finding com.android.future.usb.manager to compile and install the program, but once it tries to run it can find it.
Based on this tutorial from http://stream.tellart.com/controlling-arduino-with-android/
In the examples RGB_Arduino the name, version and author variables are set at the top of the sketch.
Try adding in this section of code at the top of your arduino sketch just underneath the library imports
// accessory descriptor. It's how Arduino identifies itself to Android
char applicationName[] = "Mega_ADK"; // the app on your phone
char accessoryName[] = "Mega_ADK"; // your Arduino board
char companyName[] = "Freeware";
// make up anything you want for these
char versionNumber[] = "1.0";
char serialNumber[] = "1";
char url[] = "http://labs.arduino.cc/adk/"; // the URL of your app online
//initialize the accessory:
AndroidAccessory usb(companyName, applicationName,
accessoryName,versionNumber,url,serialNumber);

Eclipse & Seqoyah - Tries to connect to gdbserver before application is launched on device

I've setup my Eclipse to debug the Native side of my application using Eclipse & Seqoyah and added the appropriate C/C++ Application Debug Configuration.
The problem is it seems that Eclipse is trying to initiate a connection with the applications GDB server even before it launches it. I'm not to sure how to change the order in which Eclipse tries to do things with Debug Configurations. Any help would be appreciated (as always).
http://wiki.eclipse.org/Sequoyah/ndk_guide
31-gdb-set confirm off
31^done
(gdb)
32-gdb-set width 0
32^done
(gdb)
33-gdb-set height 0
33^done
(gdb)
34-interpreter-exec console echo
34^done
(gdb)
35-gdb-show prompt
35^done,value="(gdb) "
(gdb)
36-gdb-set auto-solib-add on
36^done
(gdb)
37-gdb-set stop-on-solib-events 0
37^done
(gdb)
38-gdb-set stop-on-solib-events 1
38^done
(gdb)
39-target-select remote localhost:5039
&"Remote communication error: Connection reset by peer.\n"
39^error,msg="Remote communication error: Connection reset by peer."
(gdb)
40-gdb-exit
40^exit
Remote communication error: Connection reset by peer.
I managed to solve this one.
There should be two Debug Configurations available to your Java / C++ Native project. The first is for the Java side of things and the second is for the C++ side of things.
Make sure you have setup your environment according to: http://wiki.eclipse.org/Sequoyah/ndk_guide
Set a breakpoint just after the JNI Shared library is added or in your Activities onCreate.
Debug your application using its default debug configuration.
In a shell navigate to your project directory and issue $NDK/ndk-gdb (where $NDK is the location of your Android Native Development Kit).
Debug your application using its Native debugger that you created in the Sequoyah guide.
If all goes well you should be able to step into JNI code and when your application crashes, see where in your source it crashed.
I've not yet found a way to setup through the actual source yet, if anyone does please post here.

Categories

Resources