构建失败:当我运行 npm run android 时无法安装应用程序

我正在尝试使用 reactnative 构建一个移动应用程序并在 android 模拟器上进行测试,但是当我使用 npm run android 运行应用程序时它失败了。我尝试修改 gradle.build 文件(将 sdk 版本升级到 31 ..),但没有任何效果。 npm install 完美运行,没有漏洞。
这是命令的输出:

>react-native run-android

    warn Package react-native-vector-icons has been ignored because it contains invalid configuration. Reason: "dependency.assets" is not allowed
    info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
    (node:16364) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
    (Use `node --trace-warnings ...` to show where the warning was created)
    Jetifier found 1186 file(s) to forward-jetify. Using 12 workers...
    info Starting JS server...
    info Installing the app...
    > Task :app:mergeDebugAssets FAILED

    Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
    23 actionable tasks: 23 executed
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01      
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01    
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: �l�ment inattendu (URI : "", local : "base-extension"). Les �l�ments attendus sont <{}codename>,<{}layoutlib>,<{}api-level>

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:mergeDebugAssets'.
    > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
       > Failed to transform react-native-reanimated-69-jsc.aar (project :react-native-reanimated) to match attributes {artifactType=android-assets}.
          > Execution failed for JetifyTransform: C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesreact-native-reanimatedandroidreact-native-reanimated-69-jsc.aar.
             > Transform's input file does not exist: C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesreact-native-reanimatedandroidreact-native-reanimated-69-jsc.aar. (See https://issuetracker.google.com/issues/158753935)

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    * Get more help at https://help.gradle.org

    BUILD FAILED in 8s

    error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
    Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
    Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
    Warning: �l�ment inattendu (URI : "", local : "base-extension"). Les �l�ments attendus sont <{}codename>,<{}layoutlib>,<{}api-level>

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:mergeDebugAssets'.
    > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
       > Failed to transform react-native-reanimated-69-jsc.aar (project :react-native-reanimated) to match attributes {artifactType=android-assets}.
          > Execution failed for JetifyTransform: C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesreact-native-reanimatedandroidreact-native-reanimated-69-jsc.aar.
             > Transform's input file does not exist: C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesreact-native-reanimatedandroidreact-native-reanimated-69-jsc.aar. (See https://issuetracker.google.com/issues/158753935)

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    * Get more help at https://help.gradle.org

    BUILD FAILED in 8s

        at makeError (C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesexecaindex.js:174:9)
        at C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modulesexecaindex.js:278:16
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async runOnAllDevices (C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modules@react-native-communitycli-platform-androidbuildcommandsrunAndroidrunOnAllDevices.js:109:5)
        at async Command.handleAction (C:UsersgharsOneDriveBureaureact-navigation-v6-mixnode_modules@react-native-communityclibuildindex.js:192:9)
    info Run CLI with --verbose flag for more details.
stack overflow BUILD FAILED: can't install the app when i run npm run android
原文答案

答案:

作者头像

转到您的 babel.config 并添加“插件:['react-native-reanimated/plugin']”。

你的 babel.config.js 文件应该是这样的

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
};

如果您有正确的配置以应用 react-native-vector-icons,请检查您的 android/app/build.gradle。该配置应如下所示:

project.ext.vectoricons = [
    iconFontNames: [ 'Ionicons.ttf' ] // Name of the font files you want to copy
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

尝试清理您的项目:使用以下命令。一个接一个地运行(注意,如果你使用的是 yarn,你可以改变 npm install 而是使用 yarn install)

watchman watch-del-all
rm -rf yarn.lock package-lock.json node_modules
rm -rf android/app/build
rm ios/Pods ios/Podfile.lock 
rm -rf ~/Library/Developer/Xcode/DerivedData
npm install && cd ios && pod update && cd ..
npm start -- --reset-cache

在终端中使用以下命令运行您的项目:

npx react-native run-android ... for android 

npx react-native run-ios ... for ios
作者头像

步骤 1. 在路径 'androidappsrcmainassets' 中创建一个文件夹 'fonts'。确保 'fonts' 的 'f' 很小。

步骤 2. 从“node_modulesreact-native-vector-iconsFonts”复制所有文件并将其粘贴到“androidappsrcmainassetsfonts”中。

步骤 3. 从模拟器中删除您现有的应用程序并再次运行。