From GNU Radio
Jump to: navigation, search

Help and hints for building GNU Radio Android Apps[edit]

Take everything below with a grain of salt. This is basically a copy-paste effort from some notes that I took without any cleanup.

The general structure/layers of GNU Radio apps on Android. We design the user interface as a Java application that calls into the flowgraph that runs in C++ through the JNI layer.

Gr android apps.png

Android Makefile[edit]

To build GNU Radio flowgraphs in the Android JNI world, we need to define a handful of libraries to link against in the file. To simplify things, we provide a canned that you can include in your file. Specifically, this file defines a set of statically and dynamically linked libraries required for building our applications. Once you download, open it up and change the GRLIBPATH variable on line 5 to point to your prefix. Remember from Setup and Building the Dependencies that we set the install prefix to /opt/grandroid, so in the default makefile here, we point to the lib directory of that prefix. If you changed the prefix during your install, change this line accordingly.

Place this file in your jni directory.

In the file the defines the rest of your projects space, add these lines:


... < the rest of the makefile definitions and setup > ...


Building an App[edit]

Ubuntu systems need the 32-bit version of libz

On Ubuntu 14.10:

sudo apt-get install zlib1g:i386

Also need OpenJDK 7

sudo apt-get install openjdk-7-jdk

And install the Android tools:

sudo apt-get install android-tools-adb

Using the JNI interface. We start with a simple project space -- I just copied their hello-jni application space over to a new directory. Normally, we'll start with a fresh application space, which I'll work on and document how to do this from scratch later (easy through the android IDE tools they provide, of course).

In the base directory of our app:

android update project -p . -s -t android-21

Follow the example file for the jni directory. This sets up
GRLIBPATH to point to /opt/grandroid/lib, so change that to wherever
your install prefix was. This points to all of the Boost, FFTW, and
GNU Radio static libs.

We need to edit and In, we have:

APP_ABI := armeabi-v7a
APP_STL := gnustl_shared
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions

I will provide an file later. We will probably want to create our own file at some point that sets up most of this stuff that we can then just include into our project's file later.

Edit the file as needed to add new libraries, change or add to the LOCAL_SRC_FILES, etc.

Edit the AndroidManfest.xml file in the root directory of the project to add the necessary permissions. To write/read to /sdcard for using GR file_sink/file_source blocks, you need:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
  • Steps to build the project:
cd jni
cd ..
ant debug
adb install -r bin/HelloJni-debug.apk
  • The 'ndk-build' and 'ant debug' are the actual build stages and should complete successfully, or there's a bug/problem.
  • The -r is for reinstalling if we've already done a previous install of this APK.
  • The name of the .apk file depends on the application and build style, so alter this step as necessary.
  • We are logging some output to logcat. I like to clear the log when debugging:
adb logcat -c && adb logcat

Starting a from-scratch Android Project[edit]

See the GRAndWalkthrough for building a basic GNU Radio for Android application using Android Studio.

Tricks to working with Android[edit]

When attaching a USB radio like an RTLSDR dongle, it'll be easier to use adb over Wifi than having to constantly switch USB cables between the host and the radio. To do this, first find out and note the IP address of the wifi connection on the device:

adb shell netcfg
wlan0 UP  0x00001043 

Then setup the connection on a TCP/IP port; generally, I've seen this as port 5555:

adb tcpip 5555

Now connect to the device using the IP address we discovered in the first step.

adb connect

Now disconnect the USB between the computer and Android device and make sure we're still able to talk to it:

adb devices    device

Working with USB Permission in your App[edit]

We have built a project to make it easier to work with USRP devices on Android by managing the permissions and loading of the firmware and FPGA images. This is probably the best way to keep track of the code and techniques we are using to manage these issues.