简体   繁体   English

已签名的应用程序崩溃且未签名的APK运行

[英]Signed app crashing and unsigned apk running

This issue might be related to some SO questions as i searched a lot here, but no any post helped me. 这个问题可能与一些SO问题有关,因为我在这里搜索了很多内容,但是没有任何帖子对我有所帮助。 My app running when it is unsigned but it crashes instantly when i run the signed APK. 我的应用程序在未签名的情况下运行,但在运行已签名的APK时立即崩溃。 I put it debuggable true in gradle and checked i found this error logcat. 我把它debuggable true放在gradle中,并检查我发现此错误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. 我在帖子中看到过,发布build.gradle可以很容易地理解错误,所以这里是。

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 . 最后,这是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

Proguard basically makes your code smaller and harder to reverse engineer by doing two things: 通过执行以下两项操作,Proguard基本上使您的代码更小且更难进行反向工程:

  1. Stripping out unused code 剥离未使用的代码
  2. Obfuscating package and symbol names by renaming human-readable symbols that you wrote to names that are as small (and hard to read) as possible. 通过重命名您写给尽可能小(且难以阅读)的名称的易读符号来混淆包和符号名。

About Your Issue 关于您的问题

It looks like something is using Java reflection to lookup a field named REPLACE, but this field got obfuscated by proguard. 看起来有些东西正在使用Java反射来查找名为REPLACE的字段,但是该字段被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> ? 那么到底com.ag<init>什么呢? It's the obfuscated name of a class. 这是一个类的混淆名称。 The <init> tells me this is a class constructor of some sort. <init>告诉我这是某种类的构造函数。

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. 但是为了弄清楚ag是什么,您需要在真实符号和proguard为其分配的符号之间进行某种映射。

Solution

When proguard runs, it generates a symbol mapping file. 当proguard运行时,它将生成一个符号映射文件。 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. 您可以使用Android SDK随附的proguard工具随附的retrace.sh脚本(如果您在Windows上进行开发,则可以使用retrace.bat)来模糊处理堆栈跟踪,前提是您仍然有此映射文件并弄清楚了该映射文件的位置在您的代码中。

Something like: 就像是:

<androidsdkroot>/tools/proguard/bin/retrace.sh -verbose mapping.txt stacktrace.txt > out.txt

Where: 哪里:

  • mapping.txt is the mapping file created by proguard when it ran mapping.txt是proguard运行时创建的映射文件
  • stacktrace.txt contains your raw stack trace as you posted in your question stacktrace.txt包含您在问题中发布的原始堆栈跟踪
  • out.txt is the filename to receive the unobfuscated stack trace. out.txt是用于接收未混淆的堆栈跟踪的文件名。

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. 一旦确定了这一点,就需要在proguard配置文件中添加一个keep规则 ,以防止混淆。 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. 最后,如果进行反射调用的代码来自您不拥有的库,那么我将查看该库的文档,看看它是否调用了您应添加到proguard配置文件中的任何保留规则,并且添加它们。

Please see the Android Shrink Code documentation for more information on decoding an obfuscated stack trace. 请参阅Android Shrink Code文档,以了解有关解码混淆堆栈跟踪的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM