Gradle 尝试添加本地库时出现问题
Gradle Issue when trying to add local library
我正在尝试添加一个本地库(在本例中是 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-运行time-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
这帮助我实现了我想要的
我正在尝试添加一个本地库(在本例中是 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-运行time-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 这帮助我实现了我想要的