来自AudioTrack的dalvikvm上的UnsatisfiedLinkError

时间:2018-03-26 22:13:21

标签: java android java-native-interface dalvik audiotrack

所以我在dalvikvm上使用AudioTrack(我在app_process做了这是另一个故事):

$ cat android/media/Hello.java
package android.media;

class Hello
{
    public static void main(String[] args)
    {
        AudioAttributes aa = new AudioAttributes.Builder().build();
        AudioFormat af = new AudioFormat.Builder().build();
        AudioTrack at = new AudioTrack(aa, af, 4, 1, 0);
        at.release();
    }
}
$

我得到了:

$ /system/bin/dalvikvm -cp android.dex android.media.Hello
Exception in thread "main" java.lang.UnsatisfiedLinkError: No implementation found for int android.media.AudioTrack.native_get_FCC_8() (tried Java_android_media_AudioTrack_native_1get_1FCC_18 and Java_android_media_AudioTrack_native_1get_1FCC_18__)
        at android.media.AudioTrack.native_get_FCC_8(Native Method)
        at android.media.AudioTrack.<clinit>(AudioTrack.java:99)
        at android.media.Hello.main(Hello.java:9)
$

然后我创建了这些:

$ cat media/AudioTrack.java
package media;

public class AudioTrack
{
    public static final int CHANNEL_COUNT_MAX = native_get_FCC_8();
    public AudioTrack() {
        System.out.printf("%d\n", CHANNEL_COUNT_MAX);
    }
    static private native int native_get_FCC_8();
}
$ cat media/Hello.java
package media;

class Hello
{
    public static void main(String[] args)
    {
        new AudioTrack();
    }
}
$

这让我得到了类似的错误,正如我所希望的那样:

$ /system/bin/dalvikvm -cp media.dex media.Hello
Exception in thread "main" java.lang.UnsatisfiedLinkError: No implementation found for int media.AudioTrack.native_get_FCC_8() (tried Java_media_AudioTrack_native_1get_1FCC_18 and Java_media_AudioTrack_native_1get_1FCC_18__)
        at media.AudioTrack.native_get_FCC_8(Native Method)
        at media.AudioTrack.<clinit>(AudioTrack.java:5)
        at media.Hello.main(Hello.java:7)
$

然后我创造了这个:

$ cat fcc.c
#include <jni.h>

JNIEXPORT jint JNICALL
Java_media_AudioTrack_native_1get_1FCC_18(JNIEnv *, jobject);

JNIEXPORT jint JNICALL
Java_android_media_AudioTrack_native_1get_1FCC_18(JNIEnv *, jobject);

JNIEXPORT jint JNICALL
Java_media_AudioTrack_native_1get_1FCC_18(JNIEnv *env, jobject obj)
{
  return 8;
}

JNIEXPORT jint JNICALL
Java_android_media_AudioTrack_native_1get_1FCC_18(JNIEnv *env, jobject obj)
{
  return 8;
}
$

并将其编译为名为libfcc.so的共享库。

然后我补充道:

    static
    {
        System.loadLibrary("fcc");
    }

Hello的开头(就在main之前)并重新编译所有java文件。

然而它只适用于media.AudioTrack(假的),但不适用于android.media.AudioTrack(真实的):

$ /system/bin/dalvikvm -Djava.library.path=. -cp media.dex media.Hello
8
$ /system/bin/dalvikvm -Djava.library.path=. -cp android.dex android.media.Hello
Exception in thread "main" java.lang.UnsatisfiedLinkError: No implementation found for int android.media.AudioTrack.native_get_FCC_8() (tried Java_android_media_AudioTrack_native_1get_1FCC_18 and Java_android_media_AudioTrack_native_1get_1FCC_18__)
        at android.media.AudioTrack.native_get_FCC_8(Native Method)
        at android.media.AudioTrack.<clinit>(AudioTrack.java:99)
        at android.media.Hello.main(Hello.java:13)
$

任何人都知道为什么?

0 个答案:

没有答案