swagger-api / swagger-api/swagger-codegen

Cannot get generated Android client to work, DexException because of apache http client

Open
#4,069 23 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Android help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi.

Been testing the mobil generated clients (swift, objc, android/java) objective c and swift works great, but i have not been able to get android to work. First i used the client with the apache.http client dependency, but android kept refusing to install the test app i created to a device because of the internal apache http client. I then tried the Volly version, but to my suprise it still depends on the apache http client, at least the version im getting generated from the swagger codegen, so i have the same problem, i cannot make android studio build the test app to a device-

Then i tried the java one with the okhttp-gson but i cant even get android studio to work with it, i must be doing something wrong. I dont know if its me but it seems very hard to get the Swagger codegen to generate anything that can work with android studio and build to a device in a test project.

When trying to deploy my test app to device, with the Android/Volly client i get this error:

"Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
    File1: C:\Users\morten.nielsen\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpmime\4.5.2\22b4c53dd9b6761024258de8f9240c3dce6ea368\httpmime-4.5.2.jar
    File2: C:\Users\morten.nielsen\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpclient-android\4.3.3\39ba75b570e5f1535356e8a1bf920b1c6cc83a9a\httpclient-android-4.3.3.jar
    File3: C:\Users\morten.nielsen\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.4.4\b31526a230871fbe285fbcbe2813f9c0839ae9b0\httpcore-4.4.4.jar"

If i ignore the license file like this:

"        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }"

i get this error:

"Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/http/Consts;"

Im using the latest version of swagger-codegen to date

im using this command line tool to generate it:
java -jar swagger-codegen-cli.jar generate -i [path] -l android --library=volley -o /var/tmp/android/volley/

I dont know what the problem is, i use the generated client in a complete empty project with an empty activity. only thing i have done with the Android/Volly is to add it to my test project as a module and sync/build and run on device.

Im also getting the dependency warnings:
Warning: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: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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by generating the Android client with swagger-codegen-cli.jar using the shown --library=volley command, then add it as a module in an empty Android Studio project. Inspect the generated client's Gradle dependencies and the reported META-INF/LICENSE and duplicate org/apache/http/Consts errors. Done means the generated client builds and deploys to a device without those conflicts.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
build-system, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.