【问题标题】:How to use jar file in gradle 3 or above?如何在 gradle 3 或更高版本中使用 jar 文件?
【发布时间】:2019-07-18 06:09:29
【问题描述】:

在我的项目中,“app”模块还使用放置在其依赖模块之一中的 jar 库。当我使用 Gradle 2 和 Gradle Plugin 2.3 时效果很好。然后我将 Gradle 版本更新到 5.1.1,将 Android Gradle Plugin 版本更新到 3.4.2 并遇到以下问题。

如果我将 jar 放在两个模块的 libs 文件夹中,则会出现第一个屏幕截图中的错误。但是,如果我删除“app”模块中的 jar,它只是无法识别 jar 中的类,如第二个屏幕截图所示。当我使用旧的 Gradle 时,它​​能够使用这些类。




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'
}

【问题讨论】:

标签: java android gradle


【解决方案1】:

我认为你的实现是错误的。首先你必须把你的罐子 文件在您的 libs 文件夹中。然后在你的 gradle 中添加implementation files('libs/your_jar.jar')

【讨论】:

    【解决方案2】:

    将aar添加到项目中的lib文件夹后,必须在项目根目录中的build.gradle中添加以下行

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

    并将下面的行添加到 gradle.build 模块(例如 app ,...)

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

    否则使用自爆代码

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

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 2020-04-16
      • 1970-01-01
      • 2015-09-25
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      相关资源
      最近更新 更多