Class Not Found Exception using custom cordova plugin - android

I'm developing a printing app that uses a custom API to access the printer via USB, so I needed a custom Cordova plugin. I started developing it, it has been a very good challenge but also very frustrating at the moment because I can't figure out why my plugin can't be used correctly.
The thing is:
1.- The plugin installs correctly and lets me build the application
2.- The Javascript code runs correctly
3.- I get a runtime error that doesn't crash the app. It seems like the Java code is skipped. And I noticed there was an error in the Android Monitor.
You can find my plugin here:
https://github.com/krlozadan/cordova-custom-printer-plugin
W/System.err: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter
W/System.err: at java.lang.Class.classForName(Native Method)
W/System.err: at java.lang.Class.forName(Class.java:324)
W/System.err: at java.lang.Class.forName(Class.java:285)
W/System.err: at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:489)
W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.duplou.cordova.plugin.customprinter.CustomPrinter" on path: DexPathList[[zip file "/data/app/1/lib/1/base.apk!/lib/x86, /vendor/lib, /system/lib]]
W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err: ... 13 more
W/System.err: Suppressed: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter
W/System.err: at java.lang.Class.classForName(Native Method)
W/System.err: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
W/System.err: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
W/System.err: ... 14 more
W/System.err: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I/System.out: Error adding plugin com.duplou.cordova.plugin.customprinter.CustomPrinter.
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
D/SystemWebChromeClient: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js: Line 11 : Se terminó la ejecución
I/chromium: [INFO:CONSOLE(11)] "Se terminó la ejecución", source: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js (11)
D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
W/PluginManager: THREAD WARNING: exec() call to Sim.getSimInfo blocked the main thread for 53ms. Plugin should use CordovaInterface.getThreadPool().
D/SystemWebChromeClient: file:///android_asset/www/build/main.js: Line 1436 : ERROR
I/chromium: [INFO:CONSOLE(1436)] "ERROR", source: file:///android_asset/www/build/main.js (1436)
W/BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12139
D/EGL_emulation: eglMakeCurrent: 0xae414a40: ver 2 0 (tinfo 0xa14bfbe0)
Here's my ionic info output
global packages:
#ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
local packages:
#ionic/app-scripts : 1.3.7
#ionic/cli-plugin-cordova : 1.4.1
#ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.2.1
System:
Node : v6.10.3
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10

I see that you are pointing to a jar file in your config.xml. If you really want to keep using this jar file make sure that the path is correctly mapped in android platform folders and it matches the classpath.
If you want to do a simple test, you should declare your android source files one by one. So after the node config-file you should add several nodes like this one:
<source-file src="src/android/src/net/mydomain/myplugin/MyClass.java" target-dir="src/mydomain/myplugin" />

This is the most important part of your stacktrace:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.duplou.cordova.plugin.customprinter.CustomPrinter"
Your Cordova configuration references the CustomPrinter plugin. When Javascript triggers loading it, the Java class cannot be found and thus your application crashes.
You need to ensure that the Java class is present in your application package.

I have this error and solved it by change android.json file in \platforms\android\android.json
You must change value of
res/xml/config.xml to your package of custom Plugin.
The reason is package of your custom plugin and value of above in not same.

In my case I had multiple .java files referenced. When I changed the ordering of how it is referenced in plugin.xml, it fixed the problem. Seems like the last .java file is dependent on the second last one.
Before:
<!--libs-->
<source-file src="libs/sample-release.aar" target-dir="libs/" />
<source-file src="src/android/Licence.java" target-dir="src/android/" />
<source-file src="src/android/Deserializer.java" target-dir="src/android/" />
After:
<!--libs-->
<source-file src="libs/sample-release.aar" target-dir="libs/" />
<source-file src="src/android/Deserializer.java" target-dir="src/android/" />
<source-file src="src/android/Licence.java" target-dir="src/android/" />
So just by switching the ordering, the ClassNotFoundException was resolved.

Related

Google SignIn API Exception 10 when compile on another computer

The Google SignIn inside my Android app runs perfectly well (I can sign in using any Google accounts on the phone) when I compiled the code in my daily-laptop. But when I cloned the code in my other laptop and compiled it there, it will always return Code 10 error.
Here's the full e.printStackTrace()
W/System.err: com.google.android.gms.common.api.ApiException: 10:
W/System.err: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source:4)
W/System.err: at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source:8)
W/System.err: at com.imincode.earthlings.view.ui.Register.onActivityResult(Register.kt:443)
W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:8110)
W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:4839)
W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4887)
W/System.err: at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
W/System.err: at android.os.Looper.loop(Looper.java:214)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7403)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
In my console.developers.google.com Project Credentials, under Application restrictions I chose Android apps and I've triple confirmed that I put the correct SHA-1 signing-certificate fingerprint from both my daily computer and this other laptop.
Edit: And I can confirm that google-services.json is there under app folder on both machine.
The solution is to add the SHA Key to your project in your firebase , Go To :
Project Overview -> Click on Settings Icon -> Project Settings -> General -> Scroll down under your package name -> Add your SHA key

RealmIOException: Failed to access: . make_dir() failed

