我的目标是构建一个嵌入http://superpowered.com/库的Android。这个库提供了Android静态库(.a文件)和C++头。
我已经创建了一个模块(使用Android类型),因此它使用了超级电源库:
为了创建这个模块,我高度使用了超级电源提供的交叉例子示例。这是一个Android应用程序,现在作为第一步,我只想把它分成两个部分:一个应用程序和一个Android库。
在我的Android应用程序中,我向这个模块添加了依赖项。但是,当我调用一个调用JNI方法的方法时,我得到了以下错误:
E/art: No implementation found for void
com.example.mylib.MyDSP.onPlayPause(boolean)
(tried Java_com_example_mylib_MyDSP_onPlayPause
and Java_com_example_mylib_MyDSP_onPlayPause__Z)对为什么不起作用有什么想法吗?
来源:
在Android中:
我的java类MyDSP (MyDSP.java):
package com.example.mylib;
public class MyDSP {
public void CallJniCppMethod() {
this.onPlayPause(true);
}
private native void onPlayPause(boolean play);
static {
System.loadLibrary("SuperpoweredExample");
}
}在cpp文件中: SuperpoweredExample.cpp (SuperpoweredExample.cpp)
extern "C" JNIEXPORT void Java_com_example_mylib_MyDSP_onPlayPause(JNIEnv * __unused javaEnvironment, jobject __unused obj, jboolean play) {
//example->onPlayPause(play);
// We do nothing, but it's OK,
// Just want to see if the JNI call does not throw exception
}H文件:SuperpoweredExprese.h (SuperpoweredExample.h)
void onPlayPause(bool play);库(build.gradle)的分级配置:
应用插件:'com.android.model.library‘
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def superpowered_sdk_path = properties.getProperty('superpowered.dir')
model {
repositories {
libs(PrebuiltLibraries) {
superpowered { // this is where you declare the "superpowered" static library
headers.srcDir "${superpowered_sdk_path}"
binaries.withType(StaticLibraryBinary) { // attaching library files to each platform
def platformName = targetPlatform.getName()
if (platformName == "armeabi-v7a") {
staticLibraryFile = file("${superpowered_sdk_path}/libSuperpoweredAndroidARM.a")
} else if (platformName == "arm64-v8a") {
staticLibraryFile = file("${superpowered_sdk_path}/libSuperpoweredAndroidARM64.a")
} else if (platformName == "x86") {
staticLibraryFile = file("${superpowered_sdk_path}/libSuperpoweredAndroidX86.a")
} else if (platformName == "x86_64") {
staticLibraryFile = file("${superpowered_sdk_path}/libSuperpoweredAndroidX86_64.a")
}
}
}
}
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion.apiLevel = 21 // more than 95% of all active Android devices
targetSdkVersion.apiLevel = 21
versionCode 1
versionName "1.0"
}
}
android.ndk { // your application's native layer parameters
moduleName = "SuperpoweredExample"
platformVersion = 21
stl = "c++_static"
CFlags.addAll(["-O3", "-fsigned-char"]) // full optimization, char data type is signed
cppFlags.addAll(["-fsigned-char", "-I${superpowered_sdk_path}".toString()])
ldLibs.addAll(["log", "android", "OpenSLES"]) // load these libraries: log, android, OpenSL ES (for audio)
abiFilters.addAll(["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]) // these platforms cover 99% percent of all Android devices
}
android.sources.main.jni {
source {
srcDir "jni"
srcDir "${superpowered_sdk_path}/AndroidIO"
}
dependencies {
library "superpowered" linkage "static" // this is where you attach the "superpowered" static library to your app
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
}注:
我所有的资料都可以在Github:https://github.com/DelattreAdixon/Superpowered-Android-Lib上找到。
为了构建它/运行它,您必须更改le local.properties内容,以便它与您的ndk/sdk/超能力路径相匹配。
发布于 2016-08-02 12:59:30
如果您正在使用experimental gradle,它负责创建cpp文件,在该文件中创建函数,并将其与您的java类链接。
尝试删除cpp文件,单击private native void onPlayPause(boolean play)标记它和它们alt+intro,它会显示一个对话框来自动生成cpp文件及其中的函数。
https://stackoverflow.com/questions/38720574
复制相似问题