How to override or.apache.http in Android platform - android

I have wrote an Android application that uses HttpComponents from Apache to make a connection to server.
The version I used is 4.3 (newest), everything is ok, except when running.
I got exception
E/AndroidRuntime( 1699): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<in
it>(PoolingHttpClientConnectionManager.java:487)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:147)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:136)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:112)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.util.ApacheHTTP.<init>(ApacheHTTP.java:97)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.view.WeatherLifeActivity$3.<init>(WeatherLifeActivity.java:105)
E/AndroidRuntime( 1699): at net.xnano.weatherlife.view.WeatherLifeActivity.onOptionsItemSelected(WeatherLifeActivity.j
ava:105)
E/AndroidRuntime( 1699): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
E/AndroidRuntime( 1699): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
E/AndroidRuntime( 1699): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
E/AndroidRuntime( 1699): at android.view.View.performClick(View.java:4204)
E/AndroidRuntime( 1699): at android.view.View$PerformClick.run(View.java:17355)
E/AndroidRuntime( 1699): at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime( 1699): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1699): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1699): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 1699): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1699): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 1699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 1699): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1699): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:72)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:84)
E/AndroidRuntime( 1699): at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientCon
nectionFactory.java:59)
E/AndroidRuntime( 1699): ... 25 more
E/AndroidRuntime( 1699): Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:52)
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:56)
E/AndroidRuntime( 1699): at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterF
actory.java:46)
E/AndroidRuntime( 1699): ... 28 more
The library (in jar archive) which I added to libs folder has been exported, it seems the application uses internal org.apache.http package instead of my own library.
The IDE is Intellij Idea.
Did anyone solve this issue before please help me?

This issue is presented a few times in SO. The solution I took was to use a repackaged version of the library called httpclientandroidlib. This was presented as a solution in a newer version of this question at How to Override Android Api Class with a class available in added jar?

You can use your own library in next way
com.yourlibrary.MyClass myClass= new com.yourlibrary.MyClass();

Related

React Native App Crashes on Launch in Android (API 19)

