Why is NoSuchFieldException: ON_STOP thrown on Android 5.0.2? - android

I am using android.arch.lifecycle extension to detect when the app moves in background or foreground:
#OnLifecycleEvent(Lifecycle.Event.ON_STOP)
private void onAppBackgrounded() {
Log.i(this.getClass().getName(), "onAppBackgrounded()");
}
The extension works fine except on a device running on Android 5.0.2 (SDK 21) on which I get the following exception:
Caused by java.lang.NoSuchFieldException: ON_STOP
at java.lang.Class.getDeclaredField + 929(Class.java:929)
at libcore.reflect.AnnotationAccess.decodeValue + 685(AnnotationAccess.java:685)
at libcore.reflect.AnnotationAccess.toAnnotationInstance + 663(AnnotationAccess.java:663)
at libcore.reflect.AnnotationAccess.toAnnotationInstance + 641(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation + 170(AnnotationAccess.java:170)
at java.lang.reflect.Method.getAnnotation + 301(Method.java:301)
at android.arch.lifecycle.ClassesInfoCache.createInfo + 124(ClassesInfoCache.java:124)
at android.arch.lifecycle.ClassesInfoCache.hasLifecycleMethods + 59(ClassesInfoCache.java:59)
at android.arch.lifecycle.Lifecycling.resolveObserverCallbackType + 137(Lifecycling.java:137)
at android.arch.lifecycle.Lifecycling.getObserverConstructorType + 119(Lifecycling.java:119)
at android.arch.lifecycle.Lifecycling.getCallback + 57(Lifecycling.java:57)
at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.(LifecycleRegistry.java:2)
at android.arch.lifecycle.LifecycleRegistry.addObserver + 162(LifecycleRegistry.java:162)

Related

Fatal Exception: java.lang.UnsatisfiedLinkError centrifuge-android

We use centrifuge lib to communicate with Sockets. Everything works well but
this code :
val credentials = Centrifuge.newCredentials(
getCurrentUserId(),
webSocketToken.timestamp,
EMPTY_STRING,
webSocketToken.token
)
throws this error, it only happens with android based on arm structure. Here is the output:
Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.namba-_dbpnhlp0R3PyG4erhR_2w==/base.apk"],nativeLibraryDirectories=[/data/app/com.namba-_dbpnhlp0R3PyG4erhR_2w==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libgojni.so"
at java.lang.Runtime.loadLibrary0 + 1012(Runtime.java:1012)
at java.lang.System.loadLibrary + 1669(System.java:1669)
at go.LoadJNI.<clinit> + 23(LoadJNI.java:23)
at java.lang.Class.classForName(Class.java)
at java.lang.Class.forName + 453(Class.java:453)
at java.lang.Class.forName + 378(Class.java:378)
at go.Seq.<clinit> + 28(Seq.java:28)
at go.Seq.touch()
at centrifuge.Centrifuge.<clinit> + 11(Centrifuge.java:11)
at centrifuge.Centrifuge.newCredentials(Centrifuge.java)
at com.namba.websocket.CentrifugoWebSocketClient.createClient + 214(CentrifugoWebSocketClient.kt:214)
at com.namba.websocket.CentrifugoWebSocketClient$initClient$1.invokeSuspend + 145(CentrifugoWebSocketClient.kt:145)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith + 32(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask$DefaultImpls.run + 235(Dispatched.kt:235)
at kotlinx.coroutines.DispatchedContinuation.run + 81(Dispatched.kt:81)
at kotlinx.coroutines.scheduling.Task.run + 94(Tasks.kt:94)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely + 586(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely + 60(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run + 732(CoroutineScheduler.kt:732)

Rebooted android phone and the Geolocation in my phonegap application stopped working

I rebooted my android phone and the geolocation code in my app has stopped working. The navigator.geolocation is returning true but getCurrentPosition and watchPosition aren't working. It isn't returning an error message either. I have location turned on the phone, the phone version is 5.0.1 and the cordova version I am using is 5.3.3.
Any help would be greatly appreciated!
The JavaScript code I am using:
function showCurrentPosition(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
}
// onSuccess Callback
// This method accepts a Position object, which contains the
// current GPS coordinates
//
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
};
// onError Callback receives a PositionError object
//
function onError() {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
Console Log:
The key "target-densitydpi" is not supported.
file:///android_asset/www/css/images/ajax-loader.gif Failed to load resource: net::ERR_FILE_NOT_FOUND
whitelist.js:23 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.(anonymous function) # whitelist.js:23
index.js:41 Uncaught TypeError: Cannot read property 'querySelector' of null
521whitelist.js:25 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
I figured out what was causing my geolocation to stop working. When I rebooted my android is set the location services to GPS only. When I changed it use WiFi, phone network and GPS for my location it was able to obtain my longitude and latitude.
The problem with my android phone is that the GPS has stopped working so this turned out to be a hardware problem not a software problem.

as3 _ctx is null pozirk android in app purchases ANE

I googled _ctx is Null and I was shocked to find nothing relating to Android. I am hoping this pose will help someone if we find the right answer.
Here is a link to the ANE I am using: https://github.com/pozirk/AndroidInAppPurchase
I have no idea where to go from here. It once worked now its not. :(
I am trying to use Pozirk's InAppPurchase.ane - which I have used before but suddenly its not working. I am not sure what changed. It may be, the ANE, or something in google play. Not sure but now its not working and I keep on getting this error:
_ctx is null.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.pozirk.payment.android::InAppPurchase/init()[C:\Users\blah\blah\Android\com\pozirk\payment\android\InAppPurchase.as:46]
at hereWeGo_fla::MainTimeline/fl_MouseClickHandler()[hereWeGo_fla.MainTimeline::frame1:97]
import com.pozirk.payment.android.InAppPurchase;
import com.pozirk.payment.android.InAppPurchaseEvent;
import flash.display.MovieClip;
/**
* ...
* #author Ben Barnard
*/
var _iap:InAppPurchase;
_iap = new InAppPurchase();
_iap.addEventListener(InAppPurchaseEvent.INIT_SUCCESS, onInitSuccess);
_iap.addEventListener(InAppPurchaseEvent.INIT_ERROR, onInitError);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_SUCCESS, onPurchaseSuccess);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_ALREADY_OWNED, onPurchaseSuccess);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_ERROR, onPurchaseError);
_iap.addEventListener(InAppPurchaseEvent.CONSUME_SUCCESS, onConsumeSuccess);
_iap.addEventListener(InAppPurchaseEvent.CONSUME_ERROR, onConsumeError);
_iap.addEventListener(InAppPurchaseEvent.RESTORE_SUCCESS, onRestoreSuccess);
_iap.addEventListener(InAppPurchaseEvent.RESTORE_ERROR, onRestoreError);
// Liscense Key
function onRestoreError(e:InAppPurchaseEvent):void
{
trace("Restore Error - " + e.toString());
outputField.text = "Restore Error - " + e.toString() + e.data.toString();
}
function onConsumeError(e:InAppPurchaseEvent):void
{
trace("Consume Error - " + e.toString());
outputField.text = "Consume Error - " + e.toString() + e.data.toString();
}
function onConsumeSuccess(e:InAppPurchaseEvent):void
{
trace("Consume Success - " + e.toString());
outputField.text = "Consume Success - " + e.toString();
// ------------------------------- THIS LINE PROMPTS THE USER TO PURCHASE THE ITEM ------------------------------- //
_iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
}
function onPurchaseError(e:InAppPurchaseEvent):void
{
trace("Purchase Error - " + e.toString());
outputField.text = "Purchase Error - " + e.toString();
}
function onRestoreSuccess(e:InAppPurchaseEvent):void
{
trace("Restore Success - " + e.toString());
// ------------------------------- THIS LINE CONSUMES THE "TEST" ITEM ------------------------------- //
_iap.consume("android.test.purchased");
}
function onPurchaseSuccess(e:InAppPurchaseEvent):void
{
trace("Purchase Successful - " + e.data.toString());
outputField.text = "Purchase Successful - " + e.data.toString();
}
function onInitError(e:InAppPurchaseEvent):void
{
trace("Init Error - " + e.toString());
outputField.text = "Init Error - " + e.toString();
}
function onInitSuccess(e:InAppPurchaseEvent):void
{
trace("Init Success - " + e.toString());
outputField.text = "Init Success - " + e.toString();
// ------------------------------- THIS LINE RESTORES ALL PURCHASED ITEMS ------------------------------- //
//_iap.restore(InAppPurchase.TYPE_INAPP);
}
init.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
_iap.init("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiM0Lpjf/S5JQOh0L5c3IQNawziFTT9WeJ9fAmQl5nXJdfVnRK9+mMCnHJlKz8omt9RljlrtLpOV4iy+/KUFgtZ/SCvF+Brpk9lAEe+SbifT2mNGNKgF3tCXSHTXX2Xuq9kw1CR0bDy0Jf36LE04zBo4jYV4RcWQ66ViS2JbTEXAugG5S71z+CJXo6o5uYG/mRZlHFRJkpp1ufDFg4dp8r2ApN3RXhMv9Rl3NCcwTk3R0/rmwCc80Uy94kX7hkgeBuj/AViFZMbzYzY8YLdx80cYYHPc/ofecXmCl6OorJiBC+GiMs/vBoyjr4EGeIqfp1WdZrxeaJzMzAWPNoY4mSwIDAQAB");
}
purchase.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
}
consume.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);
function fl_MouseClickHandler_3(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.consume("android.test.purchased");
}
restore.addEventListener(MouseEvent.CLICK, rLove);
function rLove(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.restore(InAppPurchase.TYPE_INAPP);
}
You did not add ANE file to your project properly.
This question was already asked and answered:
http://inside.pozirk.com/2013/02/18/adobe-air-in-app-purchase-native-extensions/#comment-87
http://inside.pozirk.com/2013/02/18/adobe-air-in-app-purchase-native-extensions/#comment-89
My checklist, after tinkering FlashBuilder for 2 hours:
1) "project" > Properties > ActionScript Build Path > Native Extensions > Add ANE > "add InAppPurchase.ane"
2) "project" > Properties > ActionScript Build Packaging > Google Android > Native Extensions > "select package InAppPurchase.ane"
3) ... AS3 code uses the in-app-purchase API ...
4) The ANE seems to fail if you try to use it in debug mode; an exported APK should be used instead.
5) FlashBuilder > Project > Export Release Build:
Verify that the ANE is included in the package (Native Extensions)
Verify that your are using the correct signing certificate.
6) Copy the created APK to the Android device.
7) Install the APK using a file explorer.
8) The app finally runs, instead of crashing/hanging at startup.

