question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android REST call not working in emulator

See original GitHub issue

OK, I have tried for days and I am now crying uncle. I cannot get the Android build of my Capacitor app to make a REST call from the device emulator in Android Studio. The same code works fine in a browser (ionic serve), in iOS using a device and the simulator, but not in the Android emulator. Instead it does nothing and just returns a response code of 0.

I am on a Mac, using the latest Capacitor beta (as of July 1st), and the latest Android Studio (3.1.3). I am using API 26 on a Nexus 6.

I am trying to hit a REST call running in AWS that I wrote. It is HTTP and has no security right now since I am in development.

I run Burp Suite on my machine as a proxy and set the proxy for Safari and I see all the requests and responses. I set the proxy on the Android emulator and Burp shows no traffic at all. The same holds true for the Android Profiler. There is some initial network traffic when the app starts up, but never when I make the REST call.

Here’s the call:

  login(loginRequest): Observable<AuthenticationResponse> {
    console.log('in login');
    localStorage.clear();
    return this.http.put<AuthenticationResponse>(this.rest.getApiUrl() + '/v1/consumers/login', loginRequest,
      { headers: this.requestHeaders })
      .map(user => {
        // login successful if there's a jwt token in the response
        if (user && user.token) {
          localStorage.setItem('currentUser', user.token);
          localStorage.setItem('userId', user.user.toLocaleString());
        }
        return user;
      }
      ).do(user => {
        this.push.initPushNotification(user.user);
      });
  }

I am using the default setup for Android and it appears that all the Internet and network permissions are there in the AndroidManifest.xml file:

    <!-- Permissions -->

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Camera, Photos -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- Geolocation API -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <!-- Network API -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I have never used Android Studio or the Android emulator so I may be missing some setting.

Thanks, Steve

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
suppadeliuxcommented, Nov 7, 2020

These solutions didnt work for me. My code works on the browser, I can see the data from my API, but the data is never shown in the android emulator. I hope somebody has the solution!

9reactions
micahosbornecommented, Oct 13, 2020

This did not solve the problem for me, i’m still having the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webservice call from android device is not working,works well ...
It was working well at that time.Yesterday I tried to run it on a real device and I found that it was not...
Read more >
Troubleshoot known issues with Android Emulator
This page lists known issues, workarounds, and troubleshooting tips for the Android Emulator. If you encounter an issue not listed here or ...
Read more >
Android Emulator Localhost Restful Api - YouTube
Android emulator restful api, connection closed problem solved.Buy me a coffeehttps://www.buymeacoffee.com/dbestech/e/79321.
Read more >
Android Emulator is Not Able to Access the Internet
Nowadays, almost all android applications require Internet access. The problem arises when the emulator is unable to access the Internet and ...
Read more >
Connect your app to the Authentication Emulator - Firebase
For security reasons, the Authentication emulator issues unsigned ID tokens, which are only accepted by other Firebase emulators, or the Firebase Admin SDK ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found