Skip to content

Support libraries that package native libraries #1171

@joseph8282

Description

@joseph8282

Hi, I'm using robolectric framework for unit testing my android application. Since some of my function highly depends on native method(.so file). The native library could be load successfully on devices but I got UnsatisfiedLinkError while running unit test. If I really want to test the functionality of the native method, what should I do?? I can build the native library into x86 format. But I don't know how to let the testing framework link it.

Activity

changed the title [-]How to test native method with robolectric [/-] [+]Support libraries that package native libraries[/+] on Apr 24, 2015
erd

erd commented on Jul 8, 2015

@erd
Contributor

I was hoping that the Android Gradle plugin would unpack native libs into a directory similar to what it does for manifests, resources, etc, but it seems like this is not the case. In fact, it doesn't seem like the .so files are included in the build output. This might be considerably harder than I was thinking.

jaredsburrows

jaredsburrows commented on Jul 8, 2015

@jaredsburrows
Contributor
jaredsburrows

jaredsburrows commented on Jul 8, 2015

@jaredsburrows
Contributor

@erd

Searching:

$ git log -S addClassOrPackageToInstrument

Commits:

$ git log -S addClassOrPackageToInstrument
commit 56215a065f0b61b67bb7bb21f21b305da9a66c90
Author: Christian Williams & Dimitris Couchell <github+xian+dimitris@squareup.com>
Date:   Tue Nov 13 16:10:04 2012 -0800

    Extract Setup class for making decisions about instrumentation-time and runtime class handling.

commit f567a9e68c435fa0a98191c8ccda08add2f37566
Author: Rick Kawala & Ryan Richard <pair+rick+rrichard@pivotallabs.com>
Date:   Tue Oct 18 15:21:11 2011 -0700

    - allow shadowing of classes which have a private default constructor
    - allow subclasses of RobolectricTestRunner to provide a list of additional classes which should be shadowed

First Commit:

https://github.com/robolectric/robolectric/commit/56215a065f0b61b67bb7bb21f21b305da9a66c90

Second Commit:

https://github.com/robolectric/robolectric/commit/f567a9e68c435fa0a98191c8ccda08add2f37566
erd

erd commented on Jul 10, 2015

@erd
Contributor

I'm not sure - I'll have to dig into the history.

StefMa

StefMa commented on Jul 17, 2015

@StefMa

I've search and find this and #1628 and #1171 (and more :))

So, currently we have no chance to test "things" (like Fragments and Activitys) which use native code?

marcinkunert

marcinkunert commented on Jul 17, 2015

@marcinkunert

I've tried to do this, also without using robolectric and I doubt this can be made. The reason is simple: the libraries package a .so object - typical for linux environment. There is now way to load and run it on windows without building the library from scratch to *.dll. For now NDK is not able to build a *.dll.

Even if run under linux - there may be many dependencies to the android OS inside a native library.

Eventually I've failed in my trials - we are now testing the native part using instrumental tests on device/emulator and all the other functionality with junits/robolectric.

krevelen

krevelen commented on Sep 7, 2015

@krevelen

We're also running into this, and are forced to create another app for (robolectric-based) instrumental tests that require the native code. It apparently was not supported originally (#782), then it was possible in v1.2 (http://stackoverflow.com/a/11378926/1418999), and now in v2.0 and v3.0 it isn't anymore (#1171, #1389, #1516, #1628). Anyone know the prognosis for this feature?

jcogilvie

jcogilvie commented on Sep 28, 2015

@jcogilvie

I'm running into this as well. I've got dependencies on libraries which include NDK dependencies on .so files, but I have no NDK binaries at the top level.

To @erd's first point about unpacking the native .so files, you can find them in the build/intermediates/exploded-aars directory under **/jni/*.so. I'm not sure if that's helpful for what you're trying to accomplish though.

28 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xian@kingargyle@erd@jcogilvie@dazza5000

        Issue actions

          Support libraries that package native libraries · Issue #1171 · robolectric/robolectric