【问题标题】:FAILURE: Build failed with an exception. on existing react native appFAILURE:构建失败并出现异常。在现有的反应原生应用程序上
【发布时间】:2018-06-05 01:43:48
【问题描述】:

在我的 linux 操作系统中安装期间,我遇到了 React Native 现有应用程序代码的问题。

一切都设置好了(React Native 和 Android Studio)

我在运行命令时面临的问题

这是错误信息,

:app:processDebugResources
/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:3: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.

/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:4: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.

/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.

/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.


:app:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

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

BUILD FAILED

Total time: 16.116 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
[bg] Exited with code 0

这是我的 build.gradle 文件

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"]
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.mynativeapp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile project(':react-native-splash-screen')
    compile project(':react-native-navigation')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

还有settings.gradle

rootProject.name = 'mynativeapp'

include ':app'
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')

终端错误图片

我无法知道这里到底发生了什么错误。 让我知道解决方案。

【问题讨论】:

  • 您仍然应该检查 build.gradle 是否正确 compileSdkversion 、 targetSDKversion ,然后检查版本是否支持库依赖项
  • 我如何检查这个? --> 支持库依赖的版本@Napolean
  • @Tariq 你能在 github 上发布你的代码,以便我找出问题所在吗?
  • 谢谢@amorenew 这是我的完整代码-github.com/tarifrudrapur/teletaskapp

标签: android react-native


【解决方案1】:

这是我的 2 美分。

可能的修复:

  • 将您的 buildToolsVersion 更新为 24.0.3 或更高版本。
  • 更新您的 compileSdkVersion 24 或更新到大于 24 的更新版本。
  • 还基于此更新您的 appcompat 库。即compile "com.android.support:appcompat-v7:24.0.3"

P.S:您可能需要从 SDK 管理器下载该构建工具版本。它可能无法下载。在这种情况下,您可以使用最新的buildToolsVersion

潜在问题是什么:

注意这些信息:

/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:3:AAPT:检索项目的父项时出错:找不到资源匹配给定名称“android:TextAppearance.Material.Widget.Button.Borderless.Colored”。

...

/home/akaruilabs/ReactNative/teletask/android/app/build/intermediates/res/merged/debug/values-v24/values-v24.xml:4:错误:检索项目的父项时出错:找不到资源匹配给定名称“android:TextAppearance.Material.Widget.Button.Colored”。

您正在使用buildToolsVersion "23.0.1" 和您的compileSdkVersion 作为23。但是,您有一个 values-24 文件夹。它是一个目录,其中包含将在运行您的应用的设备处于 API 级别 24 或更高级别时使用的资源。

compileSdkVersion 是编译应用所针对的 API 版本。这意味着您可以使用该 API 版本(以及所有以前的版本)中包含的 Android API 功能。如果您尝试使用 API 24 功能但将 compileSdkVersion 设置为 23,您将收到编译错误。如果您将 compileSdkVersion 设置为 24,只要您的应用的执行路径不尝试调用任何特定于 API 23 的 API,您仍然可以在 API 23 设备上运行该应用。

buildToolsVersion 指定构建项目时要使用的 SDK 构建工具的版本。只要确保它支持您正在使用的compileSdkVersion。较新版本的buildToolsVersion 支持较旧的compileSdkVersion 版本。

有用的参考资料

希望这会有所帮助。

【讨论】:

  • 设置到 api 24 后出现以下错误:app:compileDebugJavaWithJavac :app:compileDebugJavaWithJavac - 不是增量的(例如,输出已更改,之前没有执行等)。 /home/akaruilabs/ReactNative/teletaskapp/android/app/src/main/java/com/teletask/MainActivity.java:4:错误:找不到符号导入com.reactnativenavigation.RnnPackage; ^ 符号:类 RnnPackage 位置:包 com.reactnativenavigation 1 错误:app:compileDebugJavaWithJavac FAILED
  • @Tariq 你可以尝试清理项目然后重新链接react-nativa-navigation吗?检查github.com/wix/react-native-navigation/issues/1484
  • 仍然面临问题。这是我的完整代码 - github.com/tarifrudrapur/teletaskapp
【解决方案2】:

更新您的 android 项目可以部分解决问题。

但看起来react-native-navigationreact-native-vector-icons 之间存在冲突,因为react-native-navigation 依赖于react-native-vector-icons 以获得工具栏中的图标。

我想知道您是否可以先删除 react-native-vector-icons 以确保没有冲突,然后再添加它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 2018-07-28
    • 2018-10-22
    • 2018-10-29
    • 2020-06-13
    • 2021-09-24
    • 2016-05-18
    相关资源
    最近更新 更多