Webview does not show onConsoleMessage in android

I have used webview
with the reference http://developer.android.com/guide/webapps/debugging.html
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
}
});
but still m not get log Logcat
Please help me out
It appears some devices (HTC Desire and some others) with specific OS (mine had 2.3.3) do not display messages in Logcat window and it seems console.log does not work for them. I found a nice workaround using JavaScript Interface to overcome the issue: Android Console via JS interface
In my case (I have Samsung Note 4 running Android 6.0), onConsoleMessage is called only if I set
myWebView.setWebContentsDebuggingEnabled(true);
and when I open the Chrome remote device debugger to inspect the webview. But obviously this is not quite helpful since I can already see the console output on the debugger window.

Android: problem with debugging javascript in webview

I have some javascript running in WebView, and I want to receive console messages about errors in JS.
In accordance with the instructions at http://developer.android.com/guide/webapps/debugging.html I overrided methods
WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)
and
WebChromeClient.onConsoleMessage(ConsoleMessage cm),
redirecting messages to logcat. In android 2.1 it works well, but in android 2.2 none of this methods are called.
What I am doing wrong?
Thanks.
It seems that HTC disabled console.log on Android 2.2 devices. check out this post:
How to display console.log() output in PhoneGap app using Eclipse and HTC Desire HD?
I just tested on 2.2 (level 8). It's working fine. Not sure why you're not seeing it. I would validate the setting of ChromeClient.
js contains...
console.log("Hello World");
console.error("Serious");
ChromeClient contains
#Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
// TODO Auto-generated method stub
Log.v("ChromeClient", "invoked: onConsoleMessage() - " + sourceID + ":"
+ lineNumber + " - " + message);
super.onConsoleMessage(message, lineNumber, sourceID);
}
#Override
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.v("ChromeClient", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
Log contains
03-16 15:53:12.309: VERBOSE/ChromeClient(595): Hello World -- From line 24 of file:///android_asset/base.js
03-16 15:53:12.309: VERBOSE/ChromeClient(595): Serious -- From line 25 of file:///android_asset/base.js

Categories

Resources