Android ClassNotFoundException on using custom java library - android

I am using my own custom java library to read response from the server by hitting urls. I have written a standalone java program to check whether the library is working or not and I am getting the positive responses for all the urls. But when I am trying to use the same java library with my android code it is throwing me an exception.
Exception:
Could not find class 'org.apache.http.impl.conn.PoolingClientConnectionManager', referenced from method com.nq.client.comm.HttpClientHelper.<init>.
java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingClientConnectionManager

You probably want to export the library in your Java Build Path:
See Android - Unable to instantiate activity - Class not found exception after upgrading to ADT 22
EDIT
In your custom library project, make sure you are exporting in the Java Build path the Apache library (org.apache.http.impl.conn.PoolingClientConnectionManager). The error message is telling you that there is a reference to this library, but it cannot be found. This means that it's not being packaged with the library that is referencing it. So, go to your custom library project and make sure that the Apache library is getting exported. If it is, raise it up in the list in order of export.

Related

Xamarin Android Bindings

I'm trying to create bindings for the android sdk provided here https://www.nmi.com/sdks-and-apis#CDNA. The binding project builds, and I can add it into my xamarin android project but as soon as I include it I get the following error/s.
error: package com.creditcall.chipdnamobile does not exist
com.creditcall.chipdnamobile.IApplicationSelectionListener ChipDnaSample.Android
C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IApplicationSelectionListenerImplementor.java 8
error: package com.creditcall.chipdnamobile does not exist private
native void n_onAvailablePinPads
(com.creditcall.chipdnamobile.Parameters
p0); ChipDnaSample.Android C:\Users\mikee\Documents\GitHub\ChipDna\ChipDnaSample\ChipDnaSample.Android\obj\Debug\90\android\src\mono\com\creditcall\chipdnamobile\IAvailablePinPadsListenerImplementor.java 33
There are 64 errors of the same nature just referencing different classes. I've put all the code on GitHub here
If I go into Obj/Release/generated/src I can find IApplicationSelectionListener so it is created some binding but it doesn't actually work. Could someone point me in the right direction about what I need to do to correct errors such as these?
Thanks
You have to change the build type of the jars. The java compile can't find it, because it's not present at compile time.
Change
InputJar to EmbeddedInputJar for ChipDnaMobile.jar
ReferenceJar to EmbeddedReferenceJar for CardEaseXMLClient.jar
For more info see: https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar
The important sentences:
Typically, you use the EmbeddedJar build action so that the .JAR is automatically packaged into the bindings library. This is the simplest option – Java bytecode in the .JAR is converted into Dex bytecode and is embedded (along with the Managed Callable Wrappers) into your APK. If you want to keep the .JAR separate from the bindings library, you can use the InputJar option; however, you must ensure that the .JAR file is available on the device that runs your app.

Xamarin Android app referenced to the dynamic shared library(.so) is looking for .dll extension

I have a Visual C++ dynamic shared library (.so) project created using Xamarin.
I am also creating a Xamarin.Android app in the same solution and trying to add the dynamic shared library project as a reference, so that I can debug into the c++ code.
I am doing this by selecting 'Add Reference' on the Android app project and bringing up the 'Reference Manager'.
I see the dynamic library, check the box and hit OK.
The library gets added to the list of references with a yellow triangle indicating there is some problem. When I select it, I do see that the path property is empty.
I go ahead and build the project and I see in the Output window the following:
C:\Program Files
(x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1550,2):
warning : Could not find file 'c:\users\documents\visual studio
2015\Projects\MySharedLibrary\x86\Debug\libMySharedLibrary.dll'.
No wonder the error, it is looking for the library with "dll" extension instead of the "so" extension.
What do I have to do to make the Android app reference the dynamic shared library(.so) for debugging?
-Thanks
Edit:
I get the same error even with the SanAngeles demo project and the sample project on the MSDN blog.
Edit2:
Direct reference to the .so lib works, it is the project reference to native library that throws this error.

Use Robotium to test android project with library

I have an android application consisting of a library project that contains the source code. I then have two additional projects, that are used to manage a pro, and lite version of the app.
I have been unable to get robotium to load the class files from either of my proxy apps(pro and lite, which reference the library via a module reference), or the library itself. I have tried a bunch of different class names, and references, but the test project fails below.
public MainTest() {
super("com.joe.app.lib", Main.class);
}
I haven't found any discussion here about testing with library projects in android. Looking for advice.
Error msg
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.joe.app.tests/com.job.app.tests.MainTest}: java.lang.ClassNotFoundException: com.joe.tests.MainTest in loader dalvik.system.PathClassLoader[/data/app/com.joe.app.tests-1.apk]
While not specific to Robotium, this post may help you using external libraries in your test project.
In case you haven't found a solution yet or others are getting to this question due to similar errors after the last the adt update.
In Project Properties of your Test Project go to item Java Build Path and select tab Order and Export. There you'll have to check the project you're testing against so it's properly exported.
For latest ADT you also have to have the Android Private Libraries exported in your projects.

android ndk mupdf build error

I am trying to make a project to read pdf in android phone.
So, I created the normal Android Project and installed the android-ndk-r6-windows.
And I built the 'libmibookreader.so' and set the native functions in my java class.
But after compiling my project I have a serious Error.
Caused by: java.lang.UnsatisfiedLinkError: Library mibookreader not found
Why this error caused?
I really don't know. I referenced the address of "http://flytgr.thoth.kr/blog/697421".
I followed down as the reference document described.
This is because your library was not loaded by the kernel. Are you sure that you placed your library inside the libs/armeabi/ folder of your project?
Check the logcat when you deploy your application, you should see some messages there that your library was loaded.
If you don't you could also try to use System.loadLibrary(libPath); to manually load your library.

Android Junit test - Mockito class not found exception

I'm attempting to build a unit test on Android which utilizes the mockito-all-1.8.5.jar file from mockito.org. I added the jar file to my project using project > properties > project build path > add external jar. This has always worked for me on non-Android java projects.
However, when I run the unit test, I get the following class not found exception:
java.lang.ClassNotFoundException: org.mockito.runners.VerboseMockitoJUnitRunner
Above it is the following message:
Cannot load class. Make sure it is in your apk. Class name: 'org.mockito.runners.VerboseMockitoJUnitRunner'. Message: org.mockito.runners.VerboseMockitoJUnitRunner
I checked the jar and the class is there.
I also tried adding according to this link:
How to use and package a JAR file with my Android app?
But, still no luck. How can I get this class to be found?
Edit: I'm thinking there is a problem with whatever libraries Mockitto depends on - they may not be compatible with the Dalvik jvm. See this post:
http://daverog.wordpress.com/2009/12/14/why-android-isnt-ready-for-tdd-and-how-i-tried-anyway/
1) Import a mocking framework (e.g. mockito) into the project as an additional dependency.
Any imported jars containing class files not compiled to Dalvik bytecode (most) will not work. Attempting to compile the source along with your project will not work either because most libraries will make extensive use of parts of the Java language not compatible with Dalvik: it uses its own library built on a subset of the Apache Harmony Java implementation.
If you are executing inside the Dalvik JVM you won't be able to use Mockito.
If you are running your unit tests on your desktop JVM however (with a testing framework like Robolectric for example) then you are good to go. I am combining the two on my Android projects at present, to good effect.

Categories

Resources