JavaCPP and Proguard issue
4 名作者发布了 17 个帖子
|
|
|
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:
But I don't think this is the source of my problem.
Regards,
Michael
|
|
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/ 61c0c0b6a4f65f3a0b3633a2db66bc cc59accbf2.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
|
|
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
- 显示引用文字 -
|
|
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
- 显示引用文字 -
|
|
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
- 显示引用文字 -
|
|
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
|
|
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.
|
|
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.
Michael
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Hello,
BTW, I've made some changes in this revision that should help:
http://code.google.com/p/ javacpp/source/detail?r= a9bcf01c04868c1f1036cf0f2d6a90 e9d1265300
Let me know if that works, thanks!
Samuel
- 显示引用文字 -
http://code.google.com/p/
Let me know if that works, thanks!
Samuel
|
|
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
- 显示引用文字 -
|
|
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.
- 显示引用文字 -
|
|
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
- 显示引用文字 -
|
|
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, RuntimeVisibleParameterAnnotat
ions, RuntimeInvisibleParameterAnnot
ations, 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