我正在尝试在android studio中加载本机库。我的项目构建并运行但在尝试加载.so文件时抛出错误。
我的项目结构是:
我的Gradle文件是:
var filters = [...];
var columns = [...];
var results = [];
var savedsearch = nlapiCreateSearch( 'customrecord_mybigfatlist', filters, columns );
var resultset = savedsearch.runSearch();
var searchid = 0;
do {
var resultslice = resultset.getResults( searchid, searchid+1000 );
for (var rs in resultslice) {
results.push( resultslice[rs] );
searchid++;
}
} while (resultslice.length >= 1000);
return results;
我正在尝试加载以下文件:
import com.android.build.gradle.tasks.PackageApplication
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:22.1.1'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
/*
signingConfigs {
release {
storeFile file(System.console().readLine("\n\$ Enter keystore path: "))
storePassword System.console().readLine("\n\$ Enter keystore password: ")
keyAlias System.console().readLine("\n\$ Enter key alias: ")
keyPassword System.console().readLine("\n\$ Enter key password: ")
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
*/
getNdkDirectory()
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
buildTypes {
debug {
debuggable true
jniDebuggable true
}
}
}
/*
* JNI Hack for gradle - works alright, copies native libs over into build folder no problem
* https://gist.github.com/khernyo/4226923
*/
task copyNativeLibs(type: Copy) {
from(new File('libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'native-libs'))
}
我收到以下错误:
static {
System.loadLibrary("NativeAudio");
}
我尝试了许多参考但无法解决问题。使用Android Studio和Gradle版本:1.2.3
答案 0 :(得分:1)
与带ADT的Eclipse不同,默认情况下,使用Android插件的gradle会在src/main/jniLibs
文件夹中查找本机库。
您可以在以下源集中更改该文件夹位置:
android {
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
}
}