No JNI_OnLoad found skipping init > Application shutdown - android

Folks,
I am working on an android application where I need a third party .so library. I built
this third party library (with ndk-build) as per their instructions and was then looking
to include this .so in to my Android project.
Therefore I followed the steps described in docs/PREBUILTS.html and successfully build the
new .so in the jni/prebuilt directory. Now I tried leveraging the .so facilities by using it in a simple test android app. So what i do is :
static {
Log.i("load so > ","load so");
System.loadLibrary("xyz");
}
/* The native functions */
private static native int openFile(String filename);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
String path = getPathForDownloadDirectoryFile();
Log.i("file path> ", path);
int num= openFile(path);
}catch(Exception e){
Log.e(">", "could not open the file");
}
}
Now when I run my app I get a debug message saying :
No JNI_OnLoad found in /data/data/com.example.myfirstapp/lib/xyz.so 0x411e6738, skipping init
and then the application shuts down.
For More Info, Here is the error log :
No JNI_OnLoad found in /data/data/com.example.mysecondapp/lib/xyz.so 0x411e67a0, skipping init
W/dalvikvm( 570): No implementation found for native Lcom/example/mysecondapp/MainActivity;.openFile:(Ljava/lang/String;)I
D/AndroidRuntime( 570): Shutting down VM
W/dalvikvm( 570): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
E/AndroidRuntime( 570): FATAL EXCEPTION: main
E/AndroidRuntime( 570): java.lang.UnsatisfiedLinkError: Native method not found: com.example.mysecondapp.MainActivity.openFile:(Ljava/lang/String;)I
E/AndroidRuntime( 570): at com.example.mysecondapp.MainActivity.openFile(Native Method)
E/AndroidRuntime( 570): at com.example.mysecondapp.MainActivity.onCreate(MainActivity.java:31)
E/AndroidRuntime( 570): at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime( 570): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 570): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 570): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 570): at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 570): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 570): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 570): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 570): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 570): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 570): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 570): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 570): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 570): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 146): Force finishing activity com.example.mysecondapp/.MainActivity
As I could see that native implementation for the openFile() method was not found but the same xyz.so lib worked pretty neat with the original sample app from the third party. I am pretty much a starter with Android-ndk world.
Java-Android-NDK Ninjas ..any guess on what I might be missing ?
I'll highly appreciate any help here :)

As guycole said "No JNI_OnLoad" is just a warning , your problem lies elsewhere .
As you mentioned you successfully compiled your "so" file , the problem may lie in your function signatures inside your c/C ++ code it should be something like this
JNIEXPORT jint JNICALL Java_com_your_package_class_method(JNIEnv *d, jobject e, jstring f)
{
//some action
}
The function signatures comes from the header file which is generated using javah tool.You need to generate header file and use the function signature with your package name. For different package and class names the header file and corresponding function signature will change .
worked pretty neat with the original sample app from the third party
This might be the reason its running on the sample app and not on your app.
refer: https://thenewcircle.com/s/post/49/using_ndk_to_call_c_code_from_android_apps

The "No JNI_OnLoad" message is just a warning. JNI_OnLoad is an optional initialization hook.
I guess your problem is inside the openFile() method. Try commenting out the call from Java and see how far you get.
I have a blog post about JNI and some sample code at http://guycole.blogspot.com/2012/03/yet-another-android-ndk-blog-posting.html - perhaps you will find it useful.
Good luck.

It also comes with this log
??-?? ??:??:??.???: INFO/(): java.lang.UnsatisfiedLinkError: Couldn't load *: findLibrary returned null
right??
I think it's the problem of android.mk files.
1:try to swith to armabi v7.
2:load funciton will call open(). check permission of the so.

As mentioned in the previous answers, No JNI_OnLoad is only a warning.
I had got similar problem, I figured the problem is because of file operations.
My app was not having external storage write permission.After adding the below code in
manifest it was working fine

Related

Android Studio 0.8.2: project using an sdk add-on which provides a jar library

