마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

shell 명령어 후 앱 강제 종료 문제

0 추천

안녕하세요. 초보 개발자 입니다.

현재 하는 프로젝트가 app 내에서 shell 명령어가 필요한 프로젝트인데요.

이 동작을 실행하면 저절로 앱이 종료가 됩니다.

무슨 문제인지는 모르겠는데 코드와 로그 내용 올려보겠습니다..

도움 부탁드리겠습니다.

 

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tcpDumpOff();
               

    }
    
    private void tcpDumpOff() {
        Process process;
        Runtime runtime = Runtime.getRuntime();

        try {
            Log.d("hcjung","tcpdumpoff");
            String cmd = "pkill -9 tcpdump\n";
            process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.flush();
            os.writeBytes(cmd);
//            os.flush();
//            os.writeBytes("exit\n");
//            os.flush();
//            os.close();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }

 

로그 내용은

 

09-20 10:54:37.861 17889-17889/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-20 10:54:37.866 17889-17889/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
09-20 10:54:37.866 17889-17889/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 830: Landroid/content/res/TypedArray;.getType (I)I
09-20 10:54:37.866 17889-17889/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
09-20 10:54:37.906 17889-17889/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
09-20 10:54:37.906 17889-17889/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 18881: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;

 

참고로 저 코드 이후에 다른 코드도 있습니다. 그런데 저부분만 실행되고는 바로 앱이 종료되는것이구요..

헐잘생겼다 (570 포인트) 님이 2016년 9월 20일 질문

2개의 답변

0 추천
 
채택된 답변
자답입니다.

코드 상의 pkill 이란 명령어가 뒤에 있는 프로세스 명이 들어간 프로세스를 다 kill 하는 명령어더군요

 

프로젝트명이 tcpdump 라 프로젝트도 같이 죽었던것 같습니다.
헐잘생겼다 (570 포인트) 님이 2016년 9월 21일 답변
0 추천
혹시 jar 라이브러리에 있는 함수 가져다 쓰시나요?

그 부분 확인 해볼 필요가 있을거 같은데요
Development Guy (70,570 포인트) 님이 2016년 9월 20일 답변
testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:support-v4:24.2.0'

디펜던시에는 이렇게 5가지 추가가 되어있습니다...
만약 jar 라이브러리를 import하여 사용하시는 경우라면
파일만 첨부할게 아니라

compile files('libs/이름.jar')

형태로 추가가 되어 있어야 합니다.
Instant Run Runtime started. Android package is com.example.hyeon.tcpdump, real application class is null.
09-20 13:52:48.706 15411-15411/com.example.hyeon.tcpdump W/InstantRun: No instant run dex files added to classpath
09-20 13:52:48.746 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
09-20 13:52:48.746 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve interface method 18357: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
09-20 13:52:48.746 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve interface method 18359: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve interface method 18363: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 757: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 779: Landroid/content/res/TypedArray;.getType (I)I
09-20 13:52:48.751 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 720: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 722: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-20 13:52:48.786 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
09-20 13:52:48.796 15411-15411/com.example.hyeon.tcpdump I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
09-20 13:52:48.796 15411-15411/com.example.hyeon.tcpdump W/dalvikvm: VFY: unable to resolve virtual method 472: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
09-20 13:52:48.796 15411-15411/com.example.hyeon.tcpdump D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
09-20 13:52:48.801 15411-15411/com.example.hyeon.tcpdump D/hcjung: tcpdumpoff
09-20 13:52:48.816 15411-15411/com.example.hyeon.tcpdump D/Activity: #1 setTransGradationModeColor false
09-20 13:52:48.881 15411-15411/com.example.hyeon.tcpdump D/libEGL: loaded /system/lib/egl/libEGL_mali.so
09-20 13:52:48.891 15411-15411/com.example.hyeon.tcpdump D/libEGL: loaded /system/lib/egl/libGLESv1_CM_mali.so
09-20 13:52:48.891 15411-15411/com.example.hyeon.tcpdump D/libEGL: loaded /system/lib/egl/libGLESv2_mali.so

에러메세지가 이렇게 나오는데 관련 메세지를 검색해봐도 모르겠네요..ㅠㅠ
상세히 알려주셔서 감사한데 제가 너무 무지한가봐요...
뭐가 문제일까요.

jar 라이브러리를 따로 import 해서 사용한적은 없는것 같습니다..
혹시 메인app프로젝트의 build.gradle 내용 전체좀 올려 주실수 있을까요?
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.hyeon.tcpdump"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:support-v4:24.2.0'
}

여기있습니다..
dependencies에서 v7 support:appcompat 라이브러리 뒤의 버전을 recyclerview처럼 '+' 로 바꿔보세요.
마찬가지입니다...
혹시 shell 명령어 쓰면 자동종료 되는문제가
이 라이브러리와 관련이 있는걸까요?

++ 보니까 shell 명령어랑 관련이 없나봐요 죽는것이... 후..너무 무지해서 ..ㅠㅠ 더 알아봐야겠네요
올려주신 오류 로그를 보면 v7 support 라이브러리 관련 오류 입니다.
제 예전 경험으로는 support 라이브러리 버전을 한단계 낮추는 것으로 해결한 기억이 있는데 똑같이 현재 24.1.1 버전에서 23.0.0으로도 바꿔보시기 바랍니다.
우선 제가 이문제를 해결하든 못하든 정말 감사합니다.
개발꾼님 말씀대로 버전을 한단계 낮추니 못찾던 메소드가 현저히 줄었구요
비슷한 방법으로 해결해 보도록 하겠습니다.

이렇게 신경써주셔서 정말 정말 감사합니다.
...