gpt4 book ai didi

android - RestrictTo 不限制受限方法的使用

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:10:44 24 4
gpt4 key购买 nike

我已经将我的图书馆项目的一个方法注释为受限 @RestrictTo(Scope.LIBRARY) 甚至尝试了 @RestrictTo(Scope.LIBRARY_GROUP) 但这并没有阻止 API在项目的其他模块中使用。我什至尝试在两个模块中设置 group=xxxgroup=yyy

enter image description here

限制API调用

enter image description here

Android Studio 没有显示错误/警告。

enter image description here为受限 API 启用事件 lint。

我什至尝试使用 ./gradlew lint 在调用方模块上运行 lint

请在 Github 上找到实现

库模块 - 异步任务处理器

尝试设置不同的组 - 模块示例

尝试使用完全不同的包名 - module myapplication

不确定这里有什么问题,请帮助。

最佳答案

Scope.LIBRARY_GROUP 注释的角度来看,如果它们具有相同的 groupId,则所有模块都是一个库的一部分

Restrict usage to code within the same group of libraries. This corresponds to the gradle group ID.

要通过 Scope.LIBRARY 限制 API,您还需要使用不同的 artifactId

Restrict usage to code within the same library (e.g. the same gradle group ID and artifact ID).


需要添加库作为外部依赖。您需要构建和部署库 Artifact :

// follow answer https://stackoverflow.com/a/28361663/3926506 to build 
artifact
group = 'com.umang.asyncprocessor'
version = '1.0'

uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://[path to you repository]")
// repository(url: "file://C:/Users/Sergey/.m2/repository")
}
}
}

例如,您可以将 Artifact 部署到本地 Maven 存储库(不要忘记将 mavenLocal() 添加到项目构建脚本中)。

然后在app build.gradle文件中添加编译库的依赖:

implementation 'com.umang.asyncprocessor:async-task-processor:1.0'

不是来自项目模块:

// it doesn't work!
implementation project(path: ':async-task-processor')

我创建了 pull request使用适当的配置到您的存储库。

关于android - RestrictTo 不限制受限方法的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53069908/

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