Implementing and using SoundTouch class (Java Android) - java

I've been trying to use the library SoundTouch in my android app in order to change the tempo of an mp3 file.
I've managed to compile the library following the steps outlined here: http://www.surina.net/soundtouch/README-SoundTouch-Android.html
My question now is how do I import and use the compiled library in my android project in Eclipse?
From following the steps in the link above I've ended up with .so files that I've added into the libs folder of my project. I've also changed the build path to include this new library.
The library is now showing up under "referenced libraries" so I'm guessing I'm some where on the right track?
In my java file I've tried importing the library like this:
static
{
System.loadLibrary("soundtouch");
}
The program builds and runs fine but I don't think the library is actually being loaded as I can't reference any of soundTouch's methods.
Any help would be much appreciated!

The JNI file provided with the SoundTouch library is merely a demonstration and does not provide any means of using any of SoundTouch's features in an Android app from Java.

Related

Binding to c# some java-code, that uses .so libraries

There are some .so libraries and java code uses them for android.
I compile this java code within android studio to get an .aar file. I need to make binding for c# code fo Xamarin.Android using Visual Studio. So, while binding with java is working good, the java code throws exception:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader
Through the seeing of full exception message I got that java code can't find .so files. In the Android Studio project .so libs are settled at ./lib/armeabi-v7a/, and the java code works well.
So, the question is: where should I put .so libs in C# binding library? Some inner scent tips me I should put it somewhere -- that's the way libraries work.
I've tried to put .so libraries in directory with my .dll, also deeper in ./lib/armeabi-v7a/, but it actually didn't help -- the exception was the same. I've tried to put them in the directory with my .aar file and also in the deeper directory in ./lib/armeabi-v7a/ but this is kinda of shamanism. it's also didn't help.
the problem was in the way I tried to check the work of program. My Android emulator didn't have the armeabi-v7a support. After I tried to change my emulator settings. it became laggy and very slow. The issue was to test an application on real device.

How to import 3rd party libraries

I found some cool android libraries the other day and decided to try some. But I'm having trouble correctly importing the library.
This is the URL of the library : https://github.com/dmytrodanylyk/android-process-button
I first tried importing the library to eclipse (and move the files in java directory to src directory and set the project as library) and importing the sample to eclipse and set it to use the library project (Properties->Android->Libraries). But it didn't work. The layout files said it failed to instantiate [custom widget class].
The I tried importing the .jar file to libs directory (and update the java build path) but it didn't work either. It showed errors in the java files too.
I then tried copying all the java and layout files to the sample project directory and it worked. But I'm guessing that's not the way to work with 3rd party libraries.
I first thought it's some error with the library but all the other libraries I tried to import to my projects faced the same problem.
Can someone walk me through how to correctly import a 3rd party library to my android project?
The best option you can do is to use gradle as your dependency manager.
The library you have posted is using Gradle so you can link to this library in this way:
dependencies {
compile 'com.github.dmytrodanylyk.android-process-button:library:0.0.7'
}
And voilá! You have your library ready to use in your app :D
I'll let you a couple of useful links to use Gradle properly:
Mark Allison's tutorial about Gradle It will explain step by step how Gradle works (keep in mind that is using an outdated version of Android Gradle plugin, you have to adapt the version to the current one which is 0.10)
Official Developer Docs about Gradle In here you can find another step by step tutorial to configure and use Gradle (this one is more updated).
You can use Gradle directly in Android Studio (Intellij) if you don't mind to change your main editor.
If you want to stick around with Eclipse then this stackoverflow link may be helpful!
EDIT:
Oh! And if you want to search already Gradlized libraries you can navigate to Gradle Please!
I see the library uses gradle. So if you use gradle for dependency management or Android Studio (which uses gradle by default) importing will be a breeze. The installation instruction for gradle is even available at the github project site.
dependencies {
compile 'com.github.dmytrodanylyk.android-process-button:library:0.0.7'
}

Using Android Library on a Regular Java Project

