在真实设备上测试时Android应用程序崩溃

时间:2017-01-02 11:31:18

标签: android

Android应用程序在模拟器上运行时工作正常,但在真实设备上进行测试时崩溃。

我们创建了一个简单的Android应用程序来连接Soap Web服务。它适用于Android模拟器,但在使用真正的Android手机测试时崩溃。 我们检查它的版本没有问题。

完整的logcat输出如下:

$ adb shell am start -n "com.asoftit.loyaltyplus/com.asoftit.loyaltyplus.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Connected to process 22149 on device samsung-gt_s7580-4203ec61e40e7100
I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
W/dalvikvm: VFY: unable to resolve interface method 16143: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
W/dalvikvm: VFY: unable to resolve interface method 16145: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
W/dalvikvm: VFY: unable to resolve interface method 16149: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
W/dalvikvm: VFY: unable to resolve virtual method 455: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
W/dalvikvm: VFY: unable to resolve virtual method 477: Landroid/content/res/TypedArray;.getType (I)I
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
I/dalvikvm: Could not find method android.widget.FrameLayout.startActionModeForChild, referenced from method android.support.v7.widget.ActionBarContainer.startActionModeForChild
W/dalvikvm: VFY: unable to resolve virtual method 16580: Landroid/widget/FrameLayout;.startActionModeForChild (Landroid/view/View;Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
D/dalvikvm: VFY: replacing opcode 0x6f at 0x0002
I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
W/dalvikvm: VFY: unable to resolve virtual method 269: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
W/dalvikvm: VFY: unable to resolve virtual method 418: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
W/dalvikvm: VFY: unable to resolve virtual method 420: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
W/dalvikvm: VFY: unable to resolve instanceof 140 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper;
D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c
D/libEGL: loaded /system/lib/egl/libGLES_hawaii.so

          [ 01-02 16:37:16.224 22149:22149 D/         ]
          mem_init ++


          [ 01-02 16:37:16.224 22149:22149 D/         ]
          gHwMemAllocator client 3

          [ 01-02 16:37:16.224 22149:22149 D/         ]
          **** Using ION allocator ****


          [ 01-02 16:37:16.224 22149:22149 D/         ]
          registered SIGUSR1[10] for pid[22149]

          [ 01-02 16:37:16.224 22149:22149 D/         ]
          HwMemAllocatorImpl Static Counters 0 0


          [ 01-02 16:37:16.224 22149:22149 D/         ]
          HwMemAllocatorImpl[40fd4dcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]


          [ 01-02 16:37:16.224 22149:22149 D/         ]
          mem_init 40fd4dcc--
D/ION: config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
D/MM_DEVICE: Waiting for mm thread to come up
D/MM_DEVICE: mm_device_thread starting
D/HAWAII_EGL: eglCreateContext() config: 18 context: 0x4c48a058, VC context 1, Thread 22149
D/HAWAII_EGL: Set SWAP INTERVAL 0
D/HAWAII_EGL: eglCreateWindowSurface() surface: 0x40054928, VC surface: 1, Thread: 22149
D/HAWAII_EGL: eglMakeCurrent(0x4c48a058, 0x40054928, 0x40054928) Thread: 22149
D/OpenGLRenderer: Enabling debug mode 0
D/WritingBuddyImpl: getCurrentWritingBuddyView() 
D/WritingBuddyImpl: getCurrentWritingBuddyView() 
D/WritingBuddyImpl: getCurrentWritingBuddyView() 
E/dalvikvm: Could not find class 'org.kxml2.kdom.Node', referenced from method org.ksoap2.SoapEnvelope.parseBody
W/dalvikvm: VFY: unable to resolve instanceof 2313 (Lorg/kxml2/kdom/Node;) in Lorg/ksoap2/SoapEnvelope;
D/dalvikvm: VFY: replacing opcode 0x20 at 0x002f
E/dalvikvm: Could not find class 'org.kxml2.kdom.Node', referenced from method org.ksoap2.SoapEnvelope.parseHeader
W/dalvikvm: VFY: unable to resolve new-instance 2313 (Lorg/kxml2/kdom/Node;) in Lorg/ksoap2/SoapEnvelope;
D/dalvikvm: VFY: replacing opcode 0x22 at 0x0003
E/dalvikvm: Could not find class 'org.kxml2.kdom.Node', referenced from method org.ksoap2.SoapEnvelope.writeBody
W/dalvikvm: VFY: unable to resolve check-cast 2313 (Lorg/kxml2/kdom/Node;) in Lorg/ksoap2/SoapEnvelope;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x000f
W/dalvikvm: VFY: array-length on non-array
W/dalvikvm: VFY:  rejecting opcode 0x21 at 0x0007
W/dalvikvm: VFY:  rejected Lorg/ksoap2/SoapEnvelope;.writeHeader (Lorg/xmlpull/v1/XmlSerializer;)V
W/dalvikvm: Verifier rejected class Lorg/ksoap2/SoapEnvelope;
W/dalvikvm: threadid=11: thread exiting with uncaught exception (group=0x413b9960)
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
                  java.lang.RuntimeException: An error occured while executing doInBackground()
                      at android.os.AsyncTask$3.done(AsyncTask.java:299)
                      at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
                      at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
                      at java.util.concurrent.FutureTask.run(FutureTask.java:239)
                      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
                      at java.lang.Thread.run(Thread.java:856)
                   Caused by: java.lang.VerifyError: org/ksoap2/SoapEnvelope
                      at com.asoftit.loyaltyplus.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:84)
                      at com.asoftit.loyaltyplus.MainActivity$MyAsyncTask.doInBackground(MainActivity.java:53)
                      at android.os.AsyncTask$2.call(AsyncTask.java:287)
                      at java.util.concurrent.FutureTask.run(FutureTask.java:234)
                      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                      at java.lang.Thread.run(Thread.java:856) 
