How to execute a HttpRequest of type HttpRequestMode.Post

That verify error is weird. I’ll take a look.

@ck If it helps, this happens for every HttpRequest like:

Http.ExecuteRequestAsJson( Url(url), jsonCallback)

or Http.ExecuteRequest, were this one this was for a HttpRequestMode.Post.

So this:

import Sugar

let jsonCallback: HttpContentResponseBlock<Sugar.Json.JsonDocument!>! = {
  response in 
    writeLn(response)
}
Http.ExecuteRequestAsJson( Url("http://blogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=myFunc"), jsonCallback)

writeLn("meh")

in java should have failed? Or only on Android? Seems to work on Java.

@ck It fails in Android.

Just tried this:

import java.util
import android.app
import android.content
import android.os
import android.util
import android.view
import android.widget
import Sugar

public class MainActivity: Activity {

	public override func onCreate(savedInstanceState: Bundle!) {
		super.onCreate(savedInstanceState)
		ContentView = R.layout.main


        
let jsonCallback: HttpContentResponseBlock<Sugar.Json.JsonDocument!>! = {
  response in 
    writeLn(response)
}
Http.ExecuteRequestAsJson( Url("http://blogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=myFunc"), jsonCallback)

writeLn("meh")

	}
}

with:


  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

and a Jellybean (4.2) emulator. Works fine? (Last beta)

@ck thanks let me try to figure out what’s going on.

Im running: Fire (8.3.90.1951), Sugar commit e190f0243ce880db5eebaeab86f948a7aa9e5178, testing on Nexus 7, Android 6.0.1.

What I see with this set up is the issue reported here: Fire Beta: Unable to run template Android Application (Swift)

so that Fire get stuck before deploy the Android Application template to the device:

Installing org.me.androidsilversampleapp Calling adb -s 0a21584f install -r "/Users/admin/Projects/MusiXmatch/MXMPortableNETLib/Samples/AndroidSilverSampleApp/./bin/Release/AndroidSilverSampleApp.apk" The process failed to start with the following error:

Then, having no option, I try with AndroidStudio 1.5.1, API Level 23, Marshmallow.
Here before pulling Sugar to latest develop commit (I presume) I get this verifier error:

03-03 14:35:07.048 24771-24732/musixmatch.com.sampleandroidapp W/art: Verification failed on class sugar.Http in /data/app/musixmatch.com.sampleandroidapp-2/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)

Maybe, bu this is my supposition, is that those two errors are related in some way.

I don’t think the 'stcuk during deploy" is related. Can you send the exact project you used?

Let me know a fresh install, kill adb, etc since it could be a wrong or misconfigured environment issue first. Back with the project asap.

Sorry I meant unrelated.

@ck So I have

  • killed adb
  • restared the mac and the device;
  • installed Xamarin emulator just to be sure it was something not related to my configuration of AndroidStudio VDs;

tried now in this first test my configuration with

Xamarin Android Player / Nexus 7 Marshmallow

and I get the same

03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp I/art: Verification error in sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp I/art: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) failed to verify: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest): [0x82] thrown class Precise Reference: sugar.HttpResponse not instanceof Throwable
03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp W/art: Verification failed on class sugar.Http in /data/app/musixmatch.com.sampleandroidapp-1/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)

The application is here:

https://github.com/loretoparisi/swift-promise-example/tree/master/SampleAndroidApp

Doing further tests.

@ck Which was your API level?
Btw, I have found which is the issue with debugger (see Fire Beta: Unable to run template Android Application (Swift)).
Now looking at this error again…

@ck after 2 hours struggling with my config having

Fire + Android Xamarin Player / Nexus7 (marshmellow) / API Level 23 + Sugar/Sugar.data latest commit, I was able to reproduce this error in Fire as well!

Here is a screen:

and the logcat from adb:

03-03 17:25:55.851 2150 2150 I art : Verification error in sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) 03-03 17:25:55.851 2150 2150 I art : sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) failed to verify: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest): [0x82] thrown class Precise Reference: sugar.HttpResponse not instanceof Throwable 03-03 17:25:55.866 2150 2150 W art : Verification failed on class sugar.Http in /data/app/org.me.androidsilversampleapp-2/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)

while the Fire console says:

Installing org.me.androidsilversampleapp Calling adb -s 10.71.34.101:5555 install -r "/Users/admin/Projects/MusiXmatch/MXMPortableNETLib/Samples/AndroidSilverSampleApp/./bin/Debug/AndroidSilverSampleApp.apk" Started Process started. An exception of type: android.system.ErrnoException occurred and was ignored An exception of type: android.system.ErrnoException occurred and was ignored Fatal exception on thread 0003 () Type: java.lang.VerifyError Message: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) (declaration of 'sugar.Http' appears in /data/app/org.me.androidsilversampleapp-2/base.apk)

I’m not sure if I can get more stack trace from here…

I don’t see org.me.androidsilversampleapp on https://github.com/loretoparisi/swift-promise-example ?

Yes I have two projects but basically the code it’s the same :wink:

So I rebuild sugar.data, opened SampleAndroidAppFire,
fixed the projitems reference (which was hardcoded),
fixed the sugar reference,
ran a matching android virtual machine.
Ran the android app.

Noticed the security exception and added:

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Then I finally got an:

  •   error	{java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]}	java.lang.Exception
    

and the other one.

Just pull latest sugar and it’s fixed.

1 Like

bugs://74652 got closed with status fixed.

@ck :+1: I confirm that both bug have been fixed, closing!

A note for Android developers - Cooper, to correct let java.net.HttpURLConnection handle cookies the Android app will have to add

let cookieManager =  CookieManager( nil, CookiePolicy.ACCEPT_ALL )
CookieHandler.setDefault( cookieManager  );

before using the Sugar.Http.
This is not needed on Nougat, where the policy is by default by NSMutableURLRequest.

Logged as bugs://i62701.

bugs://i62701 was closed as fixed.