简体   繁体   中英

Unable to find classes from Android module created from .jar file

I have an app named 'fibonacci' and a jar file created from swagger-codegen called swagger-java-client-1.0.0 (build within Android studio in a separate project).

The swagger-client is brought in as a module following the instructions at the link below. https://developer.android.com/studio/projects/android-library

Structure looks like this: 在此处输入图像描述

The dependencies section for the app is:

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.2'
    implementation 'androidx.navigation:navigation-ui:2.3.2'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation project(path: ':swagger-java-client-1.0.0')
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

The top-level settings.gradle is this:

include ':app', ':swagger-java-client-1.0.0'
rootProject.name = "Fibonacci"

The build.gradle for the swagger module is this:

configurations.maybeCreate("default")
artifacts.add("default", file('swagger-java-client-1.0.0.jar'))

When I get to the code that tries to reach the client, the app crashes because the classes (eg ApiClient) aren't found.

    ApiClient defaultClient = new ApiClient();  
    OAuth strava_oauth = (OAuth) defaultClient.getAuthentication("strava_oauth");
    strava_oauth.setAccessToken(access_token);

    // try to get some activities here
    ActivitiesApi apiInstance = new ActivitiesApi();
    List<SummaryActivity> result =
            apiInstance.getLoggedInAthleteActivities( 1609522135,
                    1546363735,
                    1,
                    30);

I've been looking but I can't find anything that describes how to have the classes in the jar file compile with the rest of the project, which I assume is the problem. The app compiles and deploys just fine, the error occurs at run-time.

The answer was that the jar file 'swagger-java-client-1.0.0.jar' only contained sources. This is what was generated automatically by the gradle build and I didn't question it at first. I was able to generate a jar with the.class files instead from the command line using:

jar cvf swagger-java-client-1.0.0.jar *

from the generated/java/build/classes/java/main folder. Once I imported this as a module, not only the did the compile work, but the swagger-generated classes were also found at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM