This issue might be related to some SO questions as i searched a lot here, but no any post helped me. My app running when it is unsigned but it crashes instantly when i run the signed APK. I put it debuggable true
in gradle and checked i found this error logcat.
java.lang.NoSuchFieldError: No static field REPLACE of type Lcom/a/a/a$a; in class Lcom/a/a/a$a; or its superclasses (declaration of 'com.a.a.a$a' appears in /data/app/com.aami.aruman.com-J1sPXkw9O_ZNL4zfcpqgMQ==/base.apk)
at java.lang.reflect.Field.getAnnotationNative(Native Method)
at java.lang.reflect.Field.getAnnotation(Field.java:847)
at com.a.g.<init>(Unknown Source:94)
at com.a.f.a(Unknown Source:97)
at com.a.f.a(Unknown Source:126)
at com.a.f.<init>(Unknown Source:27)
at com.a.b.a(Unknown Source:22)
at com.a.a.a(Unknown Source:3)
at com.a.a.a(Unknown Source:1)
at com.a.a.a(Unknown Source:9)
at com.a.b.a.onCreate(Unknown Source:3)
at com.aami.aruman.com.codingnation.base.DroiderApplication.onCreate(Unknown Source:0)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5747)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
07-12 22:22:18.355 13073-13073/com.aami.aruman.com E/UncaughtException: java.lang.NoSuchFieldError: No static field REPLACE of type Lcom/a/a/a$a; in class Lcom/a/a/a$a; or its superclasses (declaration of 'com.a.a.a$a' appears in /data/app/com.aami.aruman.com-J1sPXkw9O_ZNL4zfcpqgMQ==/base.apk)
at java.lang.reflect.Field.getAnnotationNative(Native Method)
at java.lang.reflect.Field.getAnnotation(Field.java:847)
at com.a.g.<init>(Unknown Source:94)
at com.a.f.a(Unknown Source:97)
at com.a.f.a(Unknown Source:126)
at com.a.f.<init>(Unknown Source:27)
at com.a.b.a(Unknown Source:22)
at com.a.a.a(Unknown Source:3)
at com.a.a.a(Unknown Source:1)
at com.a.a.a(Unknown Source:9)
at com.a.b.a.onCreate(Unknown Source:3)
at com.aami.aruman.com.codingnation.base.DroiderApplication.onCreate(Unknown Source:0)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5747)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I have seen in posts, that posting build.gradle
can make it easy to understand the error so here is.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 26
useLibrary 'org.apache.http.legacy'
buildToolsVersion '27.0.3'
defaultConfig {
multiDexEnabled true
applicationId "com.aami.aruman.com"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/maven/pom.properties'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/gson/FieldAttributes.class'
exclude '.readme'
}
}
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.android.support:appcompat-v7:26.1.+'
implementation 'com.android.support:gridlayout-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.facebook.android:facebook-android-sdk:4.10.0'
implementation 'com.android.support:design:26.1.+'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'de.hdodenhof:circleimageview:1.3.0'
implementation 'com.google.android.gms:play-services-places:12.0.1'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.lzyzsd:circleprogress:1.2.1'
implementation 'com.romandanylyk:pageindicatorview:0.2.0'
implementation 'com.nshmura:snappysmoothscroller:1.0.0'
implementation 'com.codemybrainsout.rating:ratingdialog:1.0.8'
implementation 'org.adw.library:discrete-seekbar:1.0.1'
implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-storage:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.facebook.fresco:fresco:1.3.0'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.nispok:snackbar:2.11.+'
implementation 'com.github.ybq:Android-SpinKit:1.1.0'
implementation 'com.gmail.samehadar:iosdialog:1.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'joda-time:joda-time:2.9.4'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
implementation 'com.google.firebase:firebase-crash:12.0.1'
implementation 'com.github.clans:fab:1.6.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
transitive = true
}
implementation 'com.github.florent37:singledateandtimepicker:2.0.5'
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.payumoney.sdkui:plug-n-play:1.3.0'
implementation 'com.amitshekhar.android:jackson-android-networking:1.0.1'
implementation 'com.daasuu:animateHorizontalProgressBar:0.2.4'
}
apply plugin: 'com.google.gms.google-services'
And finally this is the proguard
.
-dontwarn org.apache.**
-dontwarn javax.annotation.**
-dontwarn com.squareup.picasso.**
-dontwarn okio.**
-keep class com.google.**
-dontwarn com.google.**
-keepattributes Signature
-dontwarn retrofit2.Platform$Java8
# For using GSON @Expose annotation
-keepattributes *Annotation*
-dontwarn org.**
-dontwarn javax.**
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class com.squareup.okhttp.{ *; }
-dontwarn com.squareup.okhttp.**
-keep class com.facebook.{ *; }
-dontwarn com.facebook.**
-keep class ohttp3.{ *; }
-dontwarn okhttp3.**
-keep class org.joda.{ *; }
-dontwarn org.joda.**
-keepclassmembers class * {
private <fields>;
}
# Proguard configuration for Jackson 2.x (fasterxml package instead of codehaus package)
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers class com.aami.aruman.com.codingnation.beans.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn org.springframework.**
About Proguard
Proguard basically makes your code smaller and harder to reverse engineer by doing two things:
About Your Issue
It looks like something is using Java reflection to lookup a field named REPLACE, but this field got obfuscated by proguard.
From your posted stack trace, this:
com.a.g.<init>(Unknown Source:94)
is the code that is making the reflective call.
So what the heck is com.ag<init>
? It's the obfuscated name of a class. The <init>
tells me this is a class constructor of some sort.
But in order to figure out what a
and g
are, you'd need some sort of mapping between the real symbol and the one that proguard assigned it.
Solution
When proguard runs, it generates a symbol mapping file. You can unobfuscate your stack trace using the retrace.sh script (or retrace.bat if you're developing on Windows) that comes with the proguard tool packaged with the Android SDK if you've still got this mapping file and figure out where this is in your code.
Something like:
<androidsdkroot>/tools/proguard/bin/retrace.sh -verbose mapping.txt stacktrace.txt > out.txt
Where:
Once you've figured that out, you'll need to add a keep rule to your proguard config file to prevent this from being obfuscated. Or, get rid of the reflective code if you can do that instead.
Lastly, if the code that is making the reflective call is from a library you don't own, I would go look at the documentation for that library and see if it calls out any keep rules you should be adding to your proguard config file and add them.
Please see the Android Shrink Code documentation for more information on decoding an obfuscated stack trace.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.