I am trying to build a SDK add-on so developpers can use our library. I started by using this sample (a jar library add-on containing a system service):
https://github.com/gibsson/basic_sdk_addon
https://github.com/gibsson/BasicService
https://github.com/gibsson/BasicClient
I have followed the instructions from BasicService and BasicClient github pages and successfully created a working image by building both applications with the AOSP (for Android 4.3).
I built the two packages by adding the following to the device.mk file:
PRODUCT_PACKAGES += \
com.gibsson.basic.service.lib \
com.gibsson.basic.service.lib.xml \
BasicServiceApp \
BasicClient
This way, everything was build in the image and working.
End of introduction
I removed the BasicClient package from the build process and I am trying to bring this client in Android Studio, with the SDK, as would Android developpers do (they don't have access to the AOSP)
The basic_sdk_addon was successfuly created by following the instructions and using this command:
AOSP$ make PRODUCT-basic_sdk_addon-sdk_addon
I installed the Add-on in Android Studio using a User-defined repo. In the BasicClient project, I had to manually add the .jar file to the app/libs folder and click "Add as library" in order to compile BasicClient properly.
When trying to run/debug the BasicClient from AndroidStudio, I get the following error (from logcat, it's more detailed):
I/ActivityManager( 2544): Start proc com.gibsson.basic.client for activity com.gibsson.basic.client/.BasicActivity: pid=3311 uid=10044 gids={50044, 1015, 1028}
W/dalvikvm( 3311): Class resolved by unexpected DEX: Lcom/gibsson/basic/client/BasicActivity;(0x4213e238):0x40030000 ref [Lcom/gibsson/basic/service/lib/BasicManager;] Lcom/gibsson/basic/service/lib/BasicManager;(0x4213e238):0x4001d000
W/dalvikvm( 3311): (Lcom/gibsson/basic/client/BasicActivity; had used a different Lcom/gibsson/basic/service/lib/BasicManager; during pre-verification)
D/AndroidRuntime( 3311): Shutting down VM
W/dalvikvm( 3311): threadid=1: thread exiting with uncaught exception (group=0x41891700)
E/AndroidRuntime( 3311): FATAL EXCEPTION: main
E/AndroidRuntime( 3311): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
E/AndroidRuntime( 3311): at com.gibsson.basic.client.BasicActivity.<init>(BasicActivity.java:18)
E/AndroidRuntime( 3311): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 3311): at java.lang.Class.newInstance(Class.java:1130)
E/AndroidRuntime( 3311): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
E/AndroidRuntime( 3311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
E/AndroidRuntime( 3311): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
E/AndroidRuntime( 3311): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 3311): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 3311): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3311): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3311): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime( 3311): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3311): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime( 3311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime( 3311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 3311): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 2544): Force finishing activity com.gibsson.basic.client/.BasicActivity
I understand that there is a mismatch between the BasicManager dex file found and what it expects. I verified if the tools used where the same version between the AOSP and Android Studio: both use the same JDK (1.6.0.45) and the same compile version (18).
Got it working: it seems that importing the BasicService Eclipse project modified the Dependencies scope drop down menu (in Project Structure). I can now choose Provided instead of Compile, and the application works perfectly.
When creating a new project from scratch, I only had the following choices: Compile, Runtime.
So I've looked at the differences between the two projects and the build.gradle file was the only one that was changed: compile was replaced by provided.
dependencies {
provided files('libs/com.orthogone.canvas.service.lib.jar')
}
There seems to be a bug in the UI, as the Dependencies Dialog doesn't provide this choice even with the build.gradle modification.
Another important note: the AndroidManifest.xml must contain the <uses-library> information in the <appliation> section:
<uses-library
android:name="com.gibsson.basic.service.lib"
android:required="true" />

App Engine Connected Android Project - Libraries source attachment

