android FFMpeg 中加入混淆(Proguard ) JavaCPP 报错
来源:互联网 发布:linux 禁止复制文件 编辑:程序博客网 时间:2024/05/16 06:38
JavaCPP and Proguard issue
4 名作者发布了 17 个帖子
Michael David Pedersen
将帖子翻译为中文
Hello,
I'm using JavaCPP as part of JavaCV in an Android project. Everything works great, but things break after obfuscating with ProGuard. I spent hours trying to get my proguard-project.txt settings right, and by all indications (from inspecting Proguard output files), JavaCV and JavaCPP are now excluded from obfuscation.
Yet the first time I access JavaCV/JavaCPP, I get the following exception:
12-01 13:14:50.763: E/AndroidRuntime(5451): Caused by: java.lang.NullPointerException
12-01 13:14:50.763: E/AndroidRuntime(5451): at com.googlecode.javacpp.Loader.findLibrary(SourceFile:598)
12-01 13:14:50.763: E/AndroidRuntime(5451): at com.googlecode.javacpp.Loader.load(SourceFile:577)
12-01 13:14:50.763: E/AndroidRuntime(5451): at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(SourceFile:156)
The top of this trace is by doing:
IplImage.create(400, 400, IPL_DEPTH_8U, 4)
There are further warnings prior to the exception, e.g.:
12-01 13:14:50.693: D/dalvikvm(5451): DexOpt: unable to opt direct call 0x4e87 at 0x1d0 in Lcom/googlecode/javacv/cpp/opencv_core$IplImage;.getBufferedImage
12-01 13:14:50.763: D/dalvikvm(5451): No JNI_OnLoad found in /system/lib/libc.so 0x42604f78, skipping init
I've confirmed that all library files are indeed included in the resulting APK file.
Looking into the source of Loader, the above exception would indicate that the findLibrary method gets passed a null parameter for libnameversion, which in turn implies that the property "loader.library" doesn't get set correctly.
Any idea why this might happen? Note again that this only happens after obfuscation with Proguard.
I'm running out of ideas for this one, so any help would be greatly appreciated.
By the way, I noticed an issue that might be related:
https://code.google.com/p/javacpp/issues/detail?id=38
But I don't think this is the source of my problem.
Regards,
Michael
Samuel Audet
将帖子翻译为中文
Hello,
On 12/01/2013 10:50 PM, Michael David Pedersen wrote:
> I'm running out of ideas for this one, so any help would be greatly appreciated.
>
> By the way, I noticed an issue that might be related:
>
> https://code.google.com/p/javacpp/issues/detail?id=38
>
> But I don't think this is the source of my problem.
I think it's related in the sense that it should throw a more meaningful
error message than NullPointerException.
So, can you try the latest updates from the source repository:
https://javacpp.googlecode.com/archive/61c0c0b6a4f65f3a0b3633a2db66bccc59accbf2.zip
And post the error message that you get with that one? Thanks!
Samuel
On 12/01/2013 10:50 PM, Michael David Pedersen wrote:
> I'm running out of ideas for this one, so any help would be greatly appreciated.
>
> By the way, I noticed an issue that might be related:
>
> https://code.google.com/p/
>
> But I don't think this is the source of my problem.
error message than NullPointerException.
So, can you try the latest updates from the source repository:
https://javacpp.googlecode.
And post the error message that you get with that one? Thanks!
Samuel
Michael David Pedersen
将帖子翻译为中文
Hi Samuel,
Many thanks for your super quick reply.
Do you have a pre-built Jar file for the latest update? I'll try to build from sources, but it might take a while as I haven't configured an NDK environment.
Michael
- 显示引用文字 -
Michael David Pedersen
将帖子翻译为中文
Hi again - the project was easy to build after all.
Here is the new stack trace:
12-01 14:33:54.073: E/AndroidRuntime(13636): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_static from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/dk.mdp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/dk.mdp.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
12-01 14:33:54.073: E/AndroidRuntime(13636): at java.lang.Runtime.loadLibrary(Runtime.java:358)
12-01 14:33:54.073: E/AndroidRuntime(13636): at java.lang.System.loadLibrary(System.java:526)
12-01 14:33:54.073: E/AndroidRuntime(13636): at com.googlecode.javacpp.Loader.loadLibrary(SourceFile:705)
12-01 14:33:54.073: E/AndroidRuntime(13636): at com.googlecode.javacpp.Loader.load(SourceFile:571)
Does this help?
Michael
- 显示引用文字 -
Michael David Pedersen
将帖子翻译为中文
Here is some additional info further up the stack trace which may be relevant:
12-01 15:25:19.083: E/AndroidRuntime(20376): java.lang.UnsatisfiedLinkError: Couldn't load jniPointer from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/dk.mdp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/dk.mdp.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
12-01 15:25:19.083: E/AndroidRuntime(20376): at java.lang.Runtime.loadLibrary(Runtime.java:358)
12-01 15:25:19.083: E/AndroidRuntime(20376): at java.lang.System.loadLibrary(System.java:526)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.loadLibrary(SourceFile:705)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.load(SourceFile:580)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.load(SourceFile:534)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(SourceFile:156)
Michael
- 显示引用文字 -
Michael David Pedersen
将帖子翻译为中文
Just an update that I think the issue may arise from getResourceAsStream failing. I've adapted my proguard-project file to keep resource directories, and it does indeed look like the javacp/properties directory and files are preserved in the APK. Unfortunately this hasn't solved the problem.
Michael
Samuel Audet
将帖子翻译为中文
We don't need the NDK to build JavaCPP, just the JDK.
2013/12/01 23:21 "Michael David Pedersen" <michael.d...@googlemail.com>:
--- 显示引用文字 -
You received this message because you are subscribed to the Google Groups "javacpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacpp-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Samuel Audet
将帖子翻译为中文
So, can you check what errors you get with ProGuard that you do not get without? Thanks!
2013/12/02 5:47 "Michael David Pedersen" <michael.d...@googlemail.com>:
--Just an update that I think the issue may arise from getResourceAsStream failing. I've adapted my proguard-project file to keep resource directories, and it does indeed look like the javacp/properties directory and files are preserved in the APK. Unfortunately this hasn't solved the problem.MichaelYou received this message because you are subscribed to the Google Groups "javacpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacpp-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Michael David Pedersen
将帖子翻译为中文
Hi Samuel,
Thank you again for your reply.
I think you may have missed my last two messages listing the error output. I summarise below the errors I get after using Proguard:
12-01 15:25:19.083: E/AndroidRuntime(20376): java.lang.UnsatisfiedLinkError: Couldn't load jniPointer from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/dk.mdp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/dk.mdp.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
12-01 15:25:19.083: E/AndroidRuntime(20376): at java.lang.Runtime.loadLibrary(Runtime.java:358)
12-01 15:25:19.083: E/AndroidRuntime(20376): at java.lang.System.loadLibrary(System.java:526)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.loadLibrary(SourceFile:705)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.load(SourceFile:580)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacpp.Loader.load(SourceFile:534)
12-01 15:25:19.083: E/AndroidRuntime(20376): at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(SourceFile:156)
and:
12-01 14:33:54.073: E/AndroidRuntime(13636): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_static from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/dk.mdp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/dk.mdp.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
12-01 14:33:54.073: E/AndroidRuntime(13636): at java.lang.Runtime.loadLibrary(Runtime.java:358)
12-01 14:33:54.073: E/AndroidRuntime(13636): at java.lang.System.loadLibrary(System.java:526)
12-01 14:33:54.073: E/AndroidRuntime(13636): at com.googlecode.javacpp.Loader.loadLibrary(SourceFile:705)
12-01 14:33:54.073: E/AndroidRuntime(13636): at com.googlecode.javacpp.Loader.load(SourceFile:571)
I'll continue looking into this later today.
Michael
Samuel Audet
将帖子翻译为中文
Hello,
On 12/02/2013 05:00 PM, Michael David Pedersen wrote:
> Hi Samuel,
>
> Thank you again for your reply.
>
> I think you may have missed my last two messages listing the error
> output. I summarise below the errors I get after using Proguard:
I got the messages, thanks, but I was under the impression that you get
the same error messages without ProGuard. These messages do not look
like fatal error messages. We're not supposed to have libraries named
"jniPointer" or "gnustl_static" anyway, so my guess was these errors
showed up in any case, but you're saying they don't and they only happen
with ProGuard??
Samuel
On 12/02/2013 05:00 PM, Michael David Pedersen wrote:
> Hi Samuel,
>
> Thank you again for your reply.
>
> I think you may have missed my last two messages listing the error
> output. I summarise below the errors I get after using Proguard:
the same error messages without ProGuard. These messages do not look
like fatal error messages. We're not supposed to have libraries named
"jniPointer" or "gnustl_static" anyway, so my guess was these errors
showed up in any case, but you're saying they don't and they only happen
with ProGuard??
Samuel
Michael David Pedersen
将帖子翻译为中文
Hi again,
I got the messages, thanks, but I was under the impression that you get
the same error messages without ProGuard. These messages do not look
like fatal error messages. We're not supposed to have libraries named
"jniPointer" or "gnustl_static" anyway, so my guess was these errors
showed up in any case, but you're saying they don't and they only happen
with ProGuard??
These errors only show up when using Proguard, and the UnsatisfiedLinkExceptions are indeed fatal.
I've confirmed that getResourcesAsStream appears to return correctly, so that wasn't the issue. I'll continue debugging tonight.
Michael
Samuel Audet
将帖子翻译为中文
Hello,
On 12/02/2013 05:52 PM, Michael David Pedersen wrote:
> These errors only show up when using Proguard, and the
> UnsatisfiedLinkExceptions are indeed fatal.
>
> I've confirmed that getResourcesAsStream appears to return correctly, so
> that wasn't the issue. I'll continue debugging tonight.
Seems like ProGuard strips all annotations by default:
http://proguard.sourceforge.net/index.html#manual/examples.html
That's ok for most annotations as they are not required at runtime,
except for the @Platform one on the top class, because that's where the
library name is provided. However, if we use System.loadLibrary() to
load the libraries instead of Loader.load(), then we don't need to worry
about even that annotation...
Samuel
On 12/02/2013 05:52 PM, Michael David Pedersen wrote:
> These errors only show up when using Proguard, and the
> UnsatisfiedLinkExceptions are indeed fatal.
>
> I've confirmed that getResourcesAsStream appears to return correctly, so
> that wasn't the issue. I'll continue debugging tonight.
http://proguard.sourceforge.
That's ok for most annotations as they are not required at runtime,
except for the @Platform one on the top class, because that's where the
library name is provided. However, if we use System.loadLibrary() to
load the libraries instead of Loader.load(), then we don't need to worry
about even that annotation...
Samuel
Samuel Audet
将帖子翻译为中文
Hello,
BTW, I've made some changes in this revision that should help:
http://code.google.com/p/javacpp/source/detail?r=a9bcf01c04868c1f1036cf0f2d6a90e9d1265300
Let me know if that works, thanks!
Samuel
- 显示引用文字 -
http://code.google.com/p/
Let me know if that works, thanks!
Samuel
Michael David Pedersen
将帖子翻译为中文
Hi Samuel,
Thanks again for your help. The problem was indeed caused by Proguard stripping annotations. I haven't tried your update, but I did configure Proguard to keep annotations with the -keepattributes flag in proguard-project.txt as follows:
-keepattributes *
(can of course be narrowed down to keep only selected flags).
With this, everything works perfectly.
Cheers,
Michael
- 显示引用文字 -
Paul Falstad
将帖子翻译为中文
Thanks!! I was having the same problem. Unfortunately -keepattributes * did not work because I was using an old version of Proguard (4.7). I upgraded to the latest version (4.11) and I am all set.
- 显示引用文字 -
Jinesh Jain
将帖子翻译为中文
Hi Michael and Samuel,
I am facing the same problems as described in this thread. JavaCPP and JavaCV along with Ffmpeg libraries work fine without proguard but when using Proguard, I get the errors above. Unfortunately upgrading to Proguard 4.11 and using -keepattributes *Annotation* do not work for me.
Do you mind sharing how you solved the problem? Can you post your Proguard.cfg file please?
Thanks,
Jinesh
- 显示引用文字 -
Michael David Pedersen
将帖子翻译为中文
Hi Jinesh,
Here is the full -keepattributes declaration I ended up using (but probably you won't need everything):
-keepattributes *Annotation*, Exceptions, Signature, Deprecated, SourceFile, SourceDir, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, Synthetic, EnclosingMethod, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, AnnotationDefault, InnerClasses
Here are some further declarations that I experimented with - I don't think they are necessary for javacpp, but you could try if the above isn't sufficient:
-keeppackagenames com.googlecode.javacpp.properties
-keepdirectories com/googlecode/javacpp/properties
-libraryjars libs/javacpp.jar
-libraryjars libs/javacv.jar
-keep public class com.googlecode.javacpp.Loader
-keepclassmembers class com.googlecode.javacpp.Loader {
static void putMemberOffset(java.lang.String, java.lang.String, int);
}
-keepclassmembers class com.googlecode.javacpp.Pointer {
void init(long, int, long);
}
Hope that helps, I know how incredibly frustrating Proguard debugging can be.
Michael
On Tue, Mar 25, 2014 at 3:45 AM, Jinesh Jain <jines...@zeronoiseapps.com> wrote:
Hi Michael and Samuel,I am facing the same problems as described in this thread. JavaCPP and JavaCV along with Ffmpeg libraries work fine without proguard but when using Proguard, I get the errors above. Unfortunately upgrading to Proguard 4.11 and using -keepattributes *Annotation* do not work for me.Do you mind sharing how you solved the problem? Can you post your Proguard.cfg file please?Thanks,Jinesh
0 0
- android FFMpeg 中加入混淆(Proguard ) JavaCPP 报错
- Android 中 ProGuard 混淆详解(一)
- Android 中 ProGuard 混淆详解(二)
- Proguard打包混淆(使用第三方包时)报错
- Android ProGuard混淆(一)
- Android ProGuard混淆(二)
- Android proguard(混淆)模板
- javacv和javacpp录制视频混淆打包后运行报错
- Android中代码混淆之proguard
- android 代码混淆中ProGuard使用详情
- Android项目中使用javacv和javacpp的代码混淆配置
- Android Java混淆(ProGuard)(转)
- android混淆器(Proguard)小记
- android 混淆(proguard)代码-简单版
- Android 混淆proguard的实现(图文)
- Android的代码混淆(ProGuard)
- Android 签名+混淆( 签名+proguard.cfg)
- Android Studio的Proguard(代码混淆)
- discuz 如何添加数据DB::insert和更新数据DB::update 查询DB::query删除DB::delete
- sql 分组取每组的前n条或每组的n%(百分之n)的数据
- wpa_supplicant 初始化流程分析
- Android中this、super的区别
- PPT显示页码
- android FFMpeg 中加入混淆(Proguard ) JavaCPP 报错
- Observability at Twitter
- Java中三种流行的数据连接池
- 今天简要介绍继承,多态和数组
- 牛新庄的DB2之路
- [NodeJS]使用Node.js写一个简单的在线聊天室
- registerReceiver和unregisterReceiver的调用者必须一致
- 什么是MDI窗体?
- 曝广州星班客餐饮管理服务有限公司—晶锅英雄水晶锅加盟受骗记录