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

查看:380
本文介绍了无法使用@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中,我有

  android {
compileSdkVersion 25
buildToolsVersion25.0.2

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName1.0

testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner

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

 配置{
javadocDeps
}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
compilecom.android.support: appcompat-v7:$ supportLibraryVersion
compilecom.android.support:support-annotations:$supportLibraryVersion

javadocDepsc om.android.support:support-annotations:$supportLibraryVersion

我部署的到JFrog BinTray,然后尝试在我的应用程序中使用它。我必须从库依赖项中排除appcompat-v7和支持注释,但是我的构建依然失败:


错误:未能解决: annotationProcessor

现在我被卡住了,尝试了很多东西,但没有任何帮助。我不能用这个库建立主项目。
我是否需要实现任何自定义AnnotationProcessor才能使用@ IntDef's?

解决方案

已经能够克服这个问题!

它看起来像自定义注释的情况下自定义注释处理器也是必需的。目前我已决定跳过创建自定义注释处理器,并且不使用自定义注释来枚举@IntDef。



但是,无论如何,如果您的库使用现有注释并且发布它在mavenCentral或jCenter或其他存储库上,并在其他项目中使用它,您需要为javadoc任务添加一些魔力。



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


 配置{
javadocDeps
}
依赖关系{
// ...
compile(com.android.support:support-annotations:$supportLibraryVersion){
传递错误;
}
javadocDepscom.android.support:support-annotations:$supportLibraryVersion
}

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

 任务androidJavadocs(类型:Javadoc){
source = android.sourceSets.main.java.source

//这是神奇的
classpath + = configurations.javadocDeps
$ b $ classpath + = project.files(android.getBootClasspath()。join(File.pathSeparator))
}

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


I have the following code in my library:

@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;
}

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"]
            }
        }
    }
}

and

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"
}

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:

Error:Failed to resolve: annotationProcessor

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!

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.

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.

It starts here: https://github.com/vulko/AnimatedArcProgressView/blob/master/library/build.gradle with

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

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))
}

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

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

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