Programming

안드로이드 충돌 로그를 얻는 방법?

procodes 2020. 6. 15. 22:22
반응형

안드로이드 충돌 로그를 얻는 방법?


시장에 있지 않은 (디버그 인증서로 서명 된) 앱이 있지만 애플리케이션이 충돌 할 때마다 충돌 로그 데이터를 얻고 싶습니다. 내 앱이 중단 된 이유에 대한 로그는 어디에서 찾을 수 있습니까?


다른 사람이 앱을 다운로드하고 원격 장치에서 충돌하는 경우 Android 오류보고 라이브러리 ( 이 SO post 에서 참조)를 살펴볼 수 있습니다 . 장치가 자신의 로컬 장치 LogCat.에만있는 경우 충돌이 발생했을 때 장치가 호스트 시스템에 연결되어 있지 않은 경우에도 장치를 연결하고 adb logcat명령을 실행 하면 전체 logcat 기록을 다운로드합니다 (적어도 일반적으로 로그 데이터의 loooot 인 버퍼링되며 무한하지 않습니다). 이러한 옵션 중 하나가 귀하의 질문에 대답합니까? 그렇지 않다면 조금 더 찾고있는 것을 명확히 할 수 있습니까?


이를 수행하는 방법은 Thread.UncaughtExceptionHandler인터페이스 를 구현하고 Thread.setDefaultUncaughtExceptionHandler()활동 시작시 인터페이스를 전달하는 것 onCreate()입니다. 구현 클래스는 다음과 같습니다 TopExceptionHandler.

public class TopExceptionHandler implements Thread.UncaughtExceptionHandler {
    private Thread.UncaughtExceptionHandler defaultUEH;
    private Activity app = null;

    public TopExceptionHandler(Activity app) {
        this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
        this.app = app;
    }

    public void uncaughtException(Thread t, Throwable e) {
        StackTraceElement[] arr = e.getStackTrace();
        String report = e.toString()+"\n\n";
        report += "--------- Stack trace ---------\n\n";
        for (int i=0; i<arr.length; i++) {
            report += "    "+arr[i].toString()+"\n";
        }
        report += "-------------------------------\n\n";

        // If the exception was thrown in a background thread inside
        // AsyncTask, then the actual exception can be found with getCause

        report += "--------- Cause ---------\n\n";
        Throwable cause = e.getCause();
        if(cause != null) {
            report += cause.toString() + "\n\n";
            arr = cause.getStackTrace();
            for (int i=0; i<arr.length; i++) {
                report += "    "+arr[i].toString()+"\n";
            }
        }
        report += "-------------------------------\n\n";

        try {
            FileOutputStream trace = app.openFileOutput("stack.trace", 
                                                        Context.MODE_PRIVATE);
            trace.write(report.getBytes());
            trace.close();
        } catch(IOException ioe) {
        // ...
        }

        defaultUEH.uncaughtException(t, e);
    }
}

참고 Android 프레임 워크의 defaultUEH가이를 처리하도록합니다.

활동 상단에 다음과 같이 위 클래스의 인스턴스를 등록하십시오.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Thread.setDefaultUncaughtExceptionHandler(new TopExceptionHandler(this));
...

이 핸들러는 파일에 추적을 저장합니다. 하면 ReaderScope다음 번에 다시 시작, 파일 및 프롬프트 그 / 그녀가 개발자에게 이메일하고자하는 경우 사용자를 감지합니다.

스택 추적을 이메일로 보내려면 다음 코드를 실행하여 이메일로 포장하십시오.

try {
    BufferedReader reader = new BufferedReader(
        new InputStreamReader(ReaderScopeActivity.this.openFileInput("stack.trace")));
    while((line = reader.readLine()) != null) {
        trace += line+"\n";
    }
} catch(FileNotFoundException fnfe) {
    // ...
} catch(IOException ioe) {
    // ...
}

Intent sendIntent = new Intent(Intent.ACTION_SEND);
String subject = "Error report";
String body = "Mail this to appdeveloper@gmail.com: " + "\n" + trace + "\n";

sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"readerscope@altcanvas.com"});
sendIntent.putExtra(Intent.EXTRA_TEXT, body);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.setType("message/rfc822");

ReaderScopeActivity.this.startActivity(Intent.createChooser(sendIntent, "Title:"));

ReaderScopeActivity.this.deleteFile("stack.trace");

또는 ACRA 오류보고 시스템을 사용할 수도 있습니다. 프로젝트 라이브러리에 ACRA.jar를 포함시키고 실행기 활동 클래스 선언 전에 아래 코드 스 니펫을 사용하십시오.

