Description
Description
I'm using the Swagger Android export to autogenerate the structures and client code for a REST API. I made a tool to apply some JAVA syntax fixes to get the Android Studio project to compile. I have some Gradle compile issues (upgrade, and dependency) that I apply so that the APK can be created. And then when using the EndPoint, I'm getting timeouts and the client doesn't appear to connect at all. This could either be a client, or dependency issue.
Swagger-codegen version
I'm using the online editor so maybe 2.0? http://editor.swagger.io/#/
Swagger declaration file content or url
In the Swagger editor, load the URL:
https://polling.arena.razerzone.com/swagger/docs/v1
Command line used for generation
Generate Client for Android.
Steps to reproduce
-
Load the url in the editor.
-
Generate the Android Client.
-
Unzip and open the project in Android Studio.
-
Upgrade gradle when prompted.
-
I've made a temporary Windows.Form tool that you run on the root Android project directory to fix the enum and Object syntax errors.
https://github.com/tgraupmann/SwaggerAndroidClientFixer
- Add an Android app module with an Activity and reference the library. Here's some Gradle info for the build tools and target API versions.
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
-
Rebuild the project.
-
At this point Gradle warnings will appear. Are these warnings important?
Warning:Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debugAndroidTest as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for release as it may be conflicting with the internal version provided by Android.
- Hit Run which will display Gradle errors. What's the best way to resolve these errors?
Error:Execution failed for task ':swaggerapp:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\timot\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpclient-android\4.3.3\39ba75b570e5f1535356e8a1bf920b1c6cc83a9a\httpclient-android-4.3.3.jar
File2: C:\Users\timot\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.4.4\b31526a230871fbe285fbcbe2813f9c0839ae9b0\httpcore-4.4.4.jar
File3: C:\Users\timot\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpmime\4.5.2\22b4c53dd9b6761024258de8f9240c3dce6ea368\httpmime-4.5.2.jar
- Is this Gradle setting the best way to deal with the above error?
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
- Using the above fix, what’s the best way to resolve these errors?
Error:Execution failed for task ':swaggerapp:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/DEPENDENCIES
File1: C:\Users\timot\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.4.4\b31526a230871fbe285fbcbe2813f9c0839ae9b0\httpcore-4.4.4.jar
File2: C:\Users\timot\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpmime\4.5.2\22b4c53dd9b6761024258de8f9240c3dce6ea368\httpmime-4.5.2.jar
- Is this Gradle setting the best way to deal with the above error?
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
- The following activity code should use the Swagger Android client. The expected result would be a 200 status with an error message about needing a client API key. Instead I get a timeout.
package com.example.swaggerapp;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;
import io.swagger.client.api.LookupsControlEndpointApi;
import io.swagger.client.model.ResponseOutputModelListGamingServerRegionModel;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
LookupsControlEndpointApi apiInstance = new LookupsControlEndpointApi();
try {
Log.d(TAG, "*** Invoke: lookupsGamingServerRegions");
ResponseOutputModelListGamingServerRegionModel result = apiInstance.lookupsGamingServerRegions();
Log.d(TAG, "*** Got Result: lookupsGamingServerRegions");
System.out.println(result);
} catch (Exception e) {
Log.d(TAG, "*** Exception: lookupsGamingServerRegions");
Toast.makeText(MainActivity.this, "Exception when calling LookupsControlEndpointApi#lookupsGamingServerRegions", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
}
- Given that the client runs, the Android Client gets a timeout unable to connect to the REST services. Is this caused by the fixes above?
11-30 11:33:52.769 18605-18605/com.example.swaggerapp I/art: Late-enabling -Xcheck:jni
11-30 11:33:52.859 18605-18605/com.example.swaggerapp W/System: ClassLoader referenced unknown path: /data/app/com.example.swaggerapp-1/lib/arm
11-30 11:33:52.863 18605-18605/com.example.swaggerapp I/InstantRun: Instant Run Runtime started. Android package is com.example.swaggerapp, real application class is null.
11-30 11:33:54.058 18605-18605/com.example.swaggerapp W/System: ClassLoader referenced unknown path: /data/app/com.example.swaggerapp-1/lib/arm
11-30 11:33:54.211 18605-18719/com.example.swaggerapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-30 11:33:54.285 18605-18605/com.example.swaggerapp D/MainActivity: *** Invoke: lookupsGamingServerRegions
11-30 11:33:54.312 18605-18738/com.example.swaggerapp W/System: ClassLoader referenced unknown path: /system/framework/tcmclient.jar
11-30 11:34:24.292 18605-18605/com.example.swaggerapp D/MainActivity: *** Exception: lookupsGamingServerRegions
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: java.util.concurrent.TimeoutException
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at com.android.volley.toolbox.RequestFuture.doGet(RequestFuture.java:121)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at com.android.volley.toolbox.RequestFuture.get(RequestFuture.java:97)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at io.swagger.client.ApiInvoker.invokeAPI(ApiInvoker.java:381)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at io.swagger.client.api.LookupsControlEndpointApi.lookupsGamingServerRegions(LookupsControlEndpointApi.java:620)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at com.example.swaggerapp.MainActivity$1.run(MainActivity.java:30)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at android.os.Looper.loop(Looper.java:148)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5461)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at java.lang.reflect.Method.invoke(Native Method)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-30 11:34:24.325 18605-18605/com.example.swaggerapp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-30 11:34:24.326 18605-18605/com.example.swaggerapp I/Choreographer: Skipped 1805 frames! The application may be doing too much work on its main thread.
11-30 11:34:24.347 18605-18719/com.example.swaggerapp I/OpenGLRenderer: Initialized EGL, version 1.4
11-30 11:34:24.372 18605-18719/com.example.swaggerapp D/mali_winsys: new_window_surface returns 0x3000
11-30 11:34:24.521 18605-18719/com.example.swaggerapp D/mali_winsys: new_window_surface returns 0x3000
11-30 11:34:24.566 18605-18719/com.example.swaggerapp V/RenderScript: 0xb7d04990 Launching thread(s), CPUs 2
Related issues
Suggest a Fix
I need insight to what might be happening.
I'm using a tool to make syntax fixes when I should fix the raw export templates.
From debugging, it looks like the Swagger client puts a request in the queue and waits for the request to complete. The request might not actually happen...