You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Expo模块迁移后Android应用启动失败:expo.modules包不存在问题求助

Android: "error: package expo.modules does not exist" after migrating from react-native-unimodules to Expo Modules

Hey there, let's dig into this Android build error you're hitting after migrating to Expo Modules. I've seen similar issues when the Expo Modules setup isn't fully wired up on the Android side—even if you followed the docs step-by-step. Let's go through the most common fixes one by one:


1. Double-check your Gradle configuration

First, make sure your Android Gradle files have all the required Expo Modules setup:

  • Project root build.gradle: Confirm you've added the Expo Maven repo and the Expo Gradle plugin classpath:
    buildscript {
      repositories {
        // ... existing repos (Google, Maven Central, etc.)
        maven { url 'https://maven.expo.dev' }
      }
      dependencies {
        // ... existing dependencies
        classpath 'expo:expo-gradle-plugin:^X.X.X' // Use the version matching your expo package
      }
    }
    
    allprojects {
      repositories {
        // ... existing repos
        maven { url 'https://maven.expo.dev' }
      }
    }
    
  • App module build.gradle: Ensure you're applying the Expo plugin and meeting the minimum SDK requirement:
    apply plugin: 'com.android.application'
    apply plugin: 'expo' // This line is critical for Expo Modules to work
    
    android {
      defaultConfig {
        minSdkVersion 21 // Expo Modules require this minimum SDK version
        // ... other configs
      }
      // ... other Android settings
    }
    
  • Also, confirm expo-modules-core is listed in your app's dependencies:
    dependencies {
      // ... existing dependencies
      implementation 'expo:expo-modules-core:^X.X.X' // Match the version of your expo package
    }
    

2. Fix your MainApplication.java setup

Looking at your code, I spotted a key issue:

  • You're adding ApplicationLifecycleDispatcher to the packages list—this is incorrect. ApplicationLifecycleDispatcher is not a ReactPackage, so adding it here will break things. Remove this line:
    packages.add(new ApplicationLifecycleDispatcher());
    
  • The ReactNativeHostWrapper you're using should handle module registry setup automatically, so your existing commented-out unimodules code is correctly disabled. Just make sure no leftover unimodules imports are active that could cause conflicts.

3. Clean and rebuild your Android project

Cached build files often cause weird, unexplained errors. Run these commands to wipe all cached data and start fresh:

cd android
./gradlew clean
rm -rf .gradle
rm -rf app/build
cd ..
npx react-native start --reset-cache
npx react-native run-android

4. Verify Expo package version compatibility

Mismatched versions between expo, expo-modules-core, and expo-gradle-plugin are a common culprit. Run this to check your versions:

npm list expo
# or for yarn:
yarn list expo

Ensure all Expo-related packages are on the same major version (e.g., all v49.x.x if you're using Expo 49).

5. Trigger manual auto-linking (if needed)

Expo Modules rely on auto-linking, but sometimes you need to force it to run. If you haven't already, run:

npx react-native link

If you still have issues, try running the Expo prebuild command (even though you ejected, this can fix missing configs):

npx expo prebuild --platform android

6. Confirm the expo package is installed

Make sure you have the core expo package in your project dependencies. If not, install it:

npm install expo
# or
yarn add expo

Let me know if any of these steps resolve your "package expo.modules does not exist" error. If not, we can dive deeper into your Gradle files or check for other dependency conflicts!

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

火山引擎 最新活动