Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard issue for mupdf library

My application is running well until I'm trying to build the release version. I got the following error message:

java.lang.NoSuchFieldError: no field with name='globals' signature='J' in class Lcom/artifex/mupdfdemo/MuPDFCore;

Apparently the problem is in my mupdf library. I built this library to an aar file without using proguard. Here is my build.gradle for mupdf library:

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

As you see, the runProguard is false.

Then here comes the build.gradle file of my application:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 6
        versionName "2.0"
    }

    signingConfigs {

    }

    buildTypes {
        release {
            runProguard true
            proguardFile file('key/proguard-android.txt')
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.artifex.mupdfdemo:mupdfreader-lib:1.0.0@aar'
}

And here is the proguard-android.txt file:

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

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

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

-keepclassmembers class **.R$* {
    public static <fields>;
}

-dontwarn android.support.**    
-dontwarn android.support.v4.** -keep class android.support.v4.** { *; }
-dontwarn android.support.v7.** -keep class android.support.v7.** { *; }

-keep public class com.artifex.mupdfdemo.MuPDFActivity
-keep public class com.artifex.mupdfdemo.MuPDFCore

As you see, the MuPDFCore is added to my proguard file. Can anybody help to tell what the problem is ? Thank you so much.

like image 562
Bagusflyer Avatar asked Apr 01 '14 10:04

Bagusflyer


1 Answers

By adding this line

-keep class com.artifex.mupdfdemo.** {*;}

solved the problem.

I always find the solution for the problem after I posted the questions to stackoverflow. Anyway it may help somebody else.

like image 72
Bagusflyer Avatar answered Oct 05 '22 23:10

Bagusflyer