java - Cannot call the API using Swagger-UI's jar file -
i generated classes using http://swagger.io/ , got zip files contains classes , models.
when compile jar file , add project jar lib gives me error:
05-09 17:22:37.894 4589-4589/? e/reporthandler: fatal exception: main java.lang.noclassdeffounderror: failed resolution of: lorg/apache/http/consts; @ io.swagger.client.apiinvoker.<clinit>(apiinvoker.java:66) @ io.swagger.client.api.userauthenticationapi.<init>(userauthenticationapi.java:22) @ com.selfdrvn.selfdrvn.activities.loginactivity$1.onclick(loginactivity.java:99) @ android.view.view.performclick(view.java:4780) @ android.view.view$performclick.run(view.java:19866) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) caused by: java.lang.classnotfoundexception: didn't find class "org.apache.http.consts" on path: dexpathl,nativelibrarydirectories=[/vendor/lib, /system/lib]] @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56) @ java.lang.classloader.loadclass(classloader.java:511) @ java.lang.classloader.loadclass(classloader.java:469) @ io.swagger.client.apiinvoker.<clinit>(apiinvoker.java:66) @ io.swagger.client.api.userauthenticationapi.<init>(userauthenticationapi.java:22) @ com.selfdrvn.selfdrvn.activities.loginactivity$1.onclick(loginactivity.java:99) @ android.view.view.performclick(view.java:4780) @ android.view.view$performclick.run(view.java:19866) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) suppressed: java.lang.classnotfoundexception: org.apache.http.consts @ java.lang.class.classforname(native method) @ java.lang.bootclassloader.findclass(classloader.java:781) @ java.lang.bootclassloader.loadclass(classloader.java:841) @ java.lang.classloader.loadclass(classloader.java:504) ... 14 more caused by: java.lang.noclassdeffounderror: class not found using boot class loader; no stack available
this build.gradle
file swagger generated library:
group = 'io.swagger' project.version = '1.0.0' buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.+' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' android { compilesdkversion 22 buildtoolsversion '23.0.2' // uselibrary 'org.apache.http.legacy' defaultconfig { minsdkversion 14 targetsdkversion 23 } compileoptions { sourcecompatibility javaversion.version_1_7 targetcompatibility javaversion.version_1_7 } // rename aar correctly libraryvariants.all { variant -> variant.outputs.each { output -> def outputfile = output.outputfile if (outputfile != null && outputfile.name.endswith('.aar')) { def filename = "${project.name}-${variant.basename}-${version}.aar" output.outputfile = new file(outputfile.parent, filename) } } } } ext { swagger_annotations_version = "1.5.0" gson_version = "2.3.1" httpclient_version = "4.5.2" httpcore_version = "4.4.4" junit_version = "4.12" } dependencies { compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "com.google.code.gson:gson:$gson_version" compile "org.apache.httpcomponents:httpcore:$httpcore_version" compile "org.apache.httpcomponents:httpclient:$httpclient_version" compile ("org.apache.httpcomponents:httpcore:$httpcore_version") { exclude(group: 'org.apache.httpcomponents', module: 'httpclient') } compile ("org.apache.httpcomponents:httpmime:$httpclient_version") { exclude(group: 'org.apache.httpcomponents', module: 'httpclient') } testcompile "junit:junit:$junit_version" } afterevaluate { android.libraryvariants.all { variant -> def task = project.tasks.create "jar${variant.name.capitalize()}", jar task.description = "create jar artifact ${variant.name}" task.dependson variant.javacompile task.from variant.javacompile.destinationdir task.destinationdir = project.file("${project.builddir}/outputs/jar") task.archivename = "${project.name}-${variant.basename}-${version}.jar" artifacts.add('archives', task); } } task sourcesjar(type: jar) { android.sourcesets.main.java.srcdirs classifier = 'sources' } artifacts { archives sourcesjar }
can help?
if try generate default template swagger-editor apache http version.
clone swagger-codegen project github, follow instructions , make client using volley, okhttp-gson, retrofit, etc..
update
to generate android volley client:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i <your_path_to_swagger.json> -l android --library=volley -o <output_path>
to generate java okhttp-gson:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i <your_path_to_swagger.json> -l java --library=okhttp-gson -o <output_path>
in both case after have generated project navigate project folder , use
mvn package
and fild library jar on \target
Comments
Post a Comment