android - 尝试添加本地库时出现Gradle问题

标签 android android-studio gradle dependencies butterknife

我正在尝试添加一个本地库(在本例中是Butterknife,是的,我知道它已被弃用),但遇到了一些麻烦。

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
buildscript {
repositories {
    jcenter()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
    google()
}
dependencies {
    classpath "com.android.tools.build:gradle:3.6.1"
    classpath files('libs/butterknife-gradle-plugin-10.2.1.jar')
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'], excludes: ['butterknife-compiler-10.2.1.jar', 'butterknife-gradle-plugin-10.2.1.jar'])
api fileTree(dir: 'libs', include: ['*.aar'])
annotationProcessor files('libs/butterknife-compiler-10.2.1.jar')
这是我的gradle的相关部分的外观,我在本地添加了以下内容(从maven下载)到libs目录:butterknife-10.2.1.aar,butterknife-annotations-10.2.1.jar,butterknife-compiler-10.2 .1.jar,butterknife-gradle-plugin-10.2.1.jar,butterknife-runtime-10.2.1.aar。
我知道我可以用另一种方式添加库,但是我需要从本地文件中添加库。 Gradle同步成功,然后当我尝试运行该应用程序时,出现以下错误:
Unable to load class 'butterknife.OnCheckedChanged'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

最佳答案

我没有尝试手动添加每个库,而是找到了一个替代方法
https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_copy
这帮助我实现了我想要的

关于android - 尝试添加本地库时出现Gradle问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63054735/

相关文章:

android - 检索项目 : No resource found 的父级时出错

java - 无法访问服务项目中的 Cordapp 流

android - 如何在 KitKat 版本之前的 Android 中获取短信应用程序(默认)的包名?

android - Retrofit2:使用正文与查询

android - Gradle-如何在依赖项部分中使用我自己的库

android - 属性(android :textSize ="?android:attr/textAppearanceMedium") throws error

android - 生物识别提示 : how to encrypt few strings?

android - "APK Signature Scheme v2"只有 "apksigner"不支持 "jarsigner"

java - 启动 Android Studio 时出错 : Failed to create JVM: error code-6

java - Gradle lint 和测试构建错误 - JAXBException 和库中无效的包引用