I am looking to use an android class on a regular non-android java project. Specifically I want to use FaceDetector from android.media
I know that there are OpenCV and other libraries I can use to detect a face in an image but I am looking to use androids library. Is there a way to link androids library to a java project?
Thanks
Go to build path of your java project
Add a new external jar
Browse to the location of your android platform installation
(usually C:\Program Files (x86)\Android)
Under android-sdk\platforms\android-x (where x is the version of android you have) select the android.jar file to add to the project.
Now you have the android library under the referenced libraries, and you can use whatever android classes you want in your java project.
Another way of doing that is to use the android source, get only the java files you need from the android library and put them into your java project. The good thing when you do it this way is that you can modify the code and make it more compatible with your java work.
The android library might contain some calls to the system API's. Look for them before including the library with the above mentioned steps. I would recommend you to look into the documentation of the android library and look for the hooks where it calls android system APIs.Modify the source to use your webcam's API and then include it as a library

java.lang.VerifyError on imported jar

I have imported a .jar into my Eclipse Android project (importing it to the libs folder and adding the jar to the libraries in Java Build Path), but when I attempt to use it, I get a java.lang.VerifyError. The library is Jiwigo 0.13.1.1; a java library for accessing Piwigo image galleries. I know this should work, because there's an open source android project called RegalAndroid that uses it too (though, an older version, and it copied the source instead of properly importing it). The .jar is the only copy of the library on my computer, so I'd be surprised if it was a version clash error. Any ideas?
Here's my error log (shortened because all the rest is normal android stuff):
FATAL EXCEPTION: main
java.lang.VerifyError: fr.mael.jiwigo.transverse.session.SessionManager
at com.terrapages.itemdetailsactivities.FavoritesDetailsActivity.initViews(FavoritesDetailsActivity.java:179)
at com.terrapages.itemdetailsactivities.FavoritesDetailsActivity.onResume(FavoritesDetailsActivity.java:83)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
at android.app.Activity.performResume(Activity.java:3823)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
[...]
And the line it crashes on (with dummy string values that are different in the code):
SessionManager sessionManager = new SessionManager("username", "password", "gallery-url");
This is the first use of the library anywhere in the code.
I'm the developer of Jiwigo and read this post this afternoon by chance.
As I do not develop on Android, I didn't even know that my api was not compatible with android.
So after I read this post, I made some changes on my API : I replaced the old Apache HttpClient version with a newest one : 4.1 (I think it's compatible with android isn't it ?)
And I removed all JDom references. The code now uses org.w3c.dom.Document instead. The jar is here : http://maven.le-guevel.com/artifactory/libs-release-local/fr/mael/jiwigo/jiwigo-ws-api/0.2b/
As I said, I just made the modifications this afternoon, and I did not test it very well, so it could be unstable (it seems to work on my project).
Bye.
Any ideas?
SessionManager is using a class or method that does not exist in Android. Assuming this is the source for the class in question, there is no way that will work on Android without substantial modifications, as it uses:
an old version of Apache HttpClient
JDOM
neither of which are in Android.
I had a similar issue with my projects after doing the Android ADT , and Java updates.
Try these steps
Remove links to your external libraries in your Android project.
Move all your external libraries (including Google Ad libraries) to \libs folder inside your Android project.
Re-link your libraries, that now exist in the Project\libs directory.
Hopefully this will help

Android shared library which is not JNI based

I am developing a library for Android applications which does not use native code (JNI). I have tried suppling the library as an external jar in my Android projects but this method does not include the library contents in the apk and thus throws class not found errors when run in the emulator or device. I have also tried creating the library as an Android project in itself and this does work, but only for public static properties (not methods). With the library and application both being in separate apk's I can see that the VM notices references to the library and can read some properties, but when an attempt to instantiate a class in the library is executed I get class not found even though I can read the public static properties from it (very frustrating!!).
I realize that Davlik byte code is not the same as Java byte code but I am having trouble even finding good information about how to solve what would seem to be a very simple issue in Android. I am looking into the old PlatformLibrary stuff right now but I am not convinced this will work either since the sample has been removed from the Android site :(
So help me out if you can, if I find the answer before this happens I will share it.
viva la Android!
I have tried suppling the library as
an external jar in my Android projects
but this method does not include the
library contents in the apk and thus
throws class not found errors when run
in the emulator or device.
Put the JAR in your libs/ directory, and it will automatically be included in the APK.
This sample project from one of my books shows using the BeanShell JAR this way. Also, all of the GitHub repos starting with "cwac-" on my GitHub page are projects designed to build JARs to be included in Android projects via the libs/ directory.

Categories