Description
I have created a project with react-native-cli
When I launch the app using the command "react-native run-android" on Devices and Emulators with Android API level 21+ App is launching.
But for devices less than API 21, the app crashing on launch.
I have specified in android Gradle minSdk version to 16.
I viewed the stack trace using "adb logcat" the crash was due to OkHttp3 that is used internally in Facebook Flipper, which is expecting API 21+.
I haven't used any OkHttp3 Dependency explicitly in my app
React Native version:
6.14.4
Steps To Reproduce
Create a project using react-native CLI not Expo CLI
Navigate to the project folder
Connect a device or an emulator with API less than 21
run command "react-native run-android" to run the app on the connected device
Expected Results
The app should launch without any crash.
Android Logs
E/AndroidRuntime( 3745): java.lang.RuntimeException: Unable to create application com.infifive.MainApplication: java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
E/AndroidRuntime( 3745): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4347)
E/AndroidRuntime( 3745): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
E/AndroidRuntime( 3745): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime( 3745): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 3745): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 3745): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 3745): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3745): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 3745): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 3745): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 3745): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3745): Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
E/AndroidRuntime( 3745): at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:90)
E/AndroidRuntime( 3745): at com.facebook.react.ReactInstanceManager.<init>(ReactInstanceManager.java:238)
E/AndroidRuntime( 3745): at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:281)
E/AndroidRuntime( 3745): at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:87)
E/AndroidRuntime( 3745): at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:39)
E/AndroidRuntime( 3745): at com.infifive.MainApplication.onCreate(MainApplication.java:47)
E/AndroidRuntime( 3745): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
E/AndroidRuntime( 3745): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
E/AndroidRuntime( 3745): ... 10 more
E/AndroidRuntime( 3745): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 3745): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 3745): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
E/AndroidRuntime( 3745): at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:80)
E/AndroidRuntime( 3745): ... 17 more
E/AndroidRuntime( 3745): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 3745): at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263)
E/AndroidRuntime( 3745): at okhttp3.OkHttpClient.<init>(OkHttpClient.java:229)
E/AndroidRuntime( 3745): at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015)
E/AndroidRuntime( 3745): at com.facebook.react.devsupport.DevServerHelper.<init>(DevServerHelper.java:132)
E/AndroidRuntime( 3745): at com.facebook.react.devsupport.DevSupportManagerImpl.<init>(DevSupportManagerImpl.java:183)
E/AndroidRuntime( 3745): ... 20 more
E/AndroidRuntime( 3745): Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 19
E/AndroidRuntime( 3745): at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:238)
E/AndroidRuntime( 3745): at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
E/AndroidRuntime( 3745): at okhttp3.internal.platform.Platform.<clinit>(Platform.java:79)`
The only way I found to fix it is by commenting out all the code associated with flipper
GH thread here
This happens because of an internal check in the library called "okhttp" where the newer versions are supporting only API 21 and above. If possible, reduce the okhttp version, or anything related to it such as Glide or Retrofit etc. That will solve your problem.

java.lang.ArrayIndexOutOfBoundsException com.google.android.maps

I am getting this error in app that uses com.google.android.maps and the message is "Unfortunately the app has stopped."
E/AndroidRuntime( 3338): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 3338): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime( 3338): at
android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(
3338): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(
3338): at android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime( 3338): at
java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(
3338): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3338): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 3338): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 3338): at dalvik.system.NativeStart.main(Native
Method) E/AndroidRuntime( 3338): Caused by:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
E/AndroidRuntime( 3338): at
com.google.android.maps.MapActivity.createMap(MapActivity.java:575)
E/AndroidRuntime( 3338): at
com.google.android.maps.MapActivity.onCreate(MapActivity.java:423)
E/AndroidRuntime( 3338): at
com.ee.map.MainActivity.onCreate(MainActivity.java:170)
E/AndroidRuntime( 3338): at
android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime( 3338): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime( 3338): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime( 3338): ... 11 more
Has anybody seen such error and do you know what can causes this?
What is in com.google.android.maps.MapActivity.createMap(MapActivity.java:575)?

App crashed when installed from Market but not if the Apk is installed manually.

My App works fine if I just install it manually by moving the apk onto the phone and installing it, however when I put it on the Market it crashes on the first Activity, this is the logcat.
E/AndroidRuntime( 999): FATAL EXCEPTION: main
E/AndroidRuntime( 999): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mbwasi.funapp/com.mbwasi.funapp.Splash}: java.lang.ClassNotFoundException: com.mbwasi.funapp.Splash in loader dalvik.system.PathClassLoader[/data/app/com.mbwasi.funapp-1.apk]
E/AndroidRuntime( 999): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 999): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721)
E/AndroidRuntime( 999): at android.app.ActivityThread.access$2300(ActivityThread.java:132)
E/AndroidRuntime( 999): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
E/AndroidRuntime( 999): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 999): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 999): at android.app.ActivityThread.main(ActivityThread.java:4669)
E/AndroidRuntime( 999): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 999): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 999): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
E/AndroidRuntime( 999): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
E/AndroidRuntime( 999): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 999): Caused by: java.lang.ClassNotFoundException: com.mbwasi.funapp.Splash in loader dalvik.system.PathClassLoader[/data/app/com.mbwasi.funapp-1.apk]
E/AndroidRuntime( 999): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime( 999): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime( 999): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime( 999): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime( 999): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
E/AndroidRuntime( 999): ... 11 more
What could be happening here? I also notice in the log that the apk name has a -1 at the end too,
com.mbwasi.funapp-1.apk
where would this be coming from?
Is this on the same phone? Are you sure you are uploading the exact same APK? ClassNotFoundException could mean that some class your Splash activity is using is not found, you might be missing some library.
Well I left it overnight, refreshed the market page for my App and now it not only shows as compatible with all my devices but also works when installed. So it was a Market issue. There was a tip in the other thread to unpublish and publish and I did that, no idea if it actually did anything though.

Navit Excepition:java.lang.ExceptionInInitializerError

While running the Navit code for car navigation, I am getting the following exception, i thought that navit library is not available. please any one help me.
E/AndroidRuntime( 365): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 365): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 365): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 365): at java.lang.Class.newInstance(Class.java:1472)
E/AndroidRuntime( 365): at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
E/AndroidRuntime( 365): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
E/AndroidRuntime( 365): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime( 365): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
E/AndroidRuntime( 365): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
E/AndroidRuntime( 365): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 365): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 365): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 365): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 365): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 365): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
E/AndroidRuntime( 365): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 365): Caused by: java.lang.UnsatisfiedLinkError: Library navit not found
E/AndroidRuntime( 365): at java.lang.Runtime.loadLibrary(Runtime.java:489)
E/AndroidRuntime( 365): at java.lang.System.loadLibrary(System.java:557)
i downloaded the Navit code from , navit svn.ttps://navit.svn.sourceforge.net/svnroot/navit/trunk/navit But unable to run the code.
i want to run this code in Eclipse for Android Project.
You need to download Android NDK
Create standalong tools for your ARCH
Cross compile to ARM
Run make apkg
This error is due to missing libnavit.so.
Put libnavit.so it in /data/local
Change System.LoadLibrary to System.Load("/data/local/libnavit.so");
make apkg
Install
This exception should go away.

GLSurfaceView.onDetachedFromWindow

I have a little issues with an GLSurfaceView, when I start my Activity I make the GLSurfaceView invisible with this line of code:
glSurface.setVisibility(View.INVISIBLE);
During this time I start an AsyncTask which downloads an Image from network, at this time, if I press the back button I meet this Exception:
java.lang.NullPointerException
E/AndroidRuntime( 1847): at android.opengl.GLSurfaceView.onDetachedFromWindow(GLSurfaceView.java:530)
E/AndroidRuntime( 1847): at android.view.View.dispatchDetachedFromWindow(View.java:6033)
E/AndroidRuntime( 1847): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1156)
E/AndroidRuntime( 1847): at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1630)
E/AndroidRuntime( 1847): at android.view.ViewRoot.doDie(ViewRoot.java:2671)
E/AndroidRuntime( 1847): at android.view.ViewRoot.die(ViewRoot.java:2641)
E/AndroidRuntime( 1847): at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218)
E/AndroidRuntime( 1847): at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436)
E/AndroidRuntime( 1847): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3684)
E/AndroidRuntime( 1847): at android.app.ActivityThread.access$2900(ActivityThread.java:125)
E/AndroidRuntime( 1847): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
E/AndroidRuntime( 1847): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1847): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1847): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 1847): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1847): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 1847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 1847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidR
What's wrong?
It could be that you haven't set the renderer.
From the android reference:
onDetachedFromWindow ()... Must not be called before a renderer has been set.
So, if you set the renderer (even if you aren't rendering anything yet), this might avoid the issue.

Categories

Resources