java.lang.NoSuchFieldError:没有静态字段PUBLIC_ONLY

时间:2018-02-05 18:52:36

标签: android crash proguard

我的应用程序在调试模式下没有任何问题。 但是当我编译我的应用程序时,它会在与升级应用程序付费相关的活动中崩溃。

我猜这是因为ProGuard。所以我把这行添加到我的proguard-rules.pro文件中:

-keep class ir.ali_kh_y.telegramschool.GoldenVersionActivity { *; }

我也试过这个:

-keep class ir.ali_kh_y.telegramschool.GoldenVersionActivity.class { *; }

但是当我打开那个活动时,我的应用程序又崩溃了......

错误

FATAL EXCEPTION: main

Process: ir.ali_kh_y.telegramschool, PID: 6838

java.lang.NoSuchFieldError: No static field PUBLIC_ONLY of type Lcom/b/a/a/a/a/a/a/e$a; in class Lcom/b/a/a/a/a/a/a/e$a; or its superclasses (declaration of 'com.b.a.a.a.a.a.a.e$a' appears in /data/app/ir.ali_kh_y.telegramschool-1/base.apk)
at java.lang.Class.getDeclaredAnnotation(Native Method)
at java.lang.Class.getAnnotation(Class.java:2352)
at com.b.a.a.a.a.a.c.e.u$a.<clinit>(Unknown Source)
at com.b.a.a.a.a.a.c.e.u$a.a(Unknown Source)
at com.b.a.a.a.a.a.c.t.<clinit>(Unknown Source)
at com.b.a.b.b(Unknown Source)
at com.b.a.b.a(Unknown Source)
at b.a.a.e.a(Unknown Source)
at b.a.a.e.<init>(Unknown Source)
at b.a.a.a.<init>(Unknown Source)
at b.a.a.a.<init>(Unknown Source)
at ir.ali_kh_y.telegramschool.GoldenVersionActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

proguard-rules.pro

-ignorewarnings
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
-keep public class ir.adad.client.** { *; }
-keep class ir.ali_kh_y.telegramschool.GoldenVersionActivity.class { *; }

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "ir.ali_kh_y.telegramschool"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 2
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            useProguard true
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })


    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.4.0'
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
    compile 'com.github.bumptech.glide:glide:4.2.0'
    compile 'com.github.chrisbanes:PhotoView:2.1.3'
    compile 'io.nivad.billing:library:0.1.8'
    compile 'com.auth0:java-jwt:2.1.0'
    compile 'com.github.simbiose:Encryption:2.0.1'
    compile 'com.wang.avi:library:2.1.3'
    compile 'ir.adad.androidsdkv3:AdadSDKv3:3.3.1'
    compile 'me.cheshmak:analytics:2.0.6'
    compile 'com.google.android.gms:play-services-gcm:10.0.1'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
}

现在有两个问题:

  1. 我该怎么做才能解决这个问题?
  2. 如果我使用-keep class ...对我的应用程序是否安全?
  3. 如果不安全,还有其他方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

问题解决了! 那是因为Nivad。我不得不将其添加到我的计划规则中:

-keep class io.nivad.** { *; }
-keep class com.auth0.jwt.** { *; }
-dontwarn org.**
-dontwarn javax.**
-dontwarn com.auth0.jwt.**