Android-studio导入.so库问题?
ringa_lee
ringa_lee 2017-04-17 17:48:14
0
5
626

我的目录结构

一下是主activity

package com.iflytek.tts;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.iflytek.tts.TtsService.Tts;

import com.iflytek.tts.R;



public class TtsJniDemo extends Activity implements View.OnClickListener {
    //在lib目录下有AisoundDemo.so 文件
    private static final String TAG = "AisoundDemo";
    private TextView txtView;
    //准备读的文字
    private String text = "ياخشىمۇسىز";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // ui
        TextView textView = (TextView) findViewById(R.id.textView);
        EditText editText = (EditText) findViewById(R.id.editText);
        Button startButton = (Button) findViewById(R.id.startButton);
        Button stopButton = (Button) findViewById(R.id.stopButton);
        startButton.setOnClickListener(this);
        stopButton.setOnClickListener(this);
        if (!editText.getText().toString().equals("")){
            text = editText.getText().toString();
        }
        textView.setText(text);
        // tts
        Tts.JniCreate("/sdcard/Resource.irf");
        Tts.JniSetParam(1282, -11000);//1282可能是 调整语速的id  后面的-11000 是它的值。 比如Tts.JniSetParam(1282, -15000); 改成这个就说话速度快了。

//        Tts.JniSetParam(1280, 4);  这个是别的参数 看看改4 这个数字看看 我也不知道是什么
//        Tts.JniSetParam(1297, 20); 这个是别的参数 看看改20 这个数字看看 我也不知道是什么
//        Tts.JniSetParam(1282, 20000);    这个是别的参数 看看改20000 这个数字看看 我也不知道是什么



    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.startButton:
                onClickStart();
                break;
            case R.id.stopButton:
                onClickStop();
                break;
        }
    }

    public void onClickStop(){
        //Tts.JniStop();
    }

    public void onClickStart(){
        //JniSpeak参数是文字 给什么文字就读什么文字。 此代码只是维吾尔语言的离线合成。
        Tts.JniSpeak(text);
        //1。在这儿关闭语音助手的识别 stoplistening
        // stoplistening
        do {
            //2.这个的作用是 等到 语音合成结束时前 不要执行任何事情
        }while (Tts.JniIsPlaying()==0);
        //3.语音合成结束后 在这儿开启语音识别 starlistining .
        //starlistining
        //总结:通过1,2,3步骤可以实习 对助手说 你好 它回答 我好 的时候 这个“我好”防止被语音识别再一次听到自己的声音。 第3步是 说完 “我好” 后自动就开启识别了。等待用户再一次说话。 这和地方在用户多轮交流时有用。

    }
}

以下是Tts.java

package com.iflytek.tts.TtsService;



//import com.iflytek.tts.MessageDemo;

import com.iflytek.tts.TtsJniDemo;

public final class Tts{
    static {
        System.loadLibrary("Aisound");
    }

    public    static String getString;


    /**
     * 
     */
    public  synchronized static void startReadThread(TtsJniDemo ttsJniDemo){
        class TtsRunThread implements Runnable {
            @Override
            public void run() {
                JniSpeak(getString);
            }
        }
        Thread ttsRun = (new Thread(new TtsRunThread()));
        ttsRun.setPriority(Thread.MAX_PRIORITY);
        ttsRun.start();
    }

    public static native int JniGetVersion();
    public static native int JniCreate(String resFilename);
    public static native int JniDestory();
    public static native int JniStop();
    public static native int JniSpeak(String text);
    public static native int JniSetParam(int paramId,int value);
    public static native int JniGetParam(int paramId);
    public static native int JniIsPlaying();
    public static native boolean JniIsCreated();
}

以下是错误信息

我在android-studio导入一个.so库的时候遇到了以上问题,我该怎么解决?
网上有人说是NDK的bug,我改了NDK版本也是同样问题,谢谢大家。

ringa_lee
ringa_lee

ringa_lee

reply all(5)
阿神

If you compile it yourself, you won’t have this problem. If there is someone else’s library, you can use nm -Do libyourso.so to check its package structure, and then build an identical package under your src/main/java Path, change the class name to be the same as the other party

In addition, if you use someone else's, -v7a -v8a x86 x86_64 to test each individually, I have encountered this problem before, it is very unstable, sometimes it can pass and sometimes it cannot. Delete unnecessary so files and directories, test them one by one, and leave only the so files that can pass

黄舟

Are you sure the problem is caused by importing the so library? If so, you can try deleting the -v7a -v8a x86 x86_64 folders and try again. Or put .so files in corresponding formats under these folders

洪涛

In this way, we can’t know exactly where the problem is. I suggest you make a demo of calling so first. Write a simple method in so, which corresponds to a method in java. Check the method naming clearly and correspond one to one. First place the so file only in the armeabi folder, and then try to debug this method successfully according to some examples introduced on the Internet. If it succeeds, then try to debug your code above

阿神

No JNI_OnLoad found inThe problem is mostly caused by the inconsistency between the java package name and the function name of the C or C++ code that generates so. Did you compile your so yourself or directly copied someone else's?

Peter_Zhu

Isn’t this a memory overflow?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template