Android项目中使用javacv和javacpp的代码混淆配置

本文介绍了解决JavaCV和JavaCPP在Android项目中遇到的混淆问题的方法。通过调整ProGuard配置文件,特别是添加特定属性保持指令,成功避免了运行时出现的UnsatisfiedLinkError。
摘要由CSDN通过智能技术生成

最近一个项目中涉及到了视频录制,使用到了javacv和javacpp,于是在打包混淆的时候出了问题,总是报错,错误信息如下:

02-27 13:43:53.400: E/AndroidRuntime(25640): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jniPointer: findLibrary returned null
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at java.lang.Runtime.loadLibrary(Runtime.java:365)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at java.lang.System.loadLibrary(System.java:535)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at com.googlecode.javacpp.Loader.loadLibrary(Unknown Source)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at com.googlecode.javacpp.Loader.load(Unknown Source)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at com.googlecode.javacpp.Loader.load(Unknown Source)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	at com.googlecode.javacv.cpp.avcodec$AVPacket.<clinit>(Unknown Source)
02-27 13:43:53.400: E/AndroidRuntime(25640): 	... 12 more
02-27 13:43:53.400: E/AndroidRuntime(25640): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load gnustl_static: findLibrary returned null
02-27 13:43:53.400: E/AndroidRuntime(25640): 	... 18 more

搞了一下午,头都大了,最后终于解决了:

相关配置如下:

-libraryjars libs/javacpp.jar
-libraryjars libs/javacv.jar

-dontwarn com.googlecode.**
-keep class com.googlecode.**{*;}
-keepattributes *Annotation*
-keepattributes Exceptions,InnerClasses,Signature  
-keepattributes SourceFile,LineNumberTable


刚开始没有添加:

-keepattributes Exceptions,InnerClasses,Signature  
-keepattributes SourceFile,LineNumberTable

添加之后就不报错了,至于这两行的具体作用,暂时我还没有查资料。


所有的混淆配置如下:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-libraryjars libs/android-async-http-1.4.4.jar
-libraryjars libs/android-support-v7-recyclerview.jar
-libraryjars libs/mta-sdk-1.6.2.jar
-libraryjars libs/open_sdk_r4547.jar
-libraryjars libs/universal-image-loader-1.9.3.jar
-libraryjars libs/javacpp.jar
-libraryjars libs/javacv.jar


-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keep class com.sina.**{*;}

-dontwarn com.googlecode.**
-keep class com.googlecode.**{*;}
-keepattributes *Annotation*
-keepattributes Exceptions,InnerClasses,Signature  
-keepattributes SourceFile,LineNumberTable

-dontwarn android-async-http-1.4.4.jar.**
-keep class android-async-http-1.4.4.jar.**{*;}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值