混淆的openCV库的NoSuchMethodError

时间:2018-07-30 15:31:52

标签: android opencv proguard android-proguard

我正在为我的应用程序使用Android的OpenCV库。我将minifyproguard用作应用程序的发行版。这是我的proguard-rules.pro

-dontwarn okio.**
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *;}
-keep class android.support.v7.widget.** { *; }
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keep class com.theartofdev.edmodo.cropper.*
-ignorewarnings

使用该应用作为发行版时,有时会遇到此错误:

Fatal Exception: java.lang.NoSuchMethodError: no non-static method "Lorg/opencv/core/CvException;.<init>(Ljava/lang/String;)V"
       at org.opencv.core.Mat.n_submat(Mat.java)
       at org.opencv.core.Mat.submat(Mat.java:839)
       at one.realnote.app.ImageAnchor.registerForDetectionAndTraking1(ImageAnchor.java:600)
.
.
.

如果我反编译发行版APK,则会得到CvException.java的内容:

package org.opencv.core;


public class CvException extends RuntimeException {
    private static final long serialVersionUID = 0x1L;
}

没有init方法,或者没有像异常这样的构造函数。该类的正确内容应为:

package org.opencv.core;

public class CvException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    public CvException(String msg) {
        super(msg);
    }

    @Override
    public String toString() {
        return "CvException [" + super.toString() + "]";
    }
}

那么我如何告诉我的监护人离开CvException类,甚至更好地保留所有OpenCv代码,而又不要混淆或最小化它?

谢谢!

1 个答案:

答案 0 :(得分:3)

我认为您必须在proguard文件中添加以下行:

-keep class org.opencv.** { *; }

您不需要混淆opencv模块!