使用 gradle 包 org.powermock.api.easymock 不存在

package org.powermock.api.easymock does not exist using gradle

将 gradle 与 android 结合使用。

我正在尝试让 powermock 编译为依赖项。

我已经降低了使它正常工作的尝试,但它仍然无法正常工作。下面是我的 build.gradle 和 activity。我这样做只是为了演示错误并尝试使其正常工作。


//Error
error: package org.powermock.api.easymock does not exist
import org.powermock.api.easymock.PowerMock;

//build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.0"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'org.easymock:easymock:3.3.1'
    compile 'org.powermock:powermock-easymock-release-full:1.6.2'
}

//MainActivity
package android.testing.powermock;

import org.powermock.api.easymock.PowerMock;

public class MainActivity extends Activity {
    //not important
}

将此依赖项添加到您的 build.gradle

testCompile 'org.powermock:powermock-api-easymock:1.6.2'

如果您在测试之外使用它 类 将 testCompile 更改为 compile