我正在尝试添加一个本地库(在本例中是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
这帮助我实现了我想要的