我是Android测试的初学者。我正在尝试执行 Junit 测试,但是当我加载 native 库时它会崩溃。
这是我的 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 库路径,但是如何?谢谢
最佳答案
将文件夹添加到类路径中,如下所示:https://discuss.gradle.org/t/how-to-add-to-a-test-classpath/7083
关于android - 设置 build.gradle Junit Android 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38557113/