NDK:如何在AndroidStudio中包含* .so文件 [英] NDK: how include *.so files in AndroidStudio

查看:146
本文介绍了NDK:如何在AndroidStudio中包含* .so文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有libs jar和* .so.我按照教程中的说明(针对该库)创建了Eclipse项目.我现在正在Android Studio中进行项目,但是系统找不到* .so文件.我将在其中进行说明-在Android Studio的APK中包含.so库.我的应用程序在so libs中找不到功能.如何找到它们? 日志:

I have libs jar and *.so. I created Eclipse project as in tutorial (for this libs). I am now doing project in Android Studio, but system can't find *.so files. I make how in this - Include .so library in apk in android studio . My app does not find function in so libs. How to find them? Log:

10-16 12:16:55.965: W/dalvikvm(4386): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/atol/drivers/fptr/IFptrNative;
10-16 12:16:55.965: W/dalvikvm(4386): threadid=1: thread exiting with uncaught exception (group=0x41869438)
10-16 12:16:55.976: E/AndroidRuntime(4386): FATAL EXCEPTION: main
10-16 12:16:55.976: E/AndroidRuntime(4386): java.lang.ExceptionInInitializerError

使用JAR库创建对象时发生错误.她反过来戳了* .so文件,但是找到了她所需要的.谁该怪谁该怎么办?

An error occurs when creating an object using a JAR library. She in turn poked *.so files, but to find what she needs. Who is to blame and what to do?

推荐答案

三个选项:

一个

将您的* .SO库复制到libs文件夹中,并将其放在Build.gradle中:

Copy yours *.SO libraries on your libs folder and put that on Build.gradle:

dependencies
        {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

两个

src/main/jniLibs上新建一个文件夹,并将其写入您的Build.gradle:

Make a new folder on src/main/jniLibs and write that on your Build.gradle:

android {
    //Another code 
    sourceSets {
        main {         
            jniLibs.srcDirs = ['src/main/jnilibs']          
        }
        //Another code 
    }//sourceSets tag close
}//Android tag close

src/main/jniLibs上新建一个文件夹,并将其写入您的Build.gradle:

Make a new folder on src/main/jniLibs and write that on your Build.gradle:

//Another code....

    dependencies
    {
          compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    }//end dependencies


    task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
        destinationDir file("$buildDir/native-libs")
        baseName 'native-libs'
        from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
        into 'lib/'
    }

    tasks.withType(JavaCompile)
     {
          compileTask -> compileTask.dependsOn(nativeLibsToJar)
     }

这篇关于NDK:如何在AndroidStudio中包含* .so文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