UstadMobile / Codec2-Android

Android library with JNI wrapper for Codec2. Uses Gradle and NDK to cross compile Codec2 (v0.8) into an AAR library for Android
GNU Lesser General Public License v3.0
20 stars 1 forks source link

ninja error:missing and no known rule to make it #2

Open BadDateAlex opened 3 months ago

BadDateAlex commented 3 months ago

I was trying to import your project on my Android Studio and I had this error. I don't know why there isn't a folder named imported-lib,did I miss sth? please help me, thank u. ninja: error: 'E:/Android/SatellitePhoneCallApp-master/libcodec2-android/src/main/cpp/libcodec2-android/build/imported-lib/armeabi-v7a/libcodec2.so', needed by 'E:/Android/SatellitePhoneCallApp-master/libcodec2-android/build/intermediates/cxx/Debug/3o464q63/obj/armeabi-v7a/libCodec2JNI.so', missing and no known rule to make it

BadDateAlex commented 3 months ago

Have you ever import libcode2.so manually? I can't find it anywhere.

Nenteru commented 3 weeks ago

@BadDateAlex, To solve your problem, you need to download the native libraries (.so format) and add them to the project. project/app/natives/ (arm64-v8a and armeabi-v7a .. x86 .. x86_64)

For example, for me it looks like this:

project
    app
        natives
            arm64-v8a
                lib
                    arm64-v8a
                        libcodec2.so
                        libCodec2JNI.so
            armeabi-v7a
                lib
                    armeabi-v7a
                        libcodec2.so
                        libCodec2JNI.so

Next, in gradle, specify the path to these libraries:

android {
        sourceSets {
            main {
                file("${rootDir}/app/natives").eachDir() { dir ->
                    jniLibs.srcDirs += "${dir.path}/lib"
                }
            }
        }
    }

Now you can use native libraries; to do this, specify in the Codec2 class:

import android.support.annotation.RequiresApi;

@RequiresApi(23)
public class Codec2 {

    static {
        System.loadLibrary("codec2");
        System.loadLibrary("Codec2JNI");
    }

    public static final int CODEC2_MODE_3200 = 0;
    public static final int CODEC2_MODE_2400 = 1;
    public static final int CODEC2_MODE_1600 = 2;
    public static final int CODEC2_MODE_1400 = 3;
    public static final int CODEC2_MODE_1300 = 4;
    public static final int CODEC2_MODE_1200 = 5;
    public static final int CODEC2_MODE_700 = 6;
    public static final int CODEC2_MODE_700B = 7;
    public static final int CODEC2_MODE_700C = 8;
    public static final int CODEC2_MODE_WB = 9;

    /**
     * The size of the file header that is written when using c2enc. When decoding, this must be
     * skipped.
     */
    public static final int CODEC2_FILE_HEADER_SIZE = 7;

    public native static long create(int mode);

    public native static int getSamplesPerFrame(long con);

    public native static int getBitsSize(long con);

    public native static int destroy(long con);

    public native static long encode(long con, short[] buf, char[] bits);

    /**
     * Decode one frame from codec2.
     *
     * @param con pointer long, as from the create method
     * @param outputBuffer buffer which will be filled with raw PCM audio decoded
     * @param bits input buffer containing one frame of audio
     *
     * @return 0 on successful completion
     */
    public native static long decode(long con, short[] outputBuffer, byte[] bits);
}
BadDateAlex commented 1 week ago

roject/app/natives/ (arm64-v8a and armeabi-v7a .. x86 .. x86_64)

For example, for me it looks like this:

thx,I finally use an aar version from my co-workers,they build it from linux system.