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

Expo裸项目配置Android Flavor后安装dev版本报错求助

问题解决:Expo Android多包名构建后提示找不到开发构建

问题现象

配置Expo项目在Android上使用com.myapp(生产)和com.myapp.dev(开发)两个包名,执行构建命令后设备上成功安装了myapp-dev,但出现报错:

BUILD SUCCESSFUL in 4s
367 actionable tasks: 28 executed, 339 up-to-date
CommandError: No development build (com.myapp) for this project is installed. Please make and install a development build on the device first.

已做配置

1. android/app/build.gradle 配置

flavorDimensions "env"
productFlavors {
    development {
        dimension "env"
        applicationId "com.myapp.dev"
    }
    production {
        dimension "env"
        applicationId "com.myapp"
    }
}

2. android/app/src/development/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.INTERNET"/>
  <!-- OPTIONAL PERMISSIONS, REMOVE WHATEVER YOU DO NOT NEED -->
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <!-- These require runtime permissions on M -->
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <!-- END OPTIONAL PERMISSIONS -->

  <queries>
    <!-- Support checking for http(s) links via the Linking API -->
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" />
    </intent>
  </queries>

  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.myapp.dev" />
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
  </application>
</manifest>

3. android/app/src/development/res/values/strings.xml

<resources>
    <string name="app_name">MyApp-Dev</string>
</resources>

4. app.config.js 配置

const isDev = process.env.APP_ENV === "development";

console.log(`Running in ${isDev ? "development" : "production"} env`);

export default {
  name: isDev ? "MyApp (Dev)" : "MyApp",
  slug: isDev ? "myapp-dev" : "myapp",
  version: "0.0.1",
  ios: {
    bundleIdentifier: isDev ? "com.myapp.dev" : "com.myapp",
  },
  android: {
    package: isDev ? "com.myapp.dev" : "com.myapp",
  },
  extra: {
    env: isDev ? "development" : "production",
  },
};

构建命令

"android:dev": "APP_ENV=development expo run:android --variant developmentRelease --no-build-cache"

问题原因及解决方案

1. 变体类型错误:Release构建不是开发构建

报错提示需要development build(开发构建),但你使用的是developmentRelease变体——这是生产环境的Release构建,不包含开发服务器连接所需的调试组件。

解决方法:将构建命令中的变体改为developmentDebug:

"android:dev": "APP_ENV=development expo run:android --variant developmentDebug --no-build-cache"

2. Expo未匹配到正确的包名

即使安装了com.myapp.dev的构建,Expo可能仍在尝试寻找默认的com.myapp包名。可以通过以下两种方式解决:

  • 方式一:命令行指定包名
    在构建命令中添加--package com.myapp.dev参数,明确告诉Expo要连接的包:
    "android:dev": "APP_ENV=development expo run:android --variant developmentDebug --package com.myapp.dev --no-build-cache"
    
  • 方式二:确保环境变量正确传递
    确保构建时APP_ENV=development环境变量正确生效,让Expo读取到并生成对应包名的配置:
    "android:dev": "export APP_ENV=development && expo run:android --variant developmentDebug --no-build-cache"
    

3. 验证gradle配置

确保productFlavors中的applicationId与app.config.js的android.package完全对应,避免拼写错误。同时确认flavorDimensions设置正确,没有其他冲突的gradle配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 18:44:58