React-Native Android构建失败:执行任务“:app:processDebugResources”失败。无法处理资源。

3

我无法弄清楚构建有什么问题。我尝试了运行./gradlew clean和将android.enableAapt2=false添加到gradle.properties的常见解决方案。

google-services.json文件夹位于/android/app级别。

目前我不知道如何解决这个问题。

如果我忘记包含一些有用的内容,请告诉我,我会进行更新。

谢谢。

错误输出:

配置项目 :app 警告:指定的 Android SDK Build Tools 版本(26.0.1)被忽略,因为它低于 Android Gradle Plugin 3.1.3 的最低支持版本(27.0.3)。 将使用 Android SDK Build Tools 27.0.3。 要消除此警告,请从 build.gradle 文件中删除 "buildToolsVersion '26.0.1'",因为每个 Android Gradle 插件版本现在都有一个默认的构建工具版本。 在 [src/nullnull/debug、src/debug/nullnull、src/nullnull、src/debug、src/nullnullDebug] 中查找 google-services.json 失败。 registerResGeneratingTask 已弃用,请改用 registerGeneratedResFolders(FileCollection)。 在 [src/nullnull/release、src/release/nullnull、src/nullnull、src/release、src/nullnullRelease] 中查找 google-services.json 失败。 registerResGeneratingTask 已弃用,请改用 registerGeneratedResFolders(FileCollection)。
配置项目 :react-native-google-analytics-bridge 警告:Configuration 'compile' 已过时并已被 'implementation' 和 'api' 替换。 它将在 2018 年底之前被移除。更多信息请参见:http://d.android.com/r/tools/update-dependency-configurations.html 配置项目 :react-native-radar 警告:Configuration 'compile' 已过时并已被 'implementation' 和 'api' 替换。 它将在 2018 年底之前被移除。更多信息请参见:http://d.android.com/r/tools/update-dependency-configurations.html 任务 :app:processDebugGoogleServices 解析 json 文件:/Users/kyletreman/18F/courier_test_app/android/app/google-services.json
/Users/kyletreman/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/64df69838d7c555de168bdcf18f3be5c/res/values/values.xml:113:5-69: AAPT: 错误: 找不到资源 android:attr/fontVariationSettings。
/Users/kyletreman/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/64df69838d7c555de168bdcf18f3be5c/res/values/values.xml:113:5-69: AAPT: 错误: 找不到资源 android:attr/ttcIndex。
错误: 链接引用失败。
构建失败。
原因: 执行任务 ':app:processDebugResources' 失败。 处理资源失败,请参阅上面的 aapt 输出以获取详细信息。
尝试: 运行带有 --stacktrace 选项以获取堆栈跟踪。 运行带有 --info 或 --debug 选项以获取更多日志输出。 运行带有 --scan 选项以获取完整的洞察力。
获取更多帮助:https://help.gradle.org 构建失败,执行时间 2 秒。 50 个可操作任务:3 个已执行,47 个最新状态 无法在设备上安装应用程序,请阅读上面的错误以获取详细信息。 请确保您有一个运行中的 Android 模拟器或连接了设备,并已设置好 Android 开发环境:https://facebook.github.io/react-native/docs/getting-started.html

/android/app/build.gradle

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
    applicationId "com.courier_test_app.app"
    minSdkVersion 16
    targetSdkVersion 27
    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 {
implementation(project(':react-native-firebase')) {
    transitive = false
}
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'com.android.support:support-v13:27.1.1'
implementation "com.facebook.react:react-native:+"  // From node_modules
implementation project(':react-native-radar')
implementation project(':react-native-google-analytics-bridge')
}

// 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'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

/android/build.gradle

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.google.gms:google-services:4.0.0'
    classpath 'com.android.tools.build:gradle:3.1.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    mavenLocal()
    google()
    jcenter()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
}
}

configurations.all {
resolutionStrategy {
    force 'com.android.support:support-v4:27.1.0'
}
}
3个回答

1
从错误日志中我可以看到仍在使用appcompat-v7-23.0.1,因此更新resolutionStrategy可能会有所帮助。
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
        force 'com.android.support:appcompat-v7-23.0.1'
    }
}

同时,您需要将该分辨率策略块放置在您的 app/build.gradle 中。

0

已修复

我得到了一个熟悉本地代码的人的帮助,他帮我解决了很多错误。

  • 实现顺序很重要,这是对我有效的顺序

    implementation "com.facebook.react:react-native:+"  // 来自 node_modules
    implementation "com.android.support:support-v4:27.1.1"
    implementation 'com.android.support:support-v13:27.1.1'
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation(project(':react-native-firebase'))
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation project(':react-native-radar')
    implementation project(':react-native-google-analytics-bridge')
    
  • 我需要将配置解析策略移动到 android/app/build.gradle 文件中,我的配置在错误的级别上。我还必须更改支持和 appcompat 包的版本。您可以通过以下方式找到依赖项

    ./gradlew app:dependencies 
    

    从 android 文件夹中。问题是其中一个依赖项正在拉取旧版本,通过在 resolutionStrategies 中使用以下内容进行修复。

    force 'com.android.support:appcompat-v7:27.1.1'
    
  • 需要进行的下一个更改是 MainApplication.java 中的以下行

       return BuildConfig.DEBUG;
    

    变成这样

       return <app_name>.BuildConfig.DEBUG;
    
  • 我还删除了 enableaapt2=false

我能给的最后一个建议是,命名很重要,除非绝对必要,请勿重命名您的应用程序,并确保其在主Java文件和AndroidMainfest.xml中进行更改。

已更新

  • 我发现我的调试器无法连接,因为我删除了一些支持 Firebase 的实现包,将它们添加回来后问题得到解决。请在 Firebase 实现下面添加以下内容。

    implementation "com.google.android.gms:play-services-base:15.0.1"
    implementation "com.google.firebase:firebase-core:16.0.1"
    

0
将以下代码放在 android/build.gradle 文件的末尾 使用您自己的数字替换 compileSdkVersionbuildToolsVersion
subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion "27.0.2"
            }
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接