现在我在android中使用ffmpeg java库。我想直接在我的应用中使用它,因此我正在导入此库。但是我有一个问题。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.softcode.kihnoplay, PID: 15313
java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String androidFfmpeg.ArmArchHelper.cpuArchFromJNI() (tried Java_androidFfmpeg_ArmArchHelper_cpuArchFromJNI and Java_androidFfmpeg_ArmArchHelper_cpuArchFromJNI__)
at androidFfmpeg.ArmArchHelper.cpuArchFromJNI(Native Method)
at androidFfmpeg.CpuArchHelper.getCpuArch(CpuArchHelper.java:16)
at androidFfmpeg.FFmpeg.loadBinary(FFmpeg.java:40)
at com.softcode.tablet.Mp3Concat_Thread.startThread(Mp3Concat_Thread.java:90)
at com.softcode.tablet.Mp3Concat_Thread.<init>(Mp3Concat_Thread.java:54)
at com.softcode.phone.record.view.RecordActivity.onCreate(RecordActivity.java:182)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
我不知道为什么会发生此错误。
我的目录树是
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <cpu-features.h>
jstring
Java_androidFfmpeg_ArmArchHelper_cpuArchFromJNI(JNIEnv* env, jobject obj)
{
char arch_info[11] = "";
if (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) {
strcpy(arch_info, "ARM");
uint64_t cpuFeatures = android_getCpuFeatures();
if ((cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0) {
strcat(arch_info, " v7");
if((cpuFeatures & ANDROID_CPU_ARM_FEATURE_NEON) != 0) {
strcat(arch_info, "-neon");
}
}
}
return (*env)->NewStringUTF(env, arch_info);
}
这是一个成绩(应用程序)
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.softcode.kihnoplay"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.00"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a","x86"
}
aaptOptions
{
cruncherEnabled = false
}
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //important!!!! disable automatic ndk-build call
}
我不知道为什么会发生此错误。如果您知道此问题,请告诉我。谢谢!
答案 0 :(得分:1)
我猜您正在使用clang ++编译c源代码,对吗?如果为true,请尝试将文件名更改为armArch.cpp,并在C头文件和源文件中添加关键字 extern 。例如
#ifdef __cplusplus
extern "C" {
#endif
// your function declarations or implementations.
#ifdef __cplusplus
}
#endif
此外,我建议使用 externalNativeBuild 和 cmake 块,而不要使用较旧的 ndk 块,这不是Android的现代约定本机版本。例如。
android {
//....
defaultConfig {
applicationId "com.softcode.kihnoplay"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.00"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
}
buildTypes {
release {
//....
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
Android NDK已弃用 armeabi ,您实际上不需要包含此ABI就是您的abiFilters设置。 ABI 'armeabi-v7a','arm64-v8a','x86','x86_64'足以支持几乎所有当前的Android设备以及仿真器。
您可以从https://arophix.com/2017/12/17/andoid-jni-summary/中找到全面的JNI教程 和https://github.com/russell-shizhen/JniExample
的示例JNI项目