Reputation: 13
I'm trying to follow this tutorial to integrate MFP 7.1 SDK
into a native android application. The application is built using latest Studio 1.5.1
. The MFP android native API component is deployed on my development server. For testing purposes, I set the Application Access on native API to "active, notifying" because I want to see the pop-up appear in Android app. When I invoke WLClient
connect call from Java
code, I see the following class cast exception
. The application does not crash however I do not see the active notification dialog/pop-up.
02-05 01:57:07.010 2992-2992/com.ibm.test.myapplication I/art: Not late-enabling -Xcheck:jni (already on)
02-05 01:57:07.130 2992-3011/com.ibm.test.myapplication W/com.worklight.common.Logger: com.worklight.common.Logger.setContext(Context) must be called to fully enable debug log capture. Currently, the 'capture' flag is set but the 'context' field is not. This warning will only be printed once.
02-05 01:57:07.130 2992-3011/com.ibm.test.myapplication D/wl.request: WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://192.168.1.3:10080/MFPNativeApps/authorization/v1/clients/instance
02-05 01:57:07.130 2992-3011/com.ibm.test.myapplication D/WLClient: WLClient$ActivityListener.onActivityStarted in WLClient.java:1476 :: on activity started com.ibm.test.myapplication.MainActivity
02-05 01:57:07.130 2992-3011/com.ibm.test.myapplication D/WLClient: WLClient$ActivityListener.onActivityResumed in WLClient.java:1465 :: on activity resumed com.ibm.test.myapplication.MainActivity . activity count = 1
02-05 01:57:07.130 2992-3013/com.ibm.test.myapplication D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: java.lang.ClassCastException: com.worklight.wlclient.WLPersistentCookieStore cannot be cast to org.apache.http.client.CookieStore
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:93)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:295)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:165)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:413)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at com.worklight.wlclient.WLRequestSender.run(WLRequestSender.java:47)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-05 01:57:07.140 2992-3012/com.ibm.test.myapplication W/System.err: at java.lang.Thread.run(Thread.java:818)
02-05 01:57:07.150 2992-3011/com.ibm.test.myapplication D/wl.certManager: WLCertManager.clearKeystore in WLCertManager.java:258 :: Key store cleared.
02-05 01:57:07.200 2992-3013/com.ibm.test.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
02-05 01:57:07.220 2992-3013/com.ibm.test.myapplication D/OpenGLRenderer: Enabling debug mode 0
02-05 01:57:07.220 2992-3013/com.ibm.test.myapplication W/EGL_emulation: eglSurfaceAttrib not implemented
02-05 01:57:07.220 2992-3013/com.ibm.test.myapplication W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3fd8e60, error=EGL_SUCCESS
Here's my application gradle file. Note that I tried the tutorial recommended ibmmobilefirstplatformfoundation pom 7.1.0.0 as well without any luck. The gradle below uses 7.1.5.
apply plugin: 'com.android.application'
repositories{
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.ibm.test.myapplication"
minSdkVersion 22
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
pickFirst 'META-INF/ASL2.0'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/NOTICE'
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.ibm.mobile.foundation:ibmmobilefirstplatformfoundation:7.1.5@aar'
}
Finally, here's the MainActivity Java code:
package com.ibm.test.myapplication;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.worklight.wlclient.api.WLClient;
import com.worklight.wlclient.api.WLFailResponse;
import com.worklight.wlclient.api.WLResponse;
import com.worklight.wlclient.api.WLResponseListener;
public class MainActivity extends AppCompatActivity implements WLResponseListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
WLClient.createInstance(this).connect(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onSuccess(WLResponse var1) {}
public void onFailure(WLFailResponse var1) {}
}
Upvotes: 0
Views: 300
Reputation: 13
I think I found the answer. It was a silly mistake in gradle file. I had to use the following loopj version: compile 'com.loopj.android:android-async-http:1.4.8'
. I have added comments to the tutorial for someone who runs into this problem again.
Upvotes: 1