【问题标题】:Set up build.gradle Junit Android tests设置 build.gradle Junit Android 测试
【发布时间】:2016-07-24 21:42:17
【问题描述】:

我是 Android 测试的初学者。我正在尝试执行 Junit 测试,但是当我加载本机库时它会崩溃。

这是我的 build.gradle 文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.0.0'
    // Unit testing dependencies
    testCompile 'junit:junit:4.12'
    // Set this dependency if you want to use the Hamcrest matcher library
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    // more stuff, e.g., Mockito
    testCompile 'org.mockito:mockito-core:1.10.19'
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

当我这样做时

static
    {
        System.loadLibrary("a");
    }

我得到java.lang.UnsatisfiedLinkError: no a in java.library.path

我的测试在"src/test/java",我的本地库在"src/test/jniLibs"。我想我必须在 build.gradle 中指定 Jni 库路径,但是如何?

谢谢

【问题讨论】:

    标签: android testing gradle junit


    【解决方案1】:

    将文件夹添加到类路径中,如下所示:https://discuss.gradle.org/t/how-to-add-to-a-test-classpath/7083

    【讨论】:

      猜你喜欢
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      • 2012-11-27
      相关资源
      最近更新 更多