Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building ohNet for Android
03-08-2012, 02:40 PM
Post: #1
Building ohNet for Android
How should I build ohNet for Android? Do I need to compile it using the Android NDK?
Find all posts by this user
03-08-2012, 03:29 PM
Post: #2
RE: Building ohNet for Android
This is a bit embarrassing... it turns out we never quite finished Android support. We did get things working but never automated a build and lost the knowledge about build setup when Greg moved on...

From a look the code, I'd guess at
  • Install NDK to a linux box
  • Set $CROSS_COMPILE and $PATH to point towards the ARM cross-compiler which presumably comes with the NDK
  • Also set $PATH to point towards the Java toolchain
  • Build as normal (make ohNetJavaAll or whatever you prefer)
  • The build should produce its usual artifacts - ohnet.jar, libohNet.so, libohNetJni.so. Copy these into your android build tree.
  • Build your android app in the normal way using ant

Let us know if you get something running using this. We'll use the info to at least setup an automated build this time!
Find all posts by this user
17-08-2012, 11:24 AM
Post: #3
RE: Building ohNet for Android
(03-08-2012 03:29 PM)simonc Wrote:  This is a bit embarrassing... it turns out we never quite finished Android support. We did get things working but never automated a build and lost the knowledge about build setup when Greg moved on...

From a look the code, I'd guess at
  • Install NDK to a linux box
  • Set $CROSS_COMPILE and $PATH to point towards the ARM cross-compiler which presumably comes with the NDK
  • Also set $PATH to point towards the Java toolchain
  • Build as normal (make ohNetJavaAll or whatever you prefer)
  • The build should produce its usual artifacts - ohnet.jar, libohNet.so, libohNetJni.so. Copy these into your android build tree.
  • Build your android app in the normal way using ant

Let us know if you get something running using this. We'll use the info to at least setup an automated build this time!

I've found the first problem. Android doesn't have ifaddrs.h or getifaddrs(), so Os/Posix/Os.c doesn't compile. From a bit of web searching, it looks like I'll need to write an alternative implementation of OsNetworkListAdapters() that uses ioctl(SIOCGIFCONF).
Find all posts by this user
17-08-2012, 02:23 PM
Post: #4
RE: Building ohNet for Android
(17-08-2012 11:24 AM)simoncn Wrote:  I've found the first problem. Android doesn't have ifaddrs.h or getifaddrs(), so Os/Posix/Os.c doesn't compile. From a bit of web searching, it looks like I'll need to write an alternative implementation of OsNetworkListAdapters() that uses ioctl(SIOCGIFCONF).

I discovered some code in the ohNet tree to handle the getifaddrs() issue, and I also found a special makefile for use with the Android NDK. These will be very useful. Smile
Find all posts by this user
17-08-2012, 09:26 PM
Post: #5
RE: Building ohNet for Android
I've got the build working now. Some changes are needed:

1. (required) In OpenHome/Net/Bindings/Android/jni/Android.mk, the option -Wno-unused-but-set-variable must be added to the first LOCAL_CFLAGS line so that mDNS.c will compile successfully.

2. (required) In OpenHome/Net/Bindings/Android/jni/Android.mk, the following lines must be added to the first list of LOCAL_SRC_FILES to prevent linker messages about undefined symbols:
$(ohroot)OpenHome/Net/Device/DviProviderSubscriptionLongPoll.cpp \
$(ohroot)OpenHome/Net/Device/Providers/DvOpenhomeOrgSubscriptionLongPoll1.cpp \
$(ohroot)OpenHome/Net/Device/DviPropertyUpdateCollection.cpp \

3. (recommended) In OpenHome/Net/Bindings/Android/jni/Android.mk, the following lines should be added to the first list of LOCAL_SRC_FILES to make the contents of libohNet.so on Android match the contents of this library on other platforms:
$(ohroot)OpenHome/Net/ControlPoint/AsyncPrivate.cpp \
$(ohroot)OpenHome/Net/Bindings/C/Device/DvInvocationC.cpp \
$(ohroot)OpenHome/Net/Bindings/Cpp/Device/DvInvocationStd.cpp \

4. (recommended) In Common.mak line 1209, the following line should be removed because it isn't needed and it puts an ohNet-specific file into the user's NDK installation:
cp OpenHome/Net/Bindings/Android/jni/ifaddrs.h $(ANDROID_NDK_ROOT)/platforms/android-3/arch-arm/usr/include/

With the above changes, the build can done on Linux as follows:

export ANDROID_NDK_ROOT=<path to Android NDK root>
make ohNetAndroidNative

The build artifacts are placed in the Build/Obj/Posix/Release/Android/libs directory.

To clean the build artifacts, you can do:

export ANDROID_NDK_ROOT=<path to Android NDK root>
make ohNetAndroidClean
Find all posts by this user
20-08-2012, 02:37 PM
Post: #6
RE: Building ohNet for Android
Thanks! I've applied all your suggested changes; they'll hopefully appear on github this evening.
Find all posts by this user
20-08-2012, 03:35 PM
Post: #7
RE: Building ohNet for Android
(20-08-2012 02:37 PM)simonc Wrote:  Thanks! I've applied all your suggested changes; they'll hopefully appear on github this evening.

Thanks very much! I hope to have something running soon....
Find all posts by this user
18-01-2013, 08:25 PM
Post: #8
RE: Building ohNet for Android
(17-08-2012 09:26 PM)simoncn Wrote:  4. (recommended) In Common.mak line 1209, the following line should be removed because it isn't needed and it puts an ohNet-specific file into the user's NDK installation:
cp OpenHome/Net/Bindings/Android/jni/ifaddrs.h $(ANDROID_NDK_ROOT)/platforms/android-3/arch-arm/usr/include/

I've just noticed that this change, which was applied on 20 August, was reverted on 20 November. What was the reason for this?
Find all posts by this user
19-01-2013, 06:40 PM
Post: #9
RE: Building ohNet for Android
(18-01-2013 08:25 PM)simoncn Wrote:  
(17-08-2012 09:26 PM)simoncn Wrote:  4. (recommended) In Common.mak line 1209, the following line should be removed because it isn't needed and it puts an ohNet-specific file into the user's NDK installation:
cp OpenHome/Net/Bindings/Android/jni/ifaddrs.h $(ANDROID_NDK_ROOT)/platforms/android-3/arch-arm/usr/include/

I've just noticed that this change, which was applied on 20 August, was reverted on 20 November. What was the reason for this?

That was a mistake. I'll fix it on Monday
Find all posts by this user
21-01-2013, 05:13 PM
Post: #10
RE: Building ohNet for Android
(19-01-2013 06:40 PM)simonc Wrote:  That was a mistake. I'll fix it on Monday

Now fixed.
Find all posts by this user


Forum Jump: