Adding a .so file in Android Studio

时间:2022-09-28 18:34:04

I am trying to add an external library, Scandit. I keep getting this error:

我正在尝试添加一个外部库,Scandit。我一直收到这个错误:

    java.lang.UnsatisfiedLinkError: Couldn't load scanditsdk-android-3.3.1 from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.clover.barcode2-1.apk,libraryPath=/data/app-lib/com.clover.barcode2-1]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
   .....

I assume it is because I am not properly including the .so file that comes with the library, but I can't figure out how to do it.

我认为这是因为我没有正确包含库附带的.so文件,但我无法弄清楚如何做到这一点。

I am using Android Studio and I added the library by going to module settings -> libraries and added the directory with the jar and the directory with the so file.

我正在使用Android Studio,我通过转到模块设置 - >库添加了库,并添加了带有jar的目录和带有so文件的目录。

5 个解决方案

#1


64  

You can add pre built *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs.

您可以使用gradle 0.7.2+在Android Studio中添加预先构建的* .so文件。首先在此位置/ app / src / main / location创建jniLibs,然后在jniLibs中复制带有* .so文件(armeabi,armeabi-v7a,mips,x86)的所有文件夹。

Adding a .so file in Android Studio

#2


7  

To use native-library (so files) You need to add some codes in the "build.gradle" file.

使用本机库(so文件)您需要在“build.gradle”文件中添加一些代码。

This code is for cleaing "armeabi" directory and copying 'so' files into "armeabi" while 'clean project'.

此代码用于清除“armeabi”目录,并在“清理项目”时将“so”文件复制到“armeabi”中。

task copyJniLibs(type: Copy) {
    from 'libs/armeabi'
    into 'src/main/jniLibs/armeabi'
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(copyJniLibs)
}
clean.dependsOn 'cleanCopyJniLibs'

I've been referred from the below. https://gist.github.com/pocmo/6461138

我从下面提到过。 https://gist.github.com/pocmo/6461138

#3


5  

I had a libs folder in my project where i included external libraries added the line compile fileTree(dir: 'libs', include: '*.jar') into dependencies {} in the gradle's build file.

我的项目中有一个libs文件夹,其中包含外部库,在gradle的构建文件中将行编译fileTree(dir:'libs',include:'* .jar')添加到依赖项{}中。

Then I made a lib folder and inside it an armeabi folder where I've inserted all the needed .so files. I then zipped the folder into a .zip (the structure inside the zip file is now lib/armeabi/*.so) I renamed the .zip file into armeabi.jar and added it to the libs folder as an external library.

然后我创建了一个lib文件夹,里面有一个armeabi文件夹,我插入了所有需要的.so文件。然后我将文件夹压缩成.zip(zip文件中的结构现在是lib / armeabi / *。so)我将.zip文件重命名为armeabi.jar并将其作为外部库添加到libs文件夹中。

#4


1  

I think it's a problem of the new gradle build system. Try the solution of this answer. There is also a link to a google group discussion, that describes solution and the problems more detailed.

我认为这是新的gradle构建系统的问题。尝试这个答案的解决方案。还有一个链接到谷歌小组讨论,它描述了解决方案和更详细的问题。

#5


0  

splits {
    abi {
        enable true
        reset()
        include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
        universalApk false
    }
}

I get this code from facebook fresco library

我从facebook壁画库中获取此代码

#1


64  

You can add pre built *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs.

您可以使用gradle 0.7.2+在Android Studio中添加预先构建的* .so文件。首先在此位置/ app / src / main / location创建jniLibs,然后在jniLibs中复制带有* .so文件(armeabi,armeabi-v7a,mips,x86)的所有文件夹。

Adding a .so file in Android Studio

#2


7  

To use native-library (so files) You need to add some codes in the "build.gradle" file.

使用本机库(so文件)您需要在“build.gradle”文件中添加一些代码。

This code is for cleaing "armeabi" directory and copying 'so' files into "armeabi" while 'clean project'.

此代码用于清除“armeabi”目录,并在“清理项目”时将“so”文件复制到“armeabi”中。

task copyJniLibs(type: Copy) {
    from 'libs/armeabi'
    into 'src/main/jniLibs/armeabi'
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(copyJniLibs)
}
clean.dependsOn 'cleanCopyJniLibs'

I've been referred from the below. https://gist.github.com/pocmo/6461138

我从下面提到过。 https://gist.github.com/pocmo/6461138

#3


5  

I had a libs folder in my project where i included external libraries added the line compile fileTree(dir: 'libs', include: '*.jar') into dependencies {} in the gradle's build file.

我的项目中有一个libs文件夹,其中包含外部库,在gradle的构建文件中将行编译fileTree(dir:'libs',include:'* .jar')添加到依赖项{}中。

Then I made a lib folder and inside it an armeabi folder where I've inserted all the needed .so files. I then zipped the folder into a .zip (the structure inside the zip file is now lib/armeabi/*.so) I renamed the .zip file into armeabi.jar and added it to the libs folder as an external library.

然后我创建了一个lib文件夹,里面有一个armeabi文件夹,我插入了所有需要的.so文件。然后我将文件夹压缩成.zip(zip文件中的结构现在是lib / armeabi / *。so)我将.zip文件重命名为armeabi.jar并将其作为外部库添加到libs文件夹中。

#4


1  

I think it's a problem of the new gradle build system. Try the solution of this answer. There is also a link to a google group discussion, that describes solution and the problems more detailed.

我认为这是新的gradle构建系统的问题。尝试这个答案的解决方案。还有一个链接到谷歌小组讨论,它描述了解决方案和更详细的问题。

#5


0  

splits {
    abi {
        enable true
        reset()
        include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
        universalApk false
    }
}

I get this code from facebook fresco library

我从facebook壁画库中获取此代码