W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
D/HAWAII_EGL: eglMakeCurrent(NULL) Thread: 22149
D/HAWAII_EGL: eglDestroySurface() surface: 0x40054928, android window 0x512e16c8, Thread: 22149
D/HAWAII_EGL: eglMakeCurrent(0x4c48a058, 0x512e0dd8, 0x512e0dd8) Thread: 22149
D/HAWAII_EGL: eglMakeCurrent(NULL) Thread: 22149
D/HAWAII_EGL: eglMakeCurrent(0x4c48a058, 0x512e0dd8, 0x512e0dd8) Thread: 22149
D/HAWAII_EGL: eglMakeCurrent(NULL) Thread: 22149
I/Process: Sending signal. PID: 22149 SIG: 9
Application terminated.

这是主要活动:

package com.asoftit.loyaltyplus;

import android.os.AsyncTask;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class MainActivity extends AppCompatActivity {

    EditText etPhoneNo;
    Button btSubmit;
    TextView tvFirstName;
    //instantiating handler is important
    Handler mHandler = new Handler();

    public String WSDL_TARGET_NAMESPACE ;
    public String SOAP_ADDRESS;
    private SoapObject request;
    private HttpTransportSE httpTransport;
    private SoapSerializationEnvelope envelope;
    Object response;

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

        etPhoneNo = (EditText)findViewById(R.id.etPhoneNo);
        btSubmit = (Button)findViewById(R.id.btSubmit);
        tvFirstName = (TextView)findViewById(R.id.tvFirstName);
    }

    public  void GetUserDetailsByPhoneNo(View view){
        //call async task from here
        //192.99.4.45
        String inputPhone = etPhoneNo.getText().toString();
        String [] params = new String[]{inputPhone} ;
        new MyAsyncTask().execute(params);

    }

    class MyAsyncTask extends AsyncTask<String,Void,String>
    {
        public String SOAP_ACTION = "http://tempuri.org/getUserDetailsByPhoneNo";
        public String OPERATION_NAME = "getUserDetailsByPhoneNo";

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            WSDL_TARGET_NAMESPACE ="http://tempuri.org/";
            SOAP_ADDRESS = "http://loyaltywebservice.asoftit.com/AndroidWebService.asmx";
            request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

            response = null;

        }




        @Override
        protected String doInBackground(String... params){
//            SOAP_ADDRESS = "http://"+params[0]+"/AndroidWebService.asmx";


            PropertyInfo pi = new PropertyInfo();
            pi.setName("PhoneNo");
            pi.setValue(params[0]);
            pi.setType(String.class);
            request.addProperty(pi);
            pi= new PropertyInfo();

            envelope= new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.setOutputSoapObject(request);
            httpTransport = new HttpTransportSE(SOAP_ADDRESS);
            try{
                httpTransport.call(SOAP_ACTION, envelope);
                response = envelope.getResponse();

            }
            catch (Exception exp)
            {
                response = exp.getMessage();
            }
            return response.toString();
        }

        @Override
        protected void onPostExecute(final String result)
        {
            //TODO Auto-generated method stub
            super.onPostExecute(result);
            mHandler.post(new Runnable() {
                @Override
                public void run(){
                    tvFirstName.setText(result);
                }
            });
        }

    }
}

2 个答案:

答案 0 :(得分:0)

感谢大家的支持。最后我们找到了答案。问题出在ksoap2-android-2.5.2.jar文件中。 之前我们将该文件粘贴到lib文件夹中,右键单击并从菜单中选择设置为库。这对于模拟器工作正常但在使用真实设备时崩溃。 然后我们从lib文件夹中删除了jar文件,并将它们添加到gradle中。

知识库{             maven {url&#39; https://oss.sonatype.org/content/repositories/ksoap2-android-releases/&#39; }         }

作为构建类型和

编译&com; google.code.ksoap2-android:ksoap2-android:3.6.1&#39;

作为依赖。现在它工作正常。

答案 1 :(得分:0)

buildTypes {

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
    }
    repositories {
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
    }
}

}

依赖项{

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})


compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.1'
testCompile 'junit:junit:4.12'

}