You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo API调用在Google Play真机上无法工作求助

Google Play AAB测试版API调用真机连接问题排查求助

我耗时数月终于在Google Play发布了AAB测试版本,该应用的API调用在iOS、Android模拟器及Postman中均运行正常,但从Google Play下载到真机后却无法连接或工作。我已检查「设置-应用-权限」,确认无需额外权限。

LOGIN_CHECK_USER是带域名的常规URL,接收name和pass两个参数,存在对应用户时返回用户详情,接口本身功能正常。以下是checkUser函数代码及app.json的Android配置,恳请协助排查问题:

checkUser函数代码

async function checkUser(name, password) {
try {
  const response = await fetch(ApiServiceUrl.LOGIN_CHECK_USER, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ ad: name, sifre: password }),
  });

  // 检查响应是否为有效JSON
  if (!response.ok) {
    Alert.alert("连接错误", `服务器错误代码: ${response.status}`);
    return; // 终止函数
  }

  const data = await response.json();

  // 检查是否为有效数据
  if (!data || !data.data || !Array.isArray(data.data.users)) {
    throw new Error('无效响应格式');
  }

  if (data.status === '0' && data.data.users.length > 0) {
    // 创建用户对象
    const newObj = new WebYetkili();
    Object.assign(newObj, data.data.users[0]);

    console.log('Web用户名:', newObj.ad);

    // 将用户数据保存到AsyncStorage
    await AsyncStorageService.saveWebUser(newObj);

    // 从AsyncStorage获取用户并跳转到菜单
    const storedUser = await AsyncStorageService.getWebUser();
    console.log('Helloooooo : ', storedUser.ad);

    gotoUserMenu(storedUser);
  } else {
    console.log('未找到用户');
    alertWebUserName();
  }
} catch (error) {
  console.error('连接错误:', error);
  Alert.alert('连接错误', '无法访问服务器。');
}
}

app.json Android配置

"android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.talebeyoklama.takip",
      "versionCode": 11,
      "permissions": ["INTERNET"],
      "usesCleartextTraffic": true

    }

排查建议

  • 检查Google Play签名影响:Google Play会对AAB重新签名,确认服务器是否有基于应用签名的白名单验证,若有需将Google Play的签名证书添加到服务器信任列表。
  • 测试不同网络环境:切换移动数据/不同WiFi,排除企业防火墙、代理对API请求的拦截。
  • 验证HTTPS证书合规性:若API使用HTTPS,确认证书是受信任的CA颁发,避免真机因不信任自签名证书导致连接失败。
  • 抓取真机调试日志:通过adb logcat或React Native远程调试,获取具体错误信息(如DNS解析失败、SSL握手异常)。
  • 检查代码混淆配置:若启用了ProGuard/R8,确保fetch、API域名及相关模型类未被混淆,避免请求逻辑被破坏。
  • 确认参数传递一致性:对比真机与模拟器中JSON.stringify后的参数格式,排查字符编码或参数名是否存在差异。

内容的提问来源于stack exchange,提问作者Samir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 07:17:05