I'm new to Android and App Engine, I'm trying to create an App Engine Connected Android Project, following the steps described here:
http://code.google.com/intl/es-ES/eclipse/docs/appengine_connected_android.html
but I'm not able to go through the "Say Hello" step (Run & Debug:7) using C2DM, since it prompts a SocketException ("Address family not supported by protocol") and sometimes a RuntimeException when debugging it locally... I don't get it, because I didn't customize the project yet, but after some debugging I saw that it was complaining about some libraries (included at the project creation) not having a source attachment... The most annoying part is that it complains about ThreadPoolExecutor.class, which belongs to java.util.concurrent in the Android 2.2 JAR... Weird, but anyway I attached the library to its source and it keeps complaining about the same class ("The source attachment does not contain the source for the file ThreadPoolExecutor.class")...
It seems to crash in the Util.getRequestFactory() method, at the execution of the first line. Here it calls a method in RequestFactorySource, which belongs to the requestfactory-client library, included at the project creation but again, without a source attachment... By the way, after executing that method call, the "task" variable is valued null, is it normal?
I guess it is about a small error in the configuration or something, but I've been struggling with it for days and I already don't know what to do, so any help would be appreciated :)
EDIT: I'm attaching the logcat output, I hope this makes it easier to find the bug. After googling I found out that it is a common error in the C2DM sample project, but I didn't get any appropiate solution.
I/C2dmftwActivity( 333): onCreate
I/ActivityManager( 58): Displayed activity com.c2dmftw/.C2dmftwActivity: 1281
ms (total 1281 ms)
D/dalvikvm( 126): GC_EXPLICIT freed 997 objects / 54032 bytes in 83ms
W/dalvikvm( 333): threadid=7: thread exiting with uncaught exception (group=0x4
001d800)
E/AndroidRuntime( 333): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime( 333): java.lang.RuntimeException: An error occured while exec
uting doInBackground()
E/AndroidRuntime( 333): at android.os.AsyncTask$3.done(AsyncTask.java:20
0)
E/AndroidRuntime( 333): at java.util.concurrent.FutureTask$Sync.innerSet
Exception(FutureTask.java:273)
E/AndroidRuntime( 333): at java.util.concurrent.FutureTask.setException(
FutureTask.java:124)
E/AndroidRuntime( 333): at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:307)
E/AndroidRuntime( 333): at java.util.concurrent.FutureTask.run(FutureTas
k.java:137)
E/AndroidRuntime( 333): at java.util.concurrent.ThreadPoolExecutor.runWo
rker(ThreadPoolExecutor.java:1068)
E/AndroidRuntime( 333): at java.util.concurrent.ThreadPoolExecutor$Worke
r.run(ThreadPoolExecutor.java:561)
E/AndroidRuntime( 333): at java.lang.Thread.run(Thread.java:1096)
E/AndroidRuntime( 333): Caused by: java.lang.RuntimeException: The RequestFacto
ry ValidationTool must be run for the com.c2dmftw.client.MyRequestFactory Reques
tFactory type
E/AndroidRuntime( 333): at com.google.web.bindery.requestfactory.vm.impl
.Deobfuscator$Builder.load(Deobfuscator.java:59)
E/AndroidRuntime( 333): at com.google.web.bindery.requestfactory.vm.InPr
ocessRequestFactory.<init>(InProcessRequestFactory.java:80)
E/AndroidRuntime( 333): at com.google.web.bindery.requestfactory.vm.Requ
estFactorySource.create(RequestFactorySource.java:43)
E/AndroidRuntime( 333): at com.c2dmftw.Util.getRequestFactory(Util.java:
158)
E/AndroidRuntime( 333): at com.c2dmftw.C2dmftwActivity$2$1.doInBackgroun
d(C2dmftwActivity.java:144)
E/AndroidRuntime( 333): at com.c2dmftw.C2dmftwActivity$2$1.doInBackgroun
d(C2dmftwActivity.java:1)
E/AndroidRuntime( 333): at android.os.AsyncTask$2.call(AsyncTask.java:18
5)
E/AndroidRuntime( 333): at java.util.concurrent.FutureTask$Sync.innerRun
(FutureTask.java:305)
E/AndroidRuntime( 333): ... 4 more
W/ActivityManager( 58): Force finishing activity com.c2dmftw/.C2dmftwActivit
y
W/GTalkService( 170): [GTalkConnection.13] doConnect: caught XMPPError connecti
ng to mtalk.google.com:5228.: (502)
W/GTalkService( 170): -- caused by: java.net.SocketException: The operation t
imed out
I think I had the same problem. The Validation library was missing and after adding it manually it worked.
To add it or to check if it's included do:
Right click on your project > Properties > Java Build Path > Libraries Tab > Add External JARs
Then browser to your GWT installation folder. If you installed it with eclipse it's in eclipse/plugins/com.google.gwt.eclipse.sdkbundle_/gwt-/validation-api-1.0.0.GA.jar
Clean and build your workspace and try it again.
This could happen on the client GWT side too. If that happens you have to do the same but use your GAE project and add the same jar
This is the problem
Caused by: java.lang.RuntimeException: The RequestFacto
ry ValidationTool must be run for the com.c2dmftw.client.MyRequestFactory Reques
tFactory type
If you are using GWT 2.4+, you will have to run a validation tool. You can configure Eclipse to do this for you, here is how:
http://code.google.com/p/google-web-toolkit/wiki/RequestFactoryInterfaceValidation