I get this issue when I installed app from MDM(Mobile iron) where application will be wrapped for security purpose.
But it works fine if I install from Android studio,
Can any one please give solution ?
Ream : 1.0.1
minSDK: 18
Stack trace:
Unable to start activity ComponentInfo{forgepond.default.test/com.default.SplashActivity}:
io.realm.exceptions.RealmIOException:
Failed to access: . make_dir() failed: No such file or directory path: /data/user/0/com.default.test/files/default.realm.management
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5794)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: io.realm.exceptions.RealmIOException: Failed to access: . make_dir() failed: No such file or directory path: /data/user/0/com.default.test/files/default.realm.management
at io.realm.internal.SharedGroup.createNativeWithImplicitTransactions(Native Method)
at io.realm.internal.SharedGroup.openSharedGroupOrFail(SharedGroup.java:95)
at io.realm.internal.SharedGroup.(SharedGroup.java:74)
at io.realm.internal.SharedGroupManager.(SharedGroupManager.java:49)
at io.realm.BaseRealm.(BaseRealm.java:81)
at io.realm.Realm.(Realm.java:139)
at io.realm.Realm.createAndValidate(Realm.java:250)
at io.realm.Realm.createInstance(Realm.java:230)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:126)
at io.realm.Realm.getInstance(Realm.java)
As we wrapped using Gen1 wrapper technology which has no external storage access permission is the issue. When we tried with Gen2 wrapper it works fine.

Can't instantiate abstract class clarifai2.dto.ClarifaiStatus

Using Clarifai for Android getting error while invoking Clarifai
W/System.err: java.lang.RuntimeException: Failed to invoke clarifai2.dto.ClarifaiStatus() with no args
W/System.err: at com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:94)
W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:795)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:859)
W/System.err: at com.google.gson.Gson.fromJson(Gson.java:832)
W/System.err: at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:249)
W/System.err: at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:170)
W/System.err: at com.example.amutgeka.visualclarifia.MainActivity.train(MainActivity.java:120)
W/System.err: at com.example.amutgeka.visualclarifia.MainActivity$1$1.run(MainActivity.java:42)
W/System.err: at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: java.lang.InstantiationException: Can't instantiate abstract class clarifai2.dto.ClarifaiStatus
W/System.err: at java.lang.reflect.Constructor.newInstance0(Native Method)
W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
W/System.err: at `enter code here`com.google.gson.internal.ConstructorConstructor$2.construct(ConstructorConstructor.java:91)
W/System.err: ... 9 more
I maintain this library currently. The problem here is that ClarifaiStatus should not be instantiated directly (because it can't). If you look at the source code for the library, you can see that we register a Gson adapter that defines how to construct a ClarifaiStatus (in this case, by calling the constructor for AutoValue_ClarifaiStatus, which is auto-generated code).
For some reason, that adapter doesn't seem to be getting picked up; if it were, com.google.gson.internal.bind.ReflectiveTypeAdapterFactory wouldn't be getting invoked. So because no adapter is getting picked up, Gson falls back to its default behavior of trying to call the no-args constructor via reflection, which is impossible on an abstract class.
We haven't been able to reproduce this error, but we recently updated the client to support older versions of Gson, which might be the issue at hand. Can you make sure that you're using the latest version of the client, which is 2.2.3? Let me know if the issue persists.

Why can't Chromium find a Crosswalk resource, causing an exception in my Android app?

My Android app using Crosswalk and Cordova is causing an exception during long-press events, caused by onCreateActionMode in the Crosswalk bundled version of Chromium not finding a value for R.string.actionbar_textselection_title.
In order to create a long-press context menu, Chromium is looking up the string associated with R.string.actionbar_textselection_title, which at that point is set to 0, which defined, and we get this exception on long-press:
W/ResourceType: No package identifier when getting value for resource number 0x00000000
W/System.err: android.content.res.Resources$NotFoundException: String resource ID #0x0
W/System.err: at android.content.res.Resources.getText(Resources.java:1137)
W/System.err: at android.content.res.Resources.getString(Resources.java:1231)
W/System.err: at android.content.Context.getString(Context.java:363)
W/System.err: at org.chromium.content.browser.WebActionModeCallback.onCreateActionMode(WebActionModeCallback.java:138)
W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2694)
W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2619)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.View.startActionMode(View.java:4738)
W/System.err: at org.chromium.content.browser.ContentViewCore.startDefaultActionMode(ContentViewCore.java:2167)
W/System.err: at org.chromium.content.browser.ContentViewCore.startActionMode(ContentViewCore.java:2163)
W/System.err: at org.chromium.content.browser.ContentViewCore.showSelectActionMode(ContentViewCore.java:2133)
W/System.err: at org.chromium.content.browser.ContentViewCore.onSelectionEvent(ContentViewCore.java:2239)
W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:146)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5487)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
A/chromium: [FATAL:jni_android.cc(233)] Check failed: false. Please include Java exception stack in crash report
A/libc: Fatal signal 6 (SIGABRT) at 0x00006c77 (code=-6), thread 27767
This is where the getString is done, in org/chromium/content/browser/WebActionModeCallback.java:
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle(DeviceFormFactor.isTablet(getContext())
? getContext().getString(R.string.actionbar_textselection_title)
: null);
mode.setSubtitle(null);
mEditable = mActionHandler.isSelectionEditable();
mIsPasswordType = mActionHandler.isSelectionPassword();
mIsInsertion = mActionHandler.isInsertion();
createActionMenu(mode, menu);
return true;
}
During startup my app sometimes (not always) has these errors:
W/XWalkInternalResources: org.xwalk.core.R$styleableis not found.
W/XWalkInternalResources: org.xwalk.core.R$styleis not found.
W/XWalkInternalResources: org.xwalk.core.R$stringis not found.
W/XWalkInternalResources: org.xwalk.core.R$rawis not found.
W/XWalkInternalResources: org.xwalk.core.R$menuis not found.
W/XWalkInternalResources: org.xwalk.core.R$layoutis not found.
W/XWalkInternalResources: org.xwalk.core.R$idis not found.
W/XWalkInternalResources: org.xwalk.core.R$drawableis not found.
W/XWalkInternalResources: org.xwalk.core.R$dimenis not found.
W/XWalkInternalResources: org.xwalk.core.R$coloris not found.
W/XWalkInternalResources: org.xwalk.core.R$attris not found.
The main question is: why does R.string.actionbar_textselection_title not have a value? The string is defined in res/values/android_content_strings.xml:
<string name="actionbar_textselection_title">"Text selection"</string>
In my onCreate, this resource is available, so it's clearly being loaded:
getResources().getText(R.string.actionbar_textselection_title)
Log.d("FOO", (String) foo);
D/FOO: Text selection
Is this exception related to the context in which Chromium is trying to access the resource? Is there a remedy for this?
Pertinent information: Using Android API 22, build tools 23.0.3, embedding xwalk_core_library_java.jar 20.50.533.12 build as a dependency in Gradle, libxwalkcore.so under jniLibs for ARM and X86 devices, Crosswalk plugin files for Cordova in src/org/crosswalk/engine.
I have a sprawling app that grew organically over several years, containing a lot of code I can't share, so I can only supply bite-sized portions of code and config files.

