0

In my project, the "app" module also uses a jar library placed in one of its dependency module. It worked fine when I use Gradle 2 and Gradle Plugin 2.3. Then I update Gradle version to 5.1.1 and Android Gradle Plugin version to 3.4.2 and meet the following issue.

If I put the jar in the libs folder of both modules, an error appears as in the first screenshot. However, if I remove the jar in the "app" module, it just doesn't recognize the classes in the jar as in the second screenshot. It was able to use those classes when I used the old Gradle.


Error when putting the jar in both modules


Error when removing the jar from app module


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13-beta-3'
    implementation 'me.zhanghai.android.materialratingbar:library:1.3.2'

    implementation 'com.flurry.android:analytics:11.6.0@aar'

    implementation project(':dayWeekLib')
    implementation (project(':zappasoft-android-support-library'))
//    {
//        exclude module: 'libs/YouTubeAndroidPlayerApi'
//        exclude group: 'com.google.android.youtube.player'
//    }

    implementation ('androidx.appcompat:appcompat:1.0.2')

    implementation ('com.google.android.material:material:1.0.0')

    implementation ('androidx.recyclerview:recyclerview:1.0.0')

    implementation ('androidx.legacy:legacy-support-v13:1.0.0')

    implementation 'org.apache.httpcomponents:httpcore:4.4.11'
    implementation 'org.apache:apache:21'
    implementation 'com.google.android.gms:play-services-plus:17.0.0'
    implementation 'com.google.apis:google-api-services-youtube:v3-rev112-1.19.0'
    implementation 'com.google.http-client:google-http-client-android:1.30.2'
    implementation 'com.google.api-client:google-api-client-android:1.30.2'
    implementation 'com.google.api-client:google-api-client-gson:1.30.2'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.okhttp3:okhttp:4.0.1'

    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
    implementation 'com.github.barteksc:android-pdf-viewer:+'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.31'
    implementation 'se.emilsjolander:stickylistheaders:2.7.0'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

    implementation ('androidx.core:core:1.0.0')

    implementation 'org.greenrobot:greendao:3.2.2'

    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.github.chrisbanes:PhotoView:2.1.0'
    implementation 'com.opencsv:opencsv:4.4'
    implementation 'xmlwise:xmlwise:1.2.11'

    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
}
Vinh Hung Nguyen
  • 139
  • 1
  • 11

2 Answers2

1

I think you implementation is wrong. First you have to put your jar file in your libs folder. then in your gradle add implementation files('libs/your_jar.jar')

Tariqul Islam
  • 680
  • 6
  • 14
0

After adding aar to the lib folder in the project must be added the line below to build.gradle in the project root

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

And add the line below to gradle.build module (such as app , ….)

implementation files('lib-name-x.x.x.jar') 

in otherwise using blew code

 implementation fileTree(dir: 'libs', include: '*.jar'))