Android UnsatisfiedLinkError: Issue loading a shared library

I am compiling some Java code, putting it into a .JAR and then running dx --dex on it. I am pushing my file to an Android device through adb but I am having problem linking my shared library at runtime.
In HostConnection.java, I have the following code to load my library:
static {
System.loadLibrary("hostConnection");
}
I am loading the application this way:
adb shell
su
export CLASSPATH=/data/local/device.jar
export LD_LIBRARY_PATH=/data/local/libhostConnection.so
exec app_process /system/bin com.device.client.Main
I am unfortunately getting the following error:
D/dalvikvm( 1616): DexOpt: load 482ms, verify 84ms, opt 10ms
D/dalvikvm( 1608): DexOpt: --- END 'device.jar' (success) ---
D/dalvikvm( 1608): DEX prep '/data/local/device.jar': unzip in 1715ms, rewrite 1287ms
W/dalvikvm( 1608): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/device/client/HostConnection;.<clinit>
D/AndroidRuntime( 1608): Shutting down VM
W/dalvikvm( 1608): threadid=1: thread exiting with uncaught exception (group=0x4001d830)
I/Process ( 1608): Sending signal. PID: 1608 SIG: 9
E/AndroidRuntime( 1608): *** FATAL EXCEPTION IN SYSTEM PROCESS: main
E/AndroidRuntime( 1608): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1608): at com.device.client.Main.<init>(Main.java:27)
E/AndroidRuntime( 1608): at com.device.client.Main.main(Main.java:21)
E/AndroidRuntime( 1608): at com.android.internal.os.RuntimeInit.finishInit(Native Method)
E/AndroidRuntime( 1608): at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
E/AndroidRuntime( 1608): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1608): Caused by: java.lang.UnsatisfiedLinkError: Library hostConnection not found
E/AndroidRuntime( 1608): at java.lang.Runtime.loadLibrary(Runtime.java:461)
E/AndroidRuntime( 1608): at java.lang.System.loadLibrary(System.java:557)
E/AndroidRuntime( 1620): at com.device.client.HostConnection.<clinit>(HostConnection.java:25)
The line 25 in HostConnection.java is indeed System.loadLibrary("hostConnection").
My library is called libhostConnection.so and my .jar is called device.jar. They are both stored in /data/local. I have tried moving the shared library to /system/lib but the shell does not let me copy the file (read-only).
I am not sure what I am doing wrong, but I believe it cannot find the shared library for linking when running the application. I am not sure if I am using the wrong variable in export, or if I am supposed to do something else.
Could anyone please help me? It would be much appreciated.
Thank you very much!
And why don't you just try putting your library into lib/armeabi(-v7a) directory in your eclipse project? I believe it's the recomended way of linking shared library.
I figured it out. The variable is correct, but the path should be just the folder, not the .so file for some reason:
export LD_LIBRARY_PATH=/data/local
This actually works.
Thank you.

Loading a compiled .jar library into an Android Project

