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.

Network error on android signed apk

See original GitHub issue

Intended outcome:

The queries should be executed as expected, without raising network errors.

Actual outcome:

There are happening network errors when executing the queries, even with a valid network connection.

How to reproduce the issue:

  • Setup apollo on an RN app, with the following config:
import {
  ApolloLink,
  ApolloClient,
  InMemoryCache,
  createHttpLink,
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { buildSentryErrorLink } from "apollo-sentry-helper";

import getApiUri from "./getApiUri";

import { getUserJWT } from "~/utils/getUserJWT";

export const API_URI = getApiUri();

const httpLink = createHttpLink({ uri: API_URI });

const authLink = setContext(async (_req, { headers }) => {
  const token = await getUserJWT();

  return {
    ...headers,
    headers: {
      authorization: token ? `Bearer ${token}` : null,
    },
  };
});

const sentryErrorLink = buildSentryErrorLink();

const link = ApolloLink.from([
  sentryErrorLink,
  authLink,
  httpLink,
]);

const cache = new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        viewer: {
          merge: (existing, incoming, opts) => (
            opts.mergeObjects(existing, incoming)
          ),
        },
      },
    },
  },
});

const apolloClient = new ApolloClient({
  cache,
  link,
});

export default apolloClient;
  • Executes a query on an Android signed apk

Versions System: OS: macOS 10.15.6 Binaries: Node: 12.16.3 - ~/.nvm/versions/node/v12.16.3/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.4 - ~/.nvm/versions/node/v12.16.3/bin/npm Browsers: Chrome: 85.0.4183.121 Safari: 14.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
johnneulandcommented, Oct 6, 2020

I am getting the same error. All my queries work well in iOS but give me a network request failed error in Android. Some other SO and GitHub solutions suggested that I shouldn’t be using localhost for my uri and should use my computer’s IP address. But I am already not using localhost.

const httpLink = createHttpLink({
    uri: 'https://gateway_dev.companyName.en/v1/graphql',
  });

  const authLink = setContext(async (_, { headers }) => {
    const token = await auth().currentUser?.getIdToken();
    return {
      headers: {
        ...headers,
        authorization: token ? `Bearer ${token}` : '',
      },
    };
  });

  const client = new ApolloClient({
    link: authLink.concat(httpLink),
    cache: new InMemoryCache({}),
  });

  return (
    <Provider store={store}>
        <ApolloProvider client={client}>
...

The uri I am using is the Graphql Endpoint POST url from my Hasura console. I am testing by using an Android emulator from the Android Studio and not on a real device. What else could I try?

I also tried adding this android:usesCleartextTraffic="true" to AndroidManifest.xml file but it doesn’t make a difference.

2reactions
gabrielpra1commented, Oct 5, 2020

I’m also having the same problem. The error happens randomly, something the queries fail and sometimes they don’t. It seems that it is more likely to happen in the first query that is executed right after opening the app.

Also important to note that we’re using HTTPS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Signed android apk - network problem - Stack Overflow
I have signed my app using netbeans and exported it, uploaded to android market, all fine. On install of the app, it tells...
Read more >
NetworkException | Android Developers
Error code indicating the device was not connected to any network. Constant Value: 2. public static final int ERROR_NETWORK_CHANGED.
Read more >
How To Fix APKPure App Network Connection Error Android
APKPure # NetworkError # Android #InternetError ... To Fix APKPure App Network Connection Error Android - Fix APKPure App Internet Connection.
Read more >
How To Fix APKPure App Network Connection Error Android ...
APKPure # NetworkError #InternetError #Internet #Network #ConnectionerrorFix APKPure Network / Internet Connection Problem in Android & Ios ...
Read more >
Resolving Network Error in Android app development - QED42
If you access the API over HTTPS with a domain name and receive a “Network Error”. Try checking the access logs and error...
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