以上就是给各位分享android–java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader,同时本文还将给你拓展AndroidNDKUn
以上就是给各位分享android – java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader,同时本文还将给你拓展Android NDK UnsatisfiedLinkError:“dlopen失败:空/丢失DT_HASH”、Android NDK项目:java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader、android – dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)中的类加载错误?、android – Java.lang.UnsatisfiedLinkError:找不到int 的实现等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- android – java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader
- Android NDK UnsatisfiedLinkError:“dlopen失败:空/丢失DT_HASH”
- Android NDK项目:java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader
- android – dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)中的类加载错误?
- android – Java.lang.UnsatisfiedLinkError:找不到int 的实现
android – java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader
有没有经历过这个错误的人?
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.swig.simple-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] Couldn't find "liborg.swig.simple.example.so"
通过这种方式加载库时发生错误.
static {
System.loadLibrary("example");
}
我确定’example’类存在于当前文件夹中.
解决方法:
请注意,有一个命名约定.您的lib需要被称为libexample.so.
LoadLibrary(“example”)将查找libexample.so.
.so库需要在lib文件夹下的apk下面(因为你正在为Android开发,它需要在lib / armeabi和lib / armeabi-v7a文件夹下 – 为什么这两个文件夹?某些版本的Android看起来在lib下/ armeabi和一些看下lib / armeabi-v7a … se什么对你有用).
其他要寻找的东西:
>确保编译正确的体系结构(如果编译为armeabi v5,它将无法在armeabiv7或armeabiv7s上运行).
>确保导出的原型在正确的类中使用(请查看hello jni示例.您的公开函数需要看起来像Java_mypackagename_myjavabridgeclass_myfunction).
例如,函数Java_com_example_sample_hello将在java类com.example.sample,function hello中进行转换.
Android NDK UnsatisfiedLinkError:“dlopen失败:空/丢失DT_HASH”
我正在使用崩溃报告服务跟踪我们的Android应用程序(使用NDK加载C库)的崩溃.少数用户遇到以下崩溃:
java.lang.UnsatisfiedLinkError: dlopen Failed: empty/missing DT_HASH in "cpplibrary.so" (built with --hash-style=gnu?)
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:526)
我可以在互联网上找到的这个错误提及(例如这个Google Groups post)讨论了构建lib的问题,这会导致每次运行应用程序时都会出现此错误.几乎没有关于为什么偶尔会发生这种情况的信息. This post是我能找到的最接近的.
根据崩溃痕迹,看起来任何特定的用户都会经历这种不断的延伸;我不确定这些用户是否能够正确加载lib.有没有人对有时可能导致这种情况发生的想法有所了解?我可以以不同的方式进行NDK构建以试图阻止它吗?
谢谢!
编辑:This post提到了有条件地获得此类错误的两种方法;我会照顾他们.
Edit2:构建文件:
Android.mk(摘录):
include $(CLEAR_VARS)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_C_INCLUDES :=
Application.mk:
APP_STL := stlport_static
APP_CFLAGS += -std=c++11
最佳答案
如果您是第三方构建.so库供其他人使用,设置-Wl,– hash-style =两者似乎都是最好的主意.这样可以加快Gnu样式哈希的加载速度和SysV哈希的向后兼容性.
Android NDK项目:java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader
如何解决Android NDK项目:java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader?
我是NDK的新手。
我想在我的标准Java Android Studio项目中添加一些C ++代码。
我做了什么:
-
在主文件夹下添加cpp文件夹
-
在my cpp文件夹中添加myccplib.cpp和myccplib.h
-
在Gradle(模块)中添加以下内容:
android { externalNativeBuild { cmake { version "3.10.2" } } }
myccplib.cpp中的 -
代码:
#include "myccplib.h" #include <jni.h> #include <string> extern "C" JNIEXPORT jstring JNICALL Java_com_example_tof_MainActivity_stringFromJNI( jnienv *env,jobject /* this */) { std::string hello = "Hello,World!"; return env->NewStringUTF(hello.c_str()); }
-
MainActivity.java中的代码:
public class MainActivity extends AppCompatActivity {
static {
System.loadLibrary("myccplib"); // "myjni.dll" in Windows,"libmyjni.so" in Unixes
}
public native String stringFromJNI();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String s = stringFromJNI();
Log.d("stringFromJNI " + s);
}
}
我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library,sets it as either STATIC
# or SHARED,and provides the relative paths to its source code.
# You can define multiple libraries,and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default,you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries,such as libraries you define in this
# build script,prebuilt third-party libraries,or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
问题:我崩溃了:
2020-10-14 19:02:45.465 25918-25918/com.example.tof E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tof,PID: 25918
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.tof-t8Csh416BSdO6UBfZv0mOw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.tof-t8Csh416BSdO6UBfZv0mOw==/lib/arm64,/system/lib64,/product/lib64]]] Couldn''t find "libmyccplib.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.example.tof.MainActivity.<clinit>(MainActivity.java:37)
我使用的是Android 4.0。
有人能告诉我我想念什么吗?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
android – dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)中的类加载错误?
无法运行以下项目,项目中没有错误.我已经多次运行该项目了.请有人帮我解决问题.
AndroidManifest.xml中:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.extremefitness.org"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens
android:anyDensity="false"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" >
</uses-permission>
<uses-permission android:name="android.permission.disABLE_KEyguard" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Tabbaractivity"
android:windowSoftInputMode="adjustPan|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.LoginActivity"
android:noHistory="true"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.Registeractivity"
android:noHistory="true"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.Profiletabactivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.RandomWorkouttabactivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.Tracktabactivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.Workouttabactivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.StatsActivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.ExerciseActivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.CustomDialog"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.WorkoutDescription"
android:noHistory="true"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.ExerciseDescription"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.Settings"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.RandomWorkoutResponse"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name=".FBActivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name=".Twitteractivity"
android:screenorientation="portrait"
android:windowSoftInputMode="adjustPan|adjustResize" >
</activity>
<activity
android:name="com.extremefitness.views.VideoDialog"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenorientation="nosensor" >
<Meta-data
android:name="@string/minVersion"
android:value="8" />
<Meta-data
android:name="@string/isLaunchableActivity"
android:value="true" />
</activity>
<activity
android:name="com.extremefitness.views.WorktVideoDialog"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenorientation="nosensor" >
<Meta-data
android:name="@string/minVersion"
android:value="8" />
<Meta-data
android:name="@string/isLaunchableActivity"
android:value="true" />
</activity>
</application>
</manifest>
错误的日志:
04-26 14:45:08.211: E/AndroidRuntime(2179): FATAL EXCEPTION: main
04-26 14:45:08.211: E/AndroidRuntime(2179): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.extremefitness.org/com.extremefitness.org.Tabbaractivity}: java.lang.classNotFoundException: com.extremefitness.org.Tabbaractivity
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1894)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread.access$600(ActivityThread.java:128)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.os.Looper.loop(Looper.java:137)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread.main(ActivityThread.java:4517)
04-26 14:45:08.211: E/AndroidRuntime(2179): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 14:45:08.211: E/AndroidRuntime(2179): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 14:45:08.211: E/AndroidRuntime(2179): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
04-26 14:45:08.211: E/AndroidRuntime(2179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
04-26 14:45:08.211: E/AndroidRuntime(2179): at dalvik.system.NativeStart.main(Native Method)
04-26 14:45:08.211: E/AndroidRuntime(2179): Caused by: java.lang.classNotFoundException: com.extremefitness.org.Tabbaractivity
04-26 14:45:08.211: E/AndroidRuntime(2179): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-26 14:45:08.211: E/AndroidRuntime(2179): at java.lang.classLoader.loadClass(ClassLoader.java:501)
04-26 14:45:08.211: E/AndroidRuntime(2179): at java.lang.classLoader.loadClass(ClassLoader.java:461)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
04-26 14:45:08.211: E/AndroidRuntime(2179): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1885)
04-26 14:45:08.211: E/AndroidRuntime(2179): ... 11 more
解决方法:
我遇到同样的问题,检查构建路径,你的第三个罐子没有在你的apk文件中.
1.右键单击您的项目,选择“构建路径” – > “配置构建路径…”.
2.在“订购和导出”选项卡中,选中“Android私有库”选项.
希望工作.
android – Java.lang.UnsatisfiedLinkError:找不到int 的实现
我执行youtube看我的android应用程序项目.我只是在我的项目中添加一些类并使用ndk构建.我得到了错误
java.lang.UnsatisfiedLinkError: No implementation found for int com.ephronsystem.mobilizerapp.Ffmpeg.encodeVideoFrame(byte[]) (tried Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeVideoFrame and Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeVideoFrame___3B).
我的代码:
package com.ephronsystem.mobilizerapp; public class Ffmpeg { static { System.loadLibrary("ffmpeg"); } public static native boolean init(int width,int height,int audio_sample_rate,String rtmpurl); public static native void shutdown(); // Returns the size of the encoded frame. public static native int encodeVideoFrame(byte[] yuv_image); public static native int encodeAudioFrame(short[] audio_data,int length); }
这是ffmpeg-jni.c
#include <android/log.h> #include <string.h> #include <jni.h> #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libavutil/opt.h" #ifdef __cplusplus extern "C" { #endif JNIEXPORT jboolean JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_init(jnienv *env,jobject thiz,jint width,jint height,jint audio_sample_rate,jstring rtmp_url); JNIEXPORT void JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_shutdown(jnienv *env,jobject thiz ); JNIEXPORT jint JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeVideoFrame(jnienv *env,jbyteArray yuv_image); JNIEXPORT jint JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeAudioFrame(jnienv *env,jshortArray audio_data,jint length); #ifdef __cplusplus } #endif #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"ffmpeg-jni",__VA_ARGS__) #define URL_WRONLY 2 static AVFormatContext *fmt_context; static AVStream *video_stream; static AVStream *audio_stream; static int pts = 0; static int last_audio_pts = 0; // Buffers for UV format conversion static unsigned char *u_buf; static unsigned char *v_buf; static int enable_audio = 1; static int64_t audio_samples_written = 0; static int audio_sample_rate = 0; // Stupid buffer for audio samples. Not even a proper ring buffer #define AUdio_MAX_BUF_SIZE 16384 // 2x what we get from Java static short audio_buf[AUdio_MAX_BUF_SIZE]; static int audio_buf_size = 0; void AudioBuffer_Push(const short *audio,int num_samples) { if (audio_buf_size >= AUdio_MAX_BUF_SIZE - num_samples) { LOGI("AUdio BUFFER OVERFLOW: %i + %i > %i",audio_buf_size,num_samples,AUdio_MAX_BUF_SIZE); return; } for (int i = 0; i < num_samples; i++) { audio_buf[audio_buf_size++] = audio[i]; } } int AudioBuffer_Size() { return audio_buf_size; } short *AudioBuffer_Get() { return audio_buf; } void AudioBuffer_Pop(int num_samples) { if (num_samples > audio_buf_size) { LOGI("Audio buffer Pop WTF: %i vs %i",audio_buf_size); return; } memmove(audio_buf,audio_buf + num_samples,num_samples * sizeof(short)); audio_buf_size -= num_samples; } void AudioBuffer_Clear() { memset(audio_buf,sizeof(audio_buf)); audio_buf_size = 0; } static void log_callback(void *ptr,int level,const char *fmt,va_list vl) { char x[2048]; vsnprintf(x,2048,fmt,vl); LOGI(x); } JNIEXPORT jboolean JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_init(jnienv *env,jint audio_sample_rate_param,jstring rtmp_url) { avcodec_register_all(); av_register_all(); av_log_set_callback(log_callback); fmt_context = avformat_alloc_context(); AVOutputFormat *ofmt = av_guess_format("flv",NULL,NULL); if (ofmt) { LOGI("av_guess_format returned %s",ofmt->long_name); } else { LOGI("av_guess_format fail"); return JNI_FALSE; } fmt_context->oformat = ofmt; LOGI("creating video stream"); video_stream = av_new_stream(fmt_context,0); if (enable_audio) { LOGI("creating audio stream"); audio_stream = av_new_stream(fmt_context,1); } // Open Video Codec. // ====================== AVCodec *video_codec = avcodec_find_encoder(AV_CODEC_ID_H264); if (!video_codec) { LOGI("Did not find the video codec"); return JNI_FALSE; // leak! } else { LOGI("Video codec found!"); } AVCodecContext *video_codec_ctx = video_stream->codec; video_codec_ctx->codec_id = video_codec->id; video_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO; video_codec_ctx->level = 31; video_codec_ctx->width = width; video_codec_ctx->height = height; video_codec_ctx->pix_fmt = PIX_FMT_YUV420P; video_codec_ctx->rc_max_rate = 0; video_codec_ctx->rc_buffer_size = 0; video_codec_ctx->gop_size = 12; video_codec_ctx->max_b_frames = 0; video_codec_ctx->slices = 8; video_codec_ctx->b_frame_strategy = 1; video_codec_ctx->coder_type = 0; video_codec_ctx->me_cmp = 1; video_codec_ctx->me_range = 16; video_codec_ctx->qmin = 10; video_codec_ctx->qmax = 51; video_codec_ctx->keyint_min = 25; video_codec_ctx->refs = 3; video_codec_ctx->trellis = 0; video_codec_ctx->scenechange_threshold = 40; video_codec_ctx->flags |= CODEC_FLAG_LOOP_FILTER; video_codec_ctx->me_method = ME_HEX; video_codec_ctx->me_subpel_quality = 6; video_codec_ctx->i_quant_factor = 0.71; video_codec_ctx->qcompress = 0.6; video_codec_ctx->max_qdiff = 4; video_codec_ctx->time_base.den = 10; video_codec_ctx->time_base.num = 1; video_codec_ctx->bit_rate = 3200 * 1000; video_codec_ctx->bit_rate_tolerance = 0; video_codec_ctx->flags2 |= 0x00000100; fmt_context->bit_rate = 4000 * 1000; av_opt_set(video_codec_ctx,"partitions","i8x8,i4x4,p8x8,b8x8",0); av_opt_set_int(video_codec_ctx,"direct-pred",1,"rc-lookahead","fast-pskip","mixed-refs","8x8dct","weightb",0); if (fmt_context->oformat->flags & AVFMT_GLOBALHEADER) video_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER; LOGI("opening video codec"); AVDictionary *vopts = NULL; av_dict_set(&vopts,"profile","main",0); //av_dict_set(&vopts,"vprofile",0); av_dict_set(&vopts,"tune","film","preset","ultrafast",0); av_opt_set(video_codec_ctx->priv_data,0); int open_res = avcodec_open2(video_codec_ctx,video_codec,&vopts); if (open_res < 0) { LOGI("Error opening video codec: %i",open_res); return JNI_FALSE; // leak! } // Open Audio Codec. // ====================== if (enable_audio) { AudioBuffer_Clear(); audio_sample_rate = audio_sample_rate_param; AVCodec *audio_codec = avcodec_find_encoder(AV_CODEC_ID_AAC); if (!audio_codec) { LOGI("Did not find the audio codec"); return JNI_FALSE; // leak! } else { LOGI("Audio codec found!"); } AVCodecContext *audio_codec_ctx = audio_stream->codec; audio_codec_ctx->codec_id = audio_codec->id; audio_codec_ctx->codec_type = AVMEDIA_TYPE_AUdio; audio_codec_ctx->bit_rate = 128000; audio_codec_ctx->bit_rate_tolerance = 16000; audio_codec_ctx->channels = 1; audio_codec_ctx->profile = FF_PROFILE_AAC_LOW; audio_codec_ctx->sample_fmt = AV_SAMPLE_FMT_FLT; audio_codec_ctx->sample_rate = 44100; LOGI("opening audio codec"); AVDictionary *opts = NULL; av_dict_set(&opts,"strict","experimental",0); open_res = avcodec_open2(audio_codec_ctx,audio_codec,&opts); LOGI("audio frame size: %i",audio_codec_ctx->frame_size); if (open_res < 0) { LOGI("Error opening audio codec: %i",open_res); return JNI_FALSE; // leak! } } const jbyte *url = (*env)->GetStringUTFChars(env,rtmp_url,NULL); // Point to an output file if (!(ofmt->flags & AVFMT_NOFILE)) { if (avio_open(&fmt_context->pb,url,URL_WRONLY) < 0) { LOGI("ERROR: Could not open file %s",url); return JNI_FALSE; // leak! } } (*env)->ReleaseStringUTFChars(env,url); LOGI("Writing output header."); // Write file header if (avformat_write_header(fmt_context,NULL) != 0) { LOGI("ERROR: av_write_header Failed"); return JNI_FALSE; } pts = 0; last_audio_pts = 0; audio_samples_written = 0; // Initialize buffers for UV format conversion int frame_size = video_codec_ctx->width * video_codec_ctx->height; u_buf = (unsigned char *) av_malloc(frame_size / 4); v_buf = (unsigned char *) av_malloc(frame_size / 4); LOGI("ffmpeg encoding init done"); return JNI_TRUE; } JNIEXPORT void JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_shutdown(jnienv *env,jobject thiz ) { av_write_trailer(fmt_context); avio_close(fmt_context ->pb); avcodec_close(video_stream ->codec); if (enable_audio) { avcodec_close(audio_stream ->codec); } av_free(fmt_context); av_free(u_buf); av_free(v_buf); fmt_context = NULL; u_buf = NULL; v_buf = NULL; } JNIEXPORT jint JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeVideoFrame(jnienv *env,jbyteArray yuv_image) { int yuv_length = (*env)->GetArrayLength(env,yuv_image); unsigned char *yuv_data = (*env)->GetByteArrayElements(env,yuv_image,0); AVCodecContext *video_codec_ctx = video_stream->codec; //LOGI("Yuv size: %i w: %i h: %i",yuv_length,video_codec_ctx->width,video_codec_ctx->height); int frame_size = video_codec_ctx->width * video_codec_ctx->height; const unsigned char *uv = yuv_data + frame_size; // Convert YUV from NV12 to I420. Y channel is the same so we don''t touch it,// we just have to deinterleave UV. for ( int i = 0; i < frame_size / 4; i++) { v_buf[i] = uv[i * 2]; u_buf[i] = uv[i * 2 + 1]; } AVFrame source; memset(&source,sizeof(AVFrame)); source.data[0] = yuv_data; source.data[1] = u_buf; source.data[2] = v_buf; source.linesize[0] = video_codec_ctx-> width; source.linesize[1] = video_codec_ctx->width / 2; source.linesize[2] = video_codec_ctx->width / 2; // only for bitrate regulation. irrelevant for sync. source. pts = pts; pts++; int out_length = frame_size + (frame_size / 2); unsigned char *out = (unsigned char *) av_malloc(out_length); int compressed_length = avcodec_encode_video(video_codec_ctx,out,out_length,&source); (*env)-> ReleaseByteArrayElements(env,yuv_data,0); // Write to file too if (compressed_length > 0) { AVPacket pkt; av_init_packet(&pkt); pkt. pts = last_audio_pts; if (video_codec_ctx->coded_frame && video_codec_ctx->coded_frame->key_frame) { pkt.flags |= 0x0001; } pkt. stream_index = video_stream->index; pkt. data = out; pkt. size = compressed_length; if ( av_interleaved_write_frame(fmt_context,&pkt) != 0) { LOGI("Error writing video frame"); } } else { LOGI("??? compressed_length <= 0"); } last_audio_pts++; av_free(out); return compressed_length; } JNIEXPORT jint JNICALL Java_com_ephronsystem_mobilizerapp_Ffmpeg_encodeAudioFrame(jnienv *env,jshortArray audio_data,jint length ) { if (!enable_audio) { return 0; } short *audio = (*env)->GetShortArrayElements(env,audio_data,0); //LOGI("java audio buffer size: %i",length); AVCodecContext *audio_codec_ctx = audio_stream->codec; unsigned char *out = av_malloc(128000); AudioBuffer_Push(audio,length ); int total_compressed = 0; while ( AudioBuffer_Size() >= audio_codec_ctx->frame_size) { AVPacket pkt; av_init_packet(&pkt); int compressed_length = avcodec_encode_audio(audio_codec_ctx,128000,AudioBuffer_Get()); total_compressed += compressed_length; audio_samples_written += audio_codec_ctx-> frame_size; int new_pts = (audio_samples_written * 1000) / audio_sample_rate; if (compressed_length > 0) { pkt. size = compressed_length; pkt. pts = new_pts; last_audio_pts = new_pts; //LOGI("audio_samples_written: %i comp_length: %i pts: %i",(int)audio_samples_written,(int)compressed_length,(int)new_pts); pkt.flags |= 0x0001; pkt. stream_index = audio_stream->index; pkt. data = out; if ( av_interleaved_write_frame(fmt_context,&pkt) != 0) { LOGI("Error writing audio frame"); } } AudioBuffer_Pop(audio_codec_ctx ->frame_size); } (*env)-> ReleaseShortArrayElements(env,audio,0); av_free(out); return total_compressed; }
解决方法
您可以在java.library.path和链接here上找到更多详细信息
我们今天的关于android – java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader的分享已经告一段落,感谢您的关注,如果您想了解更多关于Android NDK UnsatisfiedLinkError:“dlopen失败:空/丢失DT_HASH”、Android NDK项目:java.lang.UnsatisfiedLinkError:dalvik.system.PathClassLoader、android – dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)中的类加载错误?、android – Java.lang.UnsatisfiedLinkError:找不到int 的实现的相关信息,请在本站查询。
本文标签: