无法使用@IntDef 注释导入 AAR 库 [英] Can't import AAR library with @IntDef annotations

查看:29
本文介绍了无法使用@IntDef 注释导入 AAR 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的库中有以下代码:

@Documented
@IntDef({OpacityAnimationType.NONE,
        OpacityAnimationType.BLINKING,
        OpacityAnimationType.SHINY,
        OpacityAnimationType.AURA,
})
public @interface OpacityAnimationType {
    int NONE = 0;
    int BLINKING = 1;
    int SHINY = 2;
    int AURA = 3;
}

在图书馆的 gradle 中我有

In gradle for library I have

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["library" : "true"]
            }
        }
    }
}

configurations {
    javadocDeps
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:$supportLibraryVersion"
    compile "com.android.support:support-annotations:$supportLibraryVersion"

    javadocDeps "com.android.support:support-annotations:$supportLibraryVersion"
}

我部署到 JFrog BinTray,然后尝试在我的应用程序中使用它.我必须从库依赖项中排除 appcompat-v7 和 support-annotations,但我的构建仍然失败:

Which I deploy to JFrog BinTray, and then try to use it in my app. I have to exclude appcompat-v7 and support-annotations from library dependency, but I build still fails with:

错误:无法解决:annotationProcessor

Error:Failed to resolve: annotationProcessor

现在我卡住了,尝试了很多方法但没有任何帮助.我无法用这个库构建主项目.我是否需要实现任何自定义 AnnotationProcessor 才能使用 @IntDef?

Now I'm stuck, tried many things but nothing helps. I can't build main project with this library. Do I need to implement any custom AnnotationProcessor to be able to use @IntDef's?

推荐答案

所以我终于能够克服这个问题了!

So finally I've been able to overcome this issue!

看起来在自定义注释的情况下也需要自定义注释处理器.现在,我决定跳过创建自定义注释处理器,而不是使用自定义注释进行 @IntDef 枚举.

It looks like in case of custom annotations custom annotation processor is also required. For now I've decided to skip creating custom annotation processor and not use custom annotations for enumerations with @IntDef.

但无论如何,如果您的库使用现有注解,并且您将其发布到 mavenCentral 或 jCenter 或其他存储库并在其他项目中使用它,则您需要为 javadoc 任务添加一些魔法.

But anyways, if your library uses existing annotations and you publish it on mavenCentral or jCenter or other repository and use it in other projects, that you'll need to add some magic to javadoc task.

从这里开始:https://github.com/vulko/AnimatedArcProgressView/blob/master/library/build.gradle

    configurations {
        javadocDeps
    }
    dependencies {
        // ...
        compile("com.android.support:support-annotations:$supportLibraryVersion") {
            transitive false;
        }   
        javadocDeps "com.android.support:support-annotations:$supportLibraryVersion"
    }

然后在此处继续发布 gradle 脚本:https://github.com/vulko/AnimatedArcProgressView/blob/master/gradle/publish-library.gradle 与:

and then continues in publishing gradle script here: https://github.com/vulko/AnimatedArcProgressView/blob/master/gradle/publish-library.gradle with:

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.source

    // this is the magic
    classpath += configurations.javadocDeps

    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

无论如何,所有代码都可以在这里找到:https://github.com/vulko/AnimatedArcProgressView/

Anyways, all the code can be found here: https://github.com/vulko/AnimatedArcProgressView/

这篇关于无法使用@IntDef 注释导入 AAR 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