【问题标题】:I am trying to use junit with apt plugin我正在尝试将 junit 与 apt 插件一起使用
【发布时间】:2016-03-22 18:13:39
【问题描述】:

我正在尝试在我的 android 应用程序中使用 JUnit。我有这个 build.gradle/app 配置:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.myproject.tv"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


repositories { jcenter() }

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName android.defaultConfig.applicationId
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12' //added
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.android.support:recyclerview-v7:23.2.0'
    compile 'com.android.support:leanback-v17:23.2.0'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.github.bumptech.glide:glide:3.4.+'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
    compile 'com.android.support:support-v4:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.danikula:videocache:2.3.3'
    compile 'org.androidannotations:androidannotations-api:3.3.2'
    apt 'org.androidannotations:androidannotations:3.3.2'
    compile 'com.google.dagger:dagger:2.0.2'
    apt 'com.google.dagger:dagger-compiler:2.0.2'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

当我运行应用程序时:

Error:(28, 0) Cannot get property 'processResources' on null object
<a href="openFile:E:\AndroidProject\JoinTV\app\build.gradle">Open File</a>

第 28 行是:

26 apt {
27    arguments {
28        androidManifestFile variant.outputs[0].processResources.manifestFile
29        resourcePackageName android.defaultConfig.applicationId
30    }
31}

如何在我的 gradle 中解决这个问题???

【问题讨论】:

    标签: java android unit-testing junit android-gradle-plugin


    【解决方案1】:
    Try this. It worked for me.
    <pre><code>  
        apt {
            arguments {
                androidManifestFile variant.outputs[0]?.processResources?.manifestFile
                resourcePackageName android.defaultConfig.applicationId
            }
        }
    </code></pre>
    

    【讨论】:

    • 是的,它与 testCompile 'junit:junit:4.12' 一起使用,它解决了操作的问题
    【解决方案2】:

    我遇到了同样的问题

    删除testCompile 'junit:junit:4.12' //添加

    然后同步你会修复的

    【讨论】:

    • 这不是答案。 OP 想在你的项目中使用junit
    猜你喜欢
    • 2019-02-17
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多