UPDATE
This is the correct way to add a compiled library:
Download the compiled .jar (and any extra files)
Add the jar (and anything extra) to a folder called libs in the project.
Right click on the project and configure build path
Libraries -> Add jar -> choose the jar
...
Profit
ORIGINAL QUESTION
Has anyone come across this before?
http://code.google.com/p/aacdecoder-android/
I am trying (desperately) to get it to work. Here are the steps I've followed:
Download the compiled .jar and .so files from downloads (the top one aacdecoder-android-libs-0.5.zip).
Add the two files to a folder called lib in the project.
Right click on the project and configure build path
Libraries -> Add jar -> choose the jar
I've put in the sample code on the google code page and yet I'm getting this error:
W/dalvikvm( 405): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
E/AndroidRuntime( 405): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 405): java.lang.UnsatisfiedLinkError: Library aacdecoder not found
E/AndroidRuntime( 405): at java.lang.Runtime.loadLibrary(Runtime.java:489)
E/AndroidRuntime( 405): at java.lang.System.loadLibrary(System.java:557)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.Decoder.loadLibrary(Decoder.java:167)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.Decoder.create(Decoder.java:188)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.Decoder.create(Decoder.java:178)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.AACPlayer.createDecoder(AACPlayer.java:407)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.AACPlayer.<init>(AACPlayer.java:121)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.AACPlayer.<init>(AACPlayer.java:104)
E/AndroidRuntime( 405): at com.spoledge.aacdecoder.AACPlayer.<init>(AACPlayer.java:95)
E/AndroidRuntime( 405): at com.tclayson.furadio.FURadioActivity.onCreate(FURadioActivity.java:14)
E/AndroidRuntime( 405): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
E/AndroidRuntime( 405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
E/AndroidRuntime( 405): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 405): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime( 405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime( 405): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 405): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 405): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 405): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 405): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 405): at dalvik.system.NativeStart.main(Native Method)
What am I doing wrong?! Can anyone help? Can anyone get that particular library to work at all? I need to play an AAC stream (eg: http://media-ice.musicradio.com/Capital).
Thanks
UPDATE
I added the library files (the .jar and the .so) to a different folder libs this time (with s).
Going through the same steps as above produces this new error:
D/ddm-heap( 436): Got feature list request
D/dalvikvm( 436): Trying to load lib /data/data/com.tclayson.furadio/lib/libaacdecoder.so 0x4376acc8
D/dalvikvm( 436): Added shared lib /data/data/com.tclayson.furadio/lib/libaacdecoder.so 0x4376acc8
D/dalvikvm( 436): No JNI_OnLoad found in /data/data/com.tclayson.furadio/lib/libaacdecoder.so 0x4376acc8
I/InetAddress( 436): Unknown host media-ice.musicradio.com, throwing UnknownHostException
E/AACPlayer( 436): playAsync():
E/AACPlayer( 436): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
E/AACPlayer( 436): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method)
E/AACPlayer( 436): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:85)
E/AACPlayer( 436): at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:59)
E/AACPlayer( 436): at java.net.Socket.checkClosedAndCreate(Socket.java:829)
E/AACPlayer( 436): at java.net.Socket.connect(Socket.java:984)
E/AACPlayer( 436): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:67)
E/AACPlayer( 436): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:151)
E/AACPlayer( 436): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:73)
E/AACPlayer( 436): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:826)
E/AACPlayer( 436): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:812)
E/AACPlayer( 436): at com.spoledge.aacdecoder.AACPlayer.play(AACPlayer.java:259)
E/AACPlayer( 436): at com.spoledge.aacdecoder.AACPlayer$1.run(AACPlayer.java:230)
E/AACPlayer( 436): at java.lang.Thread.run(Thread.java:1060)
What is the problem here? I don't understand the Unknown host error, because its evident that the above url exists. If this is a library specific issue then don't worry. :/
To answer your second question regarding the 'Unknown host' error (which actually says 'Permission denied' in its root cause, which makes more sense): You need to declare the INTERNET permission in your AndroidManifest.xml, such as:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..." [...]>
[...]
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
[...]
</manifest>
For further details about the Android permission concept, refer to: http://developer.android.com/guide/topics/security/security.html
Try right clicking the project, then going to properties > java build path.
You have to extract the file aacdecoder-android-libs-0.5.zip, this will revleal aacdecoder-android-0.5.jar and a folder named armeabi containing a static library.
To use the library copy the folder and the aacdecoder-android-0.5.jar into your libs folder. And add the jar to your buildpath (as you did with the zip before).

