gpt4 book ai didi

android - 自定义 android gradle 插件无法加载类

转载 作者:行者123 更新时间:2023-12-03 05:32:29 26 4
gpt4 key购买 nike

我想构建一个自定义 gradle 插件,但是当我让根项目应用插件时它总是失败。

ERROR: Unable to load class 'com.ucloud.android.plugin.UpluginImpl'.
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.


我的插件类是:
package com.ucloud.android.uplugin

import org.gradle.api.Plugin
import org.gradle.api.Project

class UpluginImpl implements Plugin<Project> {

@Override
void apply(Project project) {
project.task("Test Ucloud Task") << {
println("********************* Task *********************")
}
}
}

我的插件模块的 build.gradle 文件是:
apply plugin: 'groovy'
apply plugin: 'maven'

repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation gradleApi()
implementation localGroovy()
implementation 'com.android.tools.build:gradle:3.5.0'
}

sourceCompatibility = "8"
targetCompatibility = "8"

group = 'com.ucloud.android.plugin'
version = '1.0.2'
archivesBaseName='ucloud-plugin'

uploadArchives { //当前项目可以发布到本地文件夹中
repositories {
mavenDeployer {
repository(url: uri('/Users/joshua/.m2/repository/')) //定义本地maven仓库的地址
}
}
}


我的模块/资源/META-INF/gradle-plugins/***.properties
implementation-class = com.ucloud.android.plugin.UpluginImpl

我什至尝试完全卸载 Android Studio,删除 Studio 的所有缓存目录。并删除我的 .gradle 目录。错误仍然在这里...

最佳答案

您缺少应用插件.. 所以 gradle 会知道在哪里可以找到插件:

apply plugin: UpluginImpl

关于android - 自定义 android gradle 插件无法加载类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58538998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com