已签名的应用程序崩溃且未签名的APK运行 [英] Signed app crashing and unsigned apk running

查看:127
本文介绍了已签名的应用程序崩溃且未签名的APK运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能与某些SO问题有关,因为我在这里搜索了很多内容,但是没有任何帖子对我有所帮助.我的应用程序在未签名的情况下运行,但在运行已签名的APK时立即崩溃.我把它放在gradle中,检查是否发现了这个错误logcat.

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)

我在帖子中看到,发布build.gradle可以使错误更容易理解,所以在这里.

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'

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

推荐答案

关于Proguard

Proguard通过做两件事基本上使您的代码更小,更难进行反向工程:

Proguard basically makes your code smaller and harder to reverse engineer by doing two things:

  1. 剥离未使用的代码
  2. 通过重命名您写成尽可能小(且难以阅读)的名称的可读符号来混淆包和符号名.

关于您的问题

看起来有些东西正在使用Java反射来查找名为REPLACE的字段,但是该字段被proguard混淆了.

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.

那么com.a.g.<init>到底是什么?这是一个类的混淆名称. <init>告诉我这是某种类的构造函数.

So what the heck is com.a.g.<init>? It's the obfuscated name of a class. The <init> tells me this is a class constructor of some sort.

但是要弄清楚ag是什么,您需要在真实符号和proguard为其分配的符号之间进行某种映射.

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.

解决方案

运行proguard时,它将生成一个符号映射文件.您可以使用Android SDK随附的proguard工具随附的retrace.sh脚本(如果在Windows上进行开发,则可以使用retrace.bat)对堆栈跟踪进行模糊处理,前提是您仍然有此映射文件并弄清楚了该映射文件的位置在您的代码中.

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.

类似的东西:

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

位置:

  • mapping.txt是proguard运行时创建的映射文件
  • stacktrace.txt包含您在问题中发布的原始堆栈跟踪
  • 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. Or, get rid of the reflective code if you can do that instead.

最后,如果进行反射调用的代码来自您不拥有的库,那么我会去查看该库的文档,看看它是否调用了您应添加到proguard中的任何保留规则配置文件并添加它们.

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.

请参阅 Android收缩代码文档有关解码混淆的堆栈跟踪的更多信息.

Please see the Android Shrink Code documentation for more information on decoding an obfuscated stack trace.

这篇关于已签名的应用程序崩溃且未签名的APK运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