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

React Native Android报错:app:processDebugResources FAILED 原因及解决方法

问题原因与解决方案

Hey there! Let's break down why this AAPT error is happening and how to fix it right away.

报错原因

Android's AAPT (Android Asset Packaging Tool) has strict rules for naming package names and component attributes like android:name. The core issue here is that hyphens (-) are not allowed in these values—they violate Java's identifier naming conventions, which only permit letters, numbers, underscores (_), and require package names to follow reverse domain notation (e.g., com.yourcompany.yourapp).

When you build your React Native app, the merged debug manifest (the one in the intermediates folder) inherits these invalid hyphenated values from your main AndroidManifest.xml or third-party dependencies, triggering the errors you see.

解决步骤

Follow these steps to eliminate the invalid characters:

  1. Fix your main AndroidManifest.xml
    Open android/app/src/main/AndroidManifest.xml:

    • Locate the root <manifest> tag's package attribute, replace any hyphens with underscores:
      <!-- Before -->
      <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my-app">
      <!-- After -->
      <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my_app">
      
    • Check all component tags (like <activity>, <service>, <receiver>) for their android:name attributes and replace hyphens there too:
      <!-- Before -->
      <activity android:name="com.my-app.MainActivity">
      <!-- After -->
      <activity android:name="com.my_app.MainActivity">
      
  2. Sync your build.gradle configuration
    Open android/app/build.gradle and update the applicationId to match your modified package name:

    defaultConfig {
        applicationId "com.my_app" // Must match the fixed package name
        // ... other existing configs
    }
    
  3. Update Java/Kotlin source files
    If you have Java/Kotlin files (like MainApplication.java or MainActivity.java), update the package declaration at the top of the file:

    // Before
    package com.my-app;
    // After
    package com.my_app;
    

    Also, double-check any references to component names in these files to ensure they use the updated underscore format.

  4. Clean build cache
    Old build artifacts might still hold the invalid manifest data, so clean them up before rebuilding:

    cd android
    ./gradlew clean
    cd ..
    react-native run-android
    

特殊情况:第三方依赖引发的问题

If the invalid hyphens come from a third-party library's manifest, you can override the problematic attributes in your own AndroidManifest.xml using manifest merging. For example, if a library has a service with an invalid name, add this to your manifest:

<service
    android:name="com.invalid-lib-name.MyService"
    tools:replace="android:name"
    android:name="com.invalid_lib_name.MyService" />

(Note: You'll need to add xmlns:tools="http://schemas.android.com/tools" to your root <manifest> tag to use the tools:replace attribute.)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:55:41