Use .so library in Android Studio 0.8.2 - android

I tested All previously shown answers on stackoverflow more than once. None of them working.
I use Android Studio 0.8.2 with the latest Gradle Version.
I have libfourier.so. This is a native library made in .c.
I don't have any other files.
It has been used in a previous app and did work.
I need this library because it can perform fast fourier transform without the input being a power of 2.
Is this possible? If yes, how?
Currently I have put the libfourier.so in /libs/armeabi/libfourier.so
And I call it by using
static {
System.loadLibrary("fourier");
}
But I get an UnsatisfiedLinkException stating the library could not be found.

There is no real magic. Just put it in libs/armeabi/libfourier.so like every other library.
Everybody saying otherwise is wrong.
First of all, the library was immediately found on a real device. So emulators in Android Device Manager and Genymotion cannot find this libraries apparently. Or the application is not installed as *.apk.
For the diehards, it is certainly possible to install the apk-file. But for the lazy ones like me, a real device will do the trick.
Secondly, you have to make sure your package name corresponds in the native function in the native code with the call to the native function in the android code.
If you have in Android intec.ugent.be.MyClass.nativeMethod() than your native method should be named: Java_intec_ugent_be_MyClass_nativeMethod(..). This is the case if you do not use JNI_onLoad in your native library.
Of course you have than to rebuild the jni-package with ndk-build. And add the new so-file to libs/armeabi.
So I would advice if you work with NATIVE CODE/LIBRARY just use a REAL device to RUN TEST DEBUG (do not forget to enable debugging on the device)

Related

Android NativeActivity that references a dynamic library fails to deploy

The environment...
I have a brand new Visual Studio 2015 Android NDK Solution.
This contains 2 projects (the default template code that is generated by visual studio):
A native activity. This is where I want to put Android specific code. It has some default code which fades the screen colour between green and black.
A 'Packaging' project to help with deployment.
I have deployed this successfully to an Intel HAXM virtual device as well as to a real device connected via USB. All good so far.
I then added an Android dynamic library project (.so) - this is where I want to put core code (platform agnostic).
I added a reference to this Core library from the native activity project.
Everything compiles and links fine. I can still create an .APK file.
Other info:
Android SDK 5.1 (Android-22)
Android NDK 21
x86
Clang 3.8
C++ 11
Not using Make files or Gradle
The problem...
Now whenever I deploy to the virtual/real device I get the following error (taken from logcat)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NATester/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.NATester-2/lib/x86/libNATester.so
Things I have tried...
changing the Core library to static (.a)
checked the android device to see if the file exists - it does exist.
Manually deploying the .APK to the android device.
Some articles have suggested using Java code to load the libraries - I want to avoid calling Java code e.g. System.LoadLibrary as this seems like a hack - I feel that it should be possible to to have a pure C++ application on android. I can't be the only person to run into this issue?!
This looks relevant but old and again an unnecessary hack for what must be very common situation
- Can't load native shared library with dependencies in a native activity app
- https://github.com/ikonst/android-dl
For what its worth, I am a seasoned C# developer with Visual Studio (15 years).
I therefore take a lot of things for granted when developing apps - this is my first project using C++/Android and it seems more of a manual battle to get everything to work!
Been struggling for a while but managed to deploy the libraries, quite easy in the end.
Right click on the project [theProject (Andorid-xx)] in the Solution Explorer and select add new item, add your .so library.
Right click on the newly added library and select properties, item type should be library, set Content to Yes, this will deploy the lib.

WiFi scan android javascript

I am trying build an android application that scans for the available access points and saves it in an array.
I was able to do it using eclipse and android studio but I am unable to do it from droidscript application.
I went through WiFi demos in droidscript to no success.
Just wanna know how can I achieve this using driidscript app.
You probably need to create a DroidScript plugin to do that. You should be able to just paste your Java code into the plugin template. Note: The latest alpha of DroidScript makes it really easy to do that as it can generate the AIDE code for plugins automatically.

Not able to trigger breakpoints in Android source files

I have not been able to trigger breakpoints set in Android source files (framework source files, as opposed to my application's source files). I have attached the Android source files, so I can see them and set breakpoints, but when I run in debug mode, these breakpoints are not triggered. I have also tried adding Class Loader breakpoints: this works fine on Android source classes. I am using Eclipse 3.7.2, and I've tried with several different Android SDK versions.
Robguinness,
It looks like what you would like to do is debug Android framework, right? The best method of doing this, from what I understand, is to import the AOSP project into Android Studio (only recognizes Java files) by running "make idegen && development/tools/idegen/idegen.sh" and then opening the android.ipr file that it generated in Android Studio. You can then hook up your emulator and set breakpoints in the Java code.
There are also a wide selection of tools to debug the Kernel, C native code, etc. but there it is such a long topic to cover on this site. If you are interested in more specifics, I would highly recommended Karim Yaghmour's class on Android Debugging (http://www.opersys.com/training/android-debug-and-performance). He has also given several talks at AnDevCon that should be freely available on Youtube about AOSP and Android Internals.
Best Wishes!

Generate core dump in android

I'm developping a android's aplication using some shared
libraries written by me and compiled with ndk-r5b. The application works,
y and the calls to the libraries works too, but I detected some errors,
segmentations faults, and I need to debug it, but, I don't know how debug
native code from android and I don't know if I can generate core dumps,
as in linux, for debug my libraries.
Any idea?
The ndk comes with ndk-gdb, which supposedly allows you to debug native applications. Also, if you download the whole andriod open source project, they also have some version of gdb used for debugging. Look in the docs/ folder of the ndk to learn about using it. This tutorial might also prove helpful: http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/
However, as shown in a recent question I asked: Running ndk-gdb with package not found error on motorola phone I still can't get it to work.
Edit: You said in the comments you were using a Samsung Device: Samsung decide to wreck havoc on some of the crucial internals required for native debugging, but it's easily fixable if you have root access to the device. If you use the --verbose flag, you'll probably find that the error is different than that, a package unknown error. That's because it's looking in /data/system/packages.list, but samsung renamed that file to /dbdata/system/packages.list. So if you make a symlink to that file in /data/system/packages.list, (requires root access) it should work. Or at least so claims the ndk mailing list: http://osdir.com/ml/android-ndk/2011-03/msg00036.html

Opening android AOSP native applications in eclipse

I need to edit the original Android Apps from packages
in terms make my own distro/mod..
I want to make changes to the In Call screen, lock screen, contacts, calendar etc..
I understand that for doing this I will have to build everything from
source,
however I need to edit the source and to do so I need to open the OS provided apps as
eclipse projects,
When I did I saw that there are
missing imports which are hidden in the SDK (or missing)
hidden parameters within the classes..
I don't want to use reflection since the whole code is here and
available, but how do you build a platform development kit..
or PDK ?:)
Can any one help?
You start by reading the documentation.
EDIT:
If you are trying to download some single project from AOSP and compile it using the SDK, odds are very strong that it will not work, and that you will encounter problems like the ones you cite. You do not build Android by building individual apps; you build Android ("my own distro/mod") by building the entire firmware. Most AOSP applications are not designed to be compiled by the SDK, but need the whole firmware.
Please check Using eclipse to browse and edit AOSP. You can atleast edit your code using eclipse, but you will have to use AOSP build system to build your distro.
You might also check Debugging Android Java Framework services as that would help debug your changes.
Just open Eclipse,
then go to "window" +"preferences" +"android"
there you will get sdk location,then give the appropriate path of the android sdk for proper run...

Categories

Resources