@ReportsCrashes(formKey = "", mailTo = "abc@gmail.com;def@yahoo.com", mode = ReportingInteractionMode.SILENT) 

또는 당신은 콘솔에서 이것을 시도 할 수 있습니다 :-

adb logcat -b crash 

This is from http://www.herongyang.com/Android/Debug-adb-logcat-Command-Debugging.html

You can use adb:

adb logcat AndroidRuntime:E *:S

You can try this from console:-

adb logcat -b crash


You can use Apphance. This is a cross-platform service (now mainly Android, iOS with other platforms on their way) which allows to debug remotely any mobile device (Android, iOS now - others under development). It's much more than just a crashlog, in fact it is much more: logging, reporting of problems by testers, crashlogs. It takes about 5 minutes to integrate. Currently you can request for access to closed beta.

Disclaimer: I am CTO of Polidea, a company behind Apphance and co-creator of it.

Update: Apphance is no longer closed beta! Update 2: Apphance is available as part of http://applause.com offering


If you're using Eclipse, make sure you use debug and not run. Make sure you are in the debug perspective (top right) You may have to hit 'Resume' (F8) a few times for the log to print. The crash log will be in the Logcat window at the bottom- double click for fullscreen and make sure you scroll to the bottom. You'll see red text for errors, the crash trace will be something like

09-04 21:35:15.228: ERROR/AndroidRuntime(778): Uncaught handler: thread main exiting due to uncaught exception
09-04 21:35:15.397: ERROR/AndroidRuntime(778): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dazlious.android.helloworld/com.dazlious.android.helloworld.main}: java.lang.ArrayIndexOutOfBoundsException
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268) 
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.os.Looper.loop(Looper.java:123)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.main(ActivityThread.java:3948)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at java.lang.reflect.Method.invokeNative(Native Method)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at java.lang.reflect.Method.invoke(Method.java:521)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at dalvik.system.NativeStart.main(Native Method)
09-04 21:35:15.397: ERROR/AndroidRuntime(778): Caused by: java.lang.ArrayIndexOutOfBoundsException
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at com.example.android.helloworld.main.onCreate(main.java:13)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     ... 11 more

The important parts for this one are

09-04 21:35:15.397: ERROR/AndroidRuntime(778): Caused by: java.lang.ArrayIndexOutOfBoundsException
09-04 21:35:15.397: ERROR/AndroidRuntime(778):     at com.example.android.helloworld.main.onCreate(main.java:13)

those tell us it was an array out of bounds exception on on line 13 of main.java in the onCrate method.


Here is another solution for Crash Log.

Android market has tool named "Crash Collector"

check following link for more information

http://kpbird.blogspot.com/2011/08/android-application-crash-logs.html


You can use ACRA from this. Including this library to your projects and configuring it, you could receive (into your email or gdocs) their crash reports. Sorry for my bad English.


If you are looking for a basic crash reporting tool, try crashlytics.

If you want a more advanced reporting tool, Checkout Gryphonet. It logs all the crashes occured along with the exact line of code that caused the crash along with automated markers that show you the steps the user took prior to the crash and more.

Good luck!


Use acra crash reporter for android app..Acra lib


I have created this library to solve all your problems. Crash Reporter is a handy tool to capture all your crashes and log them in device locally

Just add this dependency and you're good to go.

compile 'com.balsikandar.android:crashreporter:1.0.1'

Find all your crashes in device locally and fix them at your convenience. Crashes are saved using date and time format easy to track. Plus it also provides API for capture Logged Exceptions using below method.

CrashRepoter.logException(Exception e)

Here is a solution that can help you dump all the logs onto a text file

adb logcat -d > logs.txt

You can also use library crashcatcher


If you're just looking for the crash log while your phone is connected to the computer, use the DDMS view in Eclipse and the report is right there in LogCat within DDMS when your app crashes while debugging.


1) Plug in Phone through USB (w/ Developer Debugging options enabled)

2) Open Terminal and Navigate to your Android SDK (for Mac):

cd ~/Library/Android/sdk/platform-tools

3) Logcat from that directory (in your terminal) to generate a constant flow of logs (for Mac):

./adb logcat

4) Open your app that crashes to generate crash logs

5) Ctrl+C to stop terminal and look for the logs associated with the app that crashes. It may say something like the following:

AndroidRuntime: FATAL EXCEPTION: main


Try Carsh log app from android.

use the link to download app.

참고URL : https://stackoverflow.com/questions/3643395/how-to-get-android-crash-logs

반응형