How can I use an external jar in an Android project in NetBeans?

I need to create an Android library which I can include as a jar in any Android application. I use NetBeans 6.8, the nbandroid plugin, and the Android SDK.
The steps I took so far are:
1) Create the library project, with android.jar included to have access to Android classes (the library uses android.util.Log and other Android classes).
2) Compile the library as a jar.
3) Add the library's jar to the Android application (right-click on Libraries under the project node and add the jar).
4) Add <uses-library> to the Android manifest. (erroneous and unnecessary)
Step 3 at least allows me to reference the library's classes in the application's source code, but the classes don't seem to actually be included at compile time. When I run the application, I get the following error in the log.
I/dalvikvm( 349): Could not find method mylibrarypackage.MyClass.myMethod, referenced from method myapplicationpackage.HomeActivity.onCreate
W/dalvikvm( 349): VFY: unable to resolve static method 985: Lmylibrarypackage/MyClass;.myMethod ()V
D/dalvikvm( 349): VFY: replacing opcode 0x71 at 0x000a
D/dalvikvm( 349): Making a copy of Lmyapplicationpackage/HomeActivity;.onCreate code (160 bytes)
D/AndroidRuntime( 349): Shutting down VM
W/dalvikvm( 349): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 349): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 349): java.lang.NoClassDefFoundError: mylibrarypackage.MyClass
E/AndroidRuntime( 349): at myapplicationpackage.HomeActivity.onCreate(HomeActivity.java:58)
E/AndroidRuntime( 349): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 349): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 349): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
E/AndroidRuntime( 349): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 349): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
E/AndroidRuntime( 349): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 349): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 349): at android.app.ActivityThread.main(ActivityThread.java:4310)
E/AndroidRuntime( 349): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 349): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 349): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 349): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 349): at dalvik.system.NativeStart.main(Native Method)
Do I have to add the library to the build path somewhere else? Am I missing something?
It appears I solved the problem.
I don't know if I missed a step when reading about how to use the nbandroid plugin, but the generated build-impl.xml doesn't seem to include any libraries I add with NetBeans when creating the APK.
This is the incriminating piece of ant script:
<target depends="init,compile,-pre-pre-jar,-pre-jar" name="-dex">
<exec executable="${dx}" failonerror="true">
<arg value="--dex"/>
<arg value="--output=${basedir}/${intermediate.dex}"/>
<arg value="--positions=lines"/>
<arg path="${build.classes.dir}"/>
</exec>
</target>
The library is included and the error mentioned in my question disappears if I add this last argument:
<arg path="${external.libs.dir}"/>
With external.libs.dir pointing to the directory containing the library's jar.
Thanks to Christopher for making me look at the build.xml generated by the Android command line tools (the script generated when creating an Android project in NetBeans with the nbandroid plugin is quite different).
Addendum: Since I'm talking about NetBeans, another way of doing this is by overriding the -pre-jar target in the project's build.xml, instead of the above change to build-impl.xml. This is done by adding the following to build.xml:
<target name="-pre-jar">
<copy todir="${build.classes.dir}">
<fileset dir="${external.libs.dir}" />
</copy>
</target>
This way, the library's jar is present along with the built classes, and automatically included.
Including android.jar within your library seems wrong — you can compile against it but shouldn't bundle it into your JAR.
When people use your library in their Android apps, it'll get compiled against the desired framework version that they've chosen.
Anyway, in Eclipse all you need to do is with a library JAR is add it to the build path. I don't see why NetBeans would be different. As you're building against it, it seems logical for it to be in the build path! :)
<uses-library android:name="com.mylibrarypackage" />
must not be included in your manifest, its usage is to include native shared libraries the application is linked against (i.e.: maps) not jars you are using in your project.
The other steps you mention are correct and work in Eclipse and should work in Netbeans unless there's a problem with the plugin.

Categories

Resources