Retrofit Error - @Field parameters can only be used with form encoding


#1

Hello,

We are getting the following error message from Retrofit when trying to call, sparkCloud.requestPasswordReset('email@example.com');

Here is the full error message.

11-14 13:37:28.255 11145-14917/com.twlighting.tw D/Retrofit: ---- ERROR 
11-14 13:37:28.259 11145-14917/com.twlighting.tw D/Retrofit: java.lang.IllegalArgumentException: IdentityApi.requestPasswordReset: @Field parameters can only be used with form encoding. (parameter #1)
                                                                 at retrofit.RestMethodInfo.methodError(RestMethodInfo.java:107)
                                                                 at retrofit.RestMethodInfo.parameterError(RestMethodInfo.java:111)
                                                                 at retrofit.RestMethodInfo.parseParameters(RestMethodInfo.java:356)
                                                                 at retrofit.RestMethodInfo.init(RestMethodInfo.java:118)
                                                                 at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:294)
                                                                 at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
                                                                 at java.lang.reflect.Proxy.invoke(Proxy.java:813)
                                                                 at $Proxy1.requestPasswordReset(Unknown Source)
                                                                 at io.particle.android.sdk.cloud.ParticleCloud.requestPasswordReset(ParticleCloud.java:490)
                                                                 at com.twlighting.tw.profile.TWPasswordResetActivity$3.callApi(TWPasswordResetActivity.java:103)
                                                                 at com.twlighting.tw.profile.TWPasswordResetActivity$3.callApi(TWPasswordResetActivity.java:99)
                                                                 at io.particle.android.sdk.utils.Async$AsyncApiWorker.doInBackground(Async.java:111)
                                                                 at io.particle.android.sdk.utils.Async$AsyncApiWorker.doInBackground(Async.java:79)
                                                                 at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                 at java.lang.Thread.run(Thread.java:762)
11-14 13:37:28.259 11145-14917/com.twlighting.tw D/Retrofit: ---- END ERROR

Please advise.


#2

The second line shows the issue, and Google is quick to show some answers: https://github.com/square/retrofit/issues/1300
Seems like you’ve got some encoding issues.


#3

Thanks for the answer. We do not use Retrofit directly. We are using the Particle Setup Library to initiate the password reset.

Here is the error from the PasswordResetActivity.java

11-14 17:27:48.959 29696-29696/com.twlighting.tw E/Async: Error calling API: Unknown error communicating with server.
                                                          io.particle.android.sdk.cloud.ParticleCloudException
                                                              at io.particle.android.sdk.cloud.ParticleCloud.requestPasswordReset(ParticleCloud.java:492)
                                                              at io.particle.android.sdk.accountsetup.PasswordResetActivity$1.callApi(PasswordResetActivity.java:86)
                                                              at io.particle.android.sdk.accountsetup.PasswordResetActivity$1.callApi(PasswordResetActivity.java:83)
                                                              at io.particle.android.sdk.utils.Async$AsyncApiWorker.doInBackground(Async.java:111)
                                                              at io.particle.android.sdk.utils.Async$AsyncApiWorker.doInBackground(Async.java:79)
                                                              at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                              at java.lang.Thread.run(Thread.java:762)

I get the Retrofit error when I set the http_log_level to FULL in strings.xml

Let me know if you need anything else from me.


#4

You found a bug. Cloud sdk update should be released next week, including a fix for this issue, setup library update is coming soon as well.


#5

@julius Awesome, thank you.


#6

Just checking to see when this will be applied.


#7

Released cloudsdk 0.4.8, try it out.


#8

Thank you for @julius

That fixed the Password issue, however, we ran into another issue with DiscoverDevice activity. It happens right after the WiFi load when there are no Photons are nearby (0 results). I am posting the error log, do you have any idea why is it happening? FYI…we recently updated to Java 1.8

