Setting up ofxOsc on Android (and general debugging on Android)

Hi,

(Note: if anyone has an example app that runs on android and uses ofxOsc, I’d love to see it)

I’ve been trying to set up OF on android so I can make an ofxOsc app to communicate between the android and my mac. I am completely new to Eclipse and Android development although I have done a number of OF apps on osx.

I am able to build the app without trouble. However, when I run the app it crashes immediately. I put in some log statements and tried to find the bug by commenting out various lines. When I commented out this line:

sender.setup(HOST, PORT);

the app stopped crashing (I made sure nothing used the sender after that so it wouldn’t crash). Adding that line back in makes the app crash. The error is always

12-24 14:31:55.069: A/libc(7235): Fatal signal 6 (SIGABRT), code -6 in tid 7277 (GLThread 43430)

I am used to debugging in C++, but I am struggling getting useful debug information back from the application. I’ve tried looking up a lot of ideas for how to setup debugging in eclipse and even using logcat and ndk-stack to try to get something useful but am failing. In fact, it doesn’t even seem like eclipse is stopping at the breakpoints I set.

I’m wondering if anyone out there with more experience building these apps on android and can give me advice for how to try to track down the bug. Or if anyone has a working ofxOsc app example on android. Or any other advice.

Thanks in advance,
Patrick

“Fatal signal 6 (SIGABRT), code -6” means the UI hanging up (ANR).

Hi,

Thanks for the idea! I tried to look for ANR problems. I set show all ANRs in debug settings on the phone and haven’t been able to find anything that says that the particular abort is an ANR. But I also am completely failing at getting a backtrace or any useful debug information. I’ve tried in both eclipse and android studio and can’t seem to get any useful debugging info.

Do you have any more specifics? Or perhaps are there any other ideas out there?

Thanks a million,
Patrick

I don’t use debugging but traditional line commenting. And I didn’t implement any ofxOsc app. So unfortunately I don’t have any idea about these subjects.

The only thing I know around your issues is the error code you are getting is an ANR. So I would focus on connection, threading and encoding problems. First of all I would check the manifest permissions are correct or not. You may need to add

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

permissions into your manifest.

Hey,

I was confronted with the same issues, adding the right permissions fixed the SIGABRT error!

You guys are completely right!

Rancs, I went and added some permissions, and it compiled immediately. I will edit this answer with my code and permissions in case anyone is searching for a solution in the future.

THANK YOU!

EDIT:
To get OSC messages sent from my android (samsung s5) to osx (macbrook pro running 10.10.4 yosemite), I set these permissions in AndroidManifest.xml:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>

Then make sure to add the addon to addons.make. Mine says:

ofxAndroid
ofxAccelerometer
ofxOsc

Then, the only thing necessary in the .h file is:

#pragma once

#include "ofMain.h"
#include "ofxAndroid.h"
#include "ofxOsc.h"

#define HOST "XXX.XXX.X.XXX"
#define PORT 12345

class ofApp : public ofxAndroidApp{
    
    public:
        
        void setup();
        void update();
        void draw();
        
        void keyPressed(int key);
        void keyReleased(int key);
        void windowResized(int w, int h);

        void touchDown(int x, int y, int id);
        void touchMoved(int x, int y, int id);
        void touchUp(int x, int y, int id);
        void touchDoubleTap(int x, int y, int id);
        void touchCancelled(int x, int y, int id);
        void swipe(ofxAndroidSwipeDir swipeDir, int id);

        void pause();
        void stop();
        void resume();
        void reloadTextures();

        bool backPressed();
        void okPressed();
        void cancelPressed();

        ofTrueTypeFont font;
        ofxOscSender sender;
};

And then the .cpp file should have this where I left out functions that were not modified from the androidEmptyExample at all:

#include "ofApp.h"
#include <unistd.h>

//--------------------------------------------------------------
void ofApp::setup(){
    ofBackground(40, 100, 40);
    ofSetFrameRate(60);
    // open an outgoing connection to HOST:PORT
    sender.setup(HOST, PORT);
}

//--------------------------------------------------------------
void ofApp::draw(){
    // display instructions
    string buf;
    buf = "sending osc messages to" + string(HOST) + ofToString(PORT);
    ofDrawBitmapString(buf, 10, 20);
    ofDrawBitmapString("move the mouse to send osc message [/mouse/position <x> <y>]", 10, 50);
    ofDrawBitmapString("click to send osc message [/mouse/button <button> <\"up\"|\"down\">]", 10, 65);
    ofDrawBitmapString("press A to send osc message [/test 1 3.5 hello <time>]", 10, 80);
    ofDrawBitmapString("press I to send a (small) image as a osc blob to [/image]", 10, 95);
}

//--------------------------------------------------------------
void ofApp::touchDown(int x, int y, int id){
    ofxOscMessage m;
    m.setAddress("/mouse/touch");
    m.addIntArg(id);
    m.addStringArg("down");
    sender.sendMessage(m, false);
}

where most of that is just from the ofxOscSenderExample. I modified the receiver example to handle the “/mouse/touch” but that’s about it. It was really simple once I was able to get things compiled. But hopefully this helps someone else who was horribly lost like me sometime in the future.

Thanks for everyone in the community who helped me out.

1 Like