SSL Error during Facebook Login in Android

I am implementing Facebook Login in my App but its not working on Api 2.3.6
I have tested the App in Emulator and its working Fine upto Api 23
Also it's working in Device with API 21 but not in 2.3.6
The Error is related to SSL
Bcoz I have read in an SO answer that,
in Api level 2.3.6 all connections and authorizations are handled by HTTPS only
while in Api levels above 2.3.6 its not the HTTPS that does every task
Also I have noticed that whenever I am trying to call any URL starting
with HTTPS it's not giving the final result but gets silently stopped as was the case
with Googles Direction Api.
Below is the StackTrace I am getting in 2.3.6 :
V/webkit: LoadListener.handleSslErrorRequest():
url:https://m.facebook.com/v2.4/dialog/oauth?
return_scopes=true&response_type=token%2Csigned_request&redirect_uri
=fbconnect%3A%2F%2Fsuccess&display=touch&sdk=android-
4.5.1&e2e=%7B%22init%22%1232%7D&client_id=1234&default_audience=friends
primary error: 3 certificate: Issued to: CN=*.facebook.com,O=Facebook\,
Inc.,L=Menlo Park,ST=CA,C=US;
Issued by: 1.2.840.113549.1.9.1=#1223,CN=Cyberoam SSL
CA_C016700030,OU=Cyberoam Certificate
Authority,O=Elitecore,L=Ahmedabad,ST=Gujarat,C=IN;
I/System.out: close [socket][/0.0.0.0:52994]
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
I/webkit/webview: WebView.stopLoading()
D/webkit/webview: WebView.stopLoading(): webcorethread is initialized
W/System.err: at
com.facebook.login.LoginManager.onActivityResult(LoginManager.java:173)
W/System.err: at
com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:139)
W/System.err: at
com.facebook.internal.CallbackManagerImpl.onActivityResult
(CallbackManagerImpl.java:82)
W/System.err: at
com.hogo.integrationapp.FirstActivity.onActivityResult
(FirstActivity.java:179)
W/System.err: at
android.app.Activity.dispatchActivityResult(Activity.java:3975)
W/System.err: at
android.app.ActivityThread.deliverResults(ActivityThread.java:2629)
W/System.err: at
android.app.ActivityThread.handleSendResult(ActivityThread.java:2675)
W/System.err: at
android.app.ActivityThread.access$2000(ActivityThread.java:156)
W/System.err: at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1030)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:130)
W/System.err: at android.os.Looper.loop(SourceFile:351)
W/System.err: at
android.app.ActivityThread.main(ActivityThread.java:3821)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:538)
W/System.err: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run\
(ZygoteInit.java:969)
W/System.err: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
Is there any Easy way to solve it ?
Also I want to understand why this is happening ?
I am using Facebook Sdk 4.5.1
For API 4.4.2 :
The Error was due to a File Transfer App open in my Device, when i closed it the error was gone
Thanks in Advance...

Categories

Resources