11-30 14:39:16.033 22120-22120/com.twlighting.tw E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.twlighting.tw, PID: 22120
                                                               java.lang.NoSuchMethodError: No virtual method io_particle_android_sdk_devicesetup_loaders_WifiScanResultLoader$$Lambda$2_lambda$new$0(Landroid/content/Context;Landroid/content/Intent;)V in class Lio/particle/android/sdk/devicesetup/loaders/WifiScanResultLoader; or its super classes (declaration of 'io.particle.android.sdk.devicesetup.loaders.WifiScanResultLoader' appears in /data/app/com.twlighting.tw-2/base.apk)
                                                                   at io.particle.android.sdk.devicesetup.loaders.WifiScanResultLoader$$Lambda$2.onReceive(Unknown Source)
                                                                   at io.particle.android.sdk.devicesetup.SimpleReceiver.onReceive(SimpleReceiver.java:46)
                                                                   at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1185)
                                                                   at android.os.Handler.handleCallback(Handler.java:751)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                   at android.os.Looper.loop(Looper.java:154)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

#9

I need more info:

  1. Android Studio 3.0 Java 1.8 or Retrolambda?
  2. Did you try cleaning project?
  3. Which version of device setup library are you using, 0.4.9?

#10

@julius here you go:

  1. Android Studio 3.0 Java 1.8
  2. Yup. Several times.
  3. Yup. 0.4.9

#11

Still trying to reproduce it. Tried to create new Android studio 3.0.1 project targeting Java 1.8 and Android sdk 27 with latest Particle libraries, called init and startDeviceSetup - works fine.

Few more questions:

  1. Is multidex enabled?
  2. Are you extending/customizing behavior of either sdk or setup libraries?
  3. Any other gradle customizations?

Could you try to create new project and try setup & sdk libraries there?


#12
  1. I tried with and without multidex, same result
  2. Not the add device functionality. We customized the Login and Register pages however.
  3. I am attaching the gradle file

I tried version switching support libraries, build tools version, and Invalidate Caches/Restart… Still getting the same issue. I see that particle is using retro-lambda. I am not very familiar with it to be honest.

I was crashing in PermissionsFragment Line 69. Any suggestions appreciated:

android {
compileSdkVersion 27
buildToolsVersion '27.0.2'
defaultConfig {
    applicationId "com.twlighting.tw"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 16
    versionName "1.6.4"
    vectorDrawables.useSupportLibrary = true
    //multiDexEnabled true
    jackOptions {
        enabled true
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
/*dexOptions {
    preDexLibraries true
    maxProcessCount 8 // Default is 4. Speeds up build.
    // Instead of setting the heap size for the DEX process, increase Gradle's
    // heap size to enable dex-in-process. To learm more, read the next section.
    // javaMaxHeapSize "2048m"
}*/
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:support-fragment:27.0.2'
compile 'com.android.support:support-annotations:27.0.2'
compile 'com.android.support:support-vector-drawable:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support:recyclerview-v7:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:gridlayout-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'

compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-maps:11.0.2'
compile 'com.google.android.gms:play-services-location:11.0.2'

compile 'io.particle:cloudsdk:0.4.8'
compile 'io.particle:devicesetup:0.4.9'
compile 'com.getbase:floatingactionbutton:1.10.0'
compile 'com.afollestad.material-dialogs:core:0.9.2.3'
compile 'com.tumblr:bookends:1.0.0'
compile 'com.squareup.okio:okio:1.11.0'
compile 'com.squareup.phrase:phrase:1.0.3'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'

compile 'com.google.guava:guava:20.0'
compile 'com.github.barteksc:android-pdf-viewer:2.7.0'

}


#13

I think your gradle classpath in project build.gradle isn’t updated to the latest version of classpath 'com.android.tools.build:gradle:3.0.1'

Note:
With 3.0.0 or later Android Studio & gradle you don’t need jackOptions block anymore.


#14

That fixed it. Thank you so much for all your help.