0

After uploading a compiled APK to the Google Developer Play Console, you are able to see log messages when the app crashes. Also, when testing an app in debug mode, you are able to see log messages if the app crashes.

Is there a way to view log messages when testing an app as a compiled APK? Note that I am using ProGuard.

What I mean by this is being able to view log messages from the app crash somehow when installing the compiled APK on the device. If the question is still unclear, let me know in the comments.

Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125

2 Answers2

0

here is some code sample to have a clear stack when your app is encrypted with proguard :

    private static void trace(String txt) {
    if (ENABLE_TRACE) {
        Trace.trace(txt);
        Trace.trace("\n");
        System.out.println(txt);
    }
}

public static String retrieveProguardStackInternal(String stack, File proguardFile,String sdkPath,String javaPath) {
    String ret = stack;
    trace("trying to uncrypt stack");
    trace("==== raw stack ====");
    trace(stack);
    if ((stack == null) || (stack.length() == 0) || (proguardFile == null) || (!proguardFile.exists()) || (sdkPath == null) || (javaPath == null)) {
        if ((stack == null) || (stack.length() == 0)) {
            trace("empty stack => abort");
        }
        if (!proguardFile.exists()) {
            trace("proguard file does not exists "+proguardFile.getAbsolutePath());
        }
        if (sdkPath == null) {
            trace("sdk path not defined");
        }
        if (javaPath == null) {
            trace("java path not defined");
        }
        return ret;
    }       
    trace("sdk : "+sdkPath);
    trace("jdk : "+javaPath);
    StringBuilder sb = new StringBuilder();
    sb.append(sdkPath);
    sb.append(File.separatorChar);
    sb.append("tools");
    sb.append(File.separatorChar);
    sb.append("proguard");
    sb.append(File.separatorChar);
    sb.append("lib");
    sb.append(File.separatorChar);
    sb.append("retrace.jar");
    String retraceJarPath = sb.toString();
    File retraceJar = new File(retraceJarPath);
    if (!retraceJar.exists()) {
        trace("proguard lib not found at "+retraceJarPath);
        return ret;
    }   
    sb = new StringBuilder();
    sb.append(javaPath);
    sb.append(File.separatorChar);
    sb.append("java");
    String javaexePath = sb.toString();
    sb = new StringBuilder();
    try {
        // using the Runtime exec method:
        Process p = Runtime.getRuntime().exec(new String[] {javaexePath,"-jar",retraceJarPath,proguardFile.getAbsolutePath()});
        OutputStream out = p.getOutputStream();
        out.write(stack.getBytes());
        out.close();
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        // read the output from the command
        String line = null;
        String lineSeparator = System.getProperty("line.separator");
        while ((line = stdInput.readLine()) != null) {
            sb.append(line);
            sb.append(lineSeparator);
        }
        // read any errors from the attempted command
        StringBuilder error = new StringBuilder();
        while ((line = stdError.readLine()) != null) {
            error.append(line);
        }
        trace("error trace :"+error);
        p.waitFor(); 
    } catch (Throwable e) {
        trace("exception happened - here's what I know: ");
        trace(e.toString());
    }
    ret = sb.toString();
    trace("=== final stack ===");
    trace(ret);
    trace("===================");
    return ret;
}

you need to provide the raw stack + the map file generated by proguard during compilation

Jerome B.
  • 244
  • 2
  • 8
0

By simply putting debuggable true in the build.gradle of my app, I could view stack traces (without line numbers however) of a compiled APK app when my phone was connected to Android Studio.

My build.gradle file looked a little like this after adding this line in:

...

buildTypes {
    release {
        debuggable true // This allows stack traces to appear in LogCat
        minifyEnabled true // This obfuscates the code
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

...

Also, this answer explains how you can show line numbers in stack traces with ProGuard.

Community
  • 1
  • 1
Farbod Salamat-Zadeh
  • 19,687
  • 20
  • 75
  • 125