Not able to test cordova android app in device attached via USB?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 12:25:10

问题


The app is running fine on virtual device AVD nexus5. But when I am trying to test my corova android app I am getting error. I am using Android Studio 1.3. I have create the app using cordova CLI and then imported in Android Studio. Also my device -Mi4i is running Android 5.0 (Does this makes any difference?)

Compile SDK version: API 22 (5.1, Lollipop) Build Tools version: 22.0.1

The errors in logcat are:
a) E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
b) E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)

When inspected using chrome developer tools, this error is shown:
Failed to load resource: net::ERR_ADDRESS_UNREACHABLE http://10.0.2.2/s/state?callback=jQuery213013105976837687194_1442380968984&_=1442380968985


回答1:


Now, I am able to test/run my app in the device connected with USB. I am writing the important points!
First of all, make sure you are connected with the mobile with 'Connected as Camera (PTP)' option and not 'Media Device(MTP)'.

Also, I uninstalled my app that I got installed earlier from the mobile!

Next I changed the 'versions' info of my application from 'Android Studio'. Here's how I did it:
1) Open 'app' in Android Studio
2) Open 'Project Structure' dialog box (File menu -> project structure)


Fig. 1

  • On left panel of dialog box, under Modules heading, select ‘android’ module.
    Next on Properties Tab
    Changed ‘Compile Sdk Version’ to API 21
    Changed ‘Build Tools Version’ to 21.1.2
    Source Compatibility to 1.7
    Target Compatibility to 1.7

  • Next click Flavors tab


    Select Min Sdk Version to API15 ( Though as of now, Min Sdk version is API14)
    Select 'Target Sdk Version' to API 21

  • Next select 'CordovaLib' module (left pane of Project Structure) and repeated the above steps of changing the version info!

    And lastly, Changed the server Url (accessed in app) from ‘http://10.0.2.2’ to ‘http://54.xx.xx.xx’ i.e. url of remote server!
    When trying to access ‘http://10.0.2.2’ I was getting error “net::ERR_NAME_NOT_RESOLVED”.
    But on remote server my app was running without errors! Make sure you are connected with internet.



    来源:https://stackoverflow.com/questions/32601116/not-able-to-test-cordova-android-app-in-device-attached-via-usb

  • 标签
    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!