I have downloaded from git latest zBar QR Code Scanner (SDK 0.2). I am trying to implement it in my application. I work on Android Studio.
我从git最新版zBar二维码扫描器(SDK 0.2)下载。我正在尝试在我的应用程序中实现它。我在安卓工作室工作。
What have I done:
我做了什么:
- I have copied zBar.jar to libs folder of my Project.
- 我已经复制zBar。我的项目的jar到libs文件夹。
- I have created *.jar files from "amerabi", "amerabi-v7a", "x86" by zip'ing them and changing their format to *.jar.
- 我已经创建了*。jar文件来自“amerabi”、“amerabi-v7a”、“x86”,压缩它们并将它们的格式更改为*.jar。
- I have copied amerabi.jar, amerabi-v7a.jar and x86.jar to libs folder of my Project.
- 我已经复制amerabi。amerabi-v7a jar。jar和x86。我的项目的jar到libs文件夹。
-
There is no need to change anything in gradle because it is already configured to import every jar file from libs projects. See below:
由于已经配置为从libs项目导入每个jar文件,所以不需要对gradle进行任何更改。见下文:
dependencies { compile 'com.android.support:support-v4:18.0.+' compile 'com.crashlytics.android:crashlytics:1.+' compile fileTree(dir: 'libs', include: '*.jar') compile project(':FacebookSDK') compile project(':actionbarsherlock') compile project(':Aviary-SDK') }
-
Every class form zBar lib can be seen so I have configured everything. I run my ScannerActivity and in onCreate I get error in this line:
可以看到zBar lib中的每个类,因此我已经配置了所有内容。我运行ScannerActivity,在onCreate中,我在这行中得到错误:
scanner = new ImageScanner(); // this line shows an error scanner.setConfig(0, Config.X_DENSITY, 3); scanner.setConfig(0, Config.Y_DENSITY, 3);
So implementation is 1:1 the same as in example.
实现是1:1,和例子一样。
My error log:
我的错误日志:
java.lang.UnsatisfiedLinkError: Couldn't load zbarjni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/pl.toptof.android.debug-2.apk"],nativeLibraryDirectories=[/data/app-lib/pl.toptof.android.debug-2, /vendor/lib, /system/lib]]]: findLibrary returned null
Please help me with that problem. I don't know why my Android Studio can see lib but can't use it in the same way it's used in example.
请帮我解决那个问题。我不知道为什么我的Android Studio可以看到lib,但是不能像在示例中那样使用它。
4 个解决方案
#1
13
I think, you made mistake in your jars structures. If you want to make jar package from *.so libs you should use that kind of structure:
我认为你的罐子结构出了错。如果您想从*中制作jar包。所以你应该使用这种结构:
/lib/armeabi/*.so
/lib/armeabi/*.so
It is directory structure example for your library:
它是您的库的目录结构示例:
lib/
---/armeabi
------/libiconv.so
------/libzbarjni.so
and of course you should rename final package from lib.zip to armeabi.jar. In your case you should repeat this process for armeabi-v7a and x86.
当然,您应该将final包从lib.zip重命名为armeabi.jar。在您的例子中,您应该为armeabi-v7a和x86重复这个过程。
#2
1
The solution is too complicated. What I did to get it working, was to use the jar files already compiled in the example solution from this example. Copy them to your lib folder and make sure to also add them in the gradle file. However, your line compile fileTree(dir: 'libs', include: '*.jar')
should do the trick.
解决办法太复杂了。我所做的工作就是使用本示例中示例解决方案中已经编译的jar文件。将它们复制到lib文件夹中,并确保在gradle文件中添加它们。但是,您的行编译文件树(dir: 'libs',包括:'*.jar')应该可以达到这个目的。
#3
1
Put the directories armeabi, armeabi-v7a, and x86 in a sub-directory called native-libs under your root project folder. Then add these settings to your build.gradle file:
将目录armeabi、armeabi-v7a和x86放在根项目文件夹下的一个名为native-libs的子目录中。然后将这些设置添加到您的构建中。gradle文件:
android {
// other settings
sourceSets {
main {
jni.srcDirs=[] //to suppress makefiles autogeneration
jniLibs.srcDirs=['native-libs'] //native *.so in armeabi x86 and mips to include
}
}
}
The resulting .apk should have the native libs included now.
结果的.apk现在应该包含本机libs。
#4
1
You better check if you have the newest possible version of ZBar in dependencies in your app.gradle file. Getting the latest version worked for me and solved all the problems like failing to find libzbarjni.so and libiconv.so
您最好检查您的应用程序.gradle文件中是否有最新的ZBar版本。获得最新版本对我来说很有用,并解决了所有问题,比如找不到libzbarjni。所以libiconv.so
#1
13
I think, you made mistake in your jars structures. If you want to make jar package from *.so libs you should use that kind of structure:
我认为你的罐子结构出了错。如果您想从*中制作jar包。所以你应该使用这种结构:
/lib/armeabi/*.so
/lib/armeabi/*.so
It is directory structure example for your library:
它是您的库的目录结构示例:
lib/
---/armeabi
------/libiconv.so
------/libzbarjni.so
and of course you should rename final package from lib.zip to armeabi.jar. In your case you should repeat this process for armeabi-v7a and x86.
当然,您应该将final包从lib.zip重命名为armeabi.jar。在您的例子中,您应该为armeabi-v7a和x86重复这个过程。
#2
1
The solution is too complicated. What I did to get it working, was to use the jar files already compiled in the example solution from this example. Copy them to your lib folder and make sure to also add them in the gradle file. However, your line compile fileTree(dir: 'libs', include: '*.jar')
should do the trick.
解决办法太复杂了。我所做的工作就是使用本示例中示例解决方案中已经编译的jar文件。将它们复制到lib文件夹中,并确保在gradle文件中添加它们。但是,您的行编译文件树(dir: 'libs',包括:'*.jar')应该可以达到这个目的。
#3
1
Put the directories armeabi, armeabi-v7a, and x86 in a sub-directory called native-libs under your root project folder. Then add these settings to your build.gradle file:
将目录armeabi、armeabi-v7a和x86放在根项目文件夹下的一个名为native-libs的子目录中。然后将这些设置添加到您的构建中。gradle文件:
android {
// other settings
sourceSets {
main {
jni.srcDirs=[] //to suppress makefiles autogeneration
jniLibs.srcDirs=['native-libs'] //native *.so in armeabi x86 and mips to include
}
}
}
The resulting .apk should have the native libs included now.
结果的.apk现在应该包含本机libs。
#4
1
You better check if you have the newest possible version of ZBar in dependencies in your app.gradle file. Getting the latest version worked for me and solved all the problems like failing to find libzbarjni.so and libiconv.so
您最好检查您的应用程序.gradle文件中是否有最新的ZBar版本。获得最新版本对我来说很有用,并解决了所有问题,比如找不到libzbarjni。所以libiconv.so