小编Mic*_*sel的帖子

别名是带参数的注释

我正在尝试将我的 Android 库转换为 Kotlin 多平台库。

我想保留的一件事是所有针对 Android Lint 的 android 特定注释。我能够通过做一些简单的事情来转换其中的大部分,比如

@MustBeDocumented
@Retention(AnnotationRetention.BINARY)

@Target(
    AnnotationTarget.FUNCTION,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.PROPERTY_SETTER,
    AnnotationTarget.CONSTRUCTOR,
    AnnotationTarget.ANNOTATION_CLASS,
    AnnotationTarget.CLASS,
    AnnotationTarget.VALUE_PARAMETER
)
expect annotation class MainThread()

actual typealias MainThread = androidx.annotation.MainThread
Run Code Online (Sandbox Code Playgroud)

这不起作用,RestrictTo因为它需要一个论点。

androidRestrictTo注释看起来像

@Retention(CLASS)
@Target({ANNOTATION_TYPE,TYPE,METHOD,CONSTRUCTOR,FIELD,PACKAGE})
public @interface RestrictTo {

    /**
     * The scope to which usage should be restricted.
     */
    Scope[] value();

    enum Scope {
    }
}
Run Code Online (Sandbox Code Playgroud)

我似乎无法让编译器对值的类型感到满意。

如果我让期望看起来像

@Target(
    AnnotationTarget.FUNCTION,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.PROPERTY_SETTER,
    AnnotationTarget.FIELD,
    AnnotationTarget.CONSTRUCTOR,
    AnnotationTarget.ANNOTATION_CLASS,
    AnnotationTarget.CLASS
)
@MustBeDocumented
@Retention(AnnotationRetention.BINARY)
expect annotation class RestrictTo(vararg val value: …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-multiplatform

8
推荐指数
1
解决办法
448
查看次数

覆盖率报告称使用gradle对android进行零覆盖

我一直无法获得代码覆盖率来处理我的任何Android项目.

为简化起见,我创建了一个新项目(选定的空活动).在src/main/java中为项目添加了一个新的实用程序类.

然后我在src/androidTest/java中为它创建了一个单元测试.

更新了gradle文件以启用覆盖.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.michaelkrussel.coverageapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    jacoco {
        version "0.7.1.201405082137"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
             testCoverageEnabled true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
}
Run Code Online (Sandbox Code Playgroud)

我使用./gradlew createDebugCoverageReport运行测试.单元测试显示我创建的测试通过,但覆盖率报告报告零覆盖.

我假设我要么丢失gradle文件中的某些内容,要么没有运行正确的gradle任务,但我无法弄清楚是什么.

java android jacoco android-gradle-plugin

5
推荐指数
1
解决办法
1436
查看次数