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

React-Native Android Build Failure: Execution failed for task ':app:processDebugResources'. Failed to process resources

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

google-services.json文件夹在/android/app层。

我现在不知道如何通过这个。

如果我忘了包含一些有用的东西,请 lmk,我会更新。

干杯

错误输出

Configure project :app WARNING: The specified Android SDK Build Tools version (26.0.1) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.3. Android SDK Build Tools 27.0.3 will be used. To suppress this warning, remove "buildToolsVersion '26.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools. Could not find google-services.json while looking in [src/nullnull/debug, src/debug/nullnull, src/nullnull, src/debug, src/nullnullDebug] registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) Could not find google-services.json while looking in [src/nullnull/release, src/release/nullnull, src/nullnull, src/release, src/nullnullRelease] registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

Configure project :react-native-google-analytics-bridge WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Configure project :react-native-radar WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

Task :app:processDebugGoogleServices Parsing json file: /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: error: resource android:attr/fontVariationSettings not found.

/Users/kyletreman/.gradle/caches/transforms-1/files-1.1/appcompat-v7-23.0.1.aar/64df69838d7c555de168bdcf18f3be5c/res/values/values.xml:113:5-69: AAPT: error: resource android:attr/ttcIndex not found.

error: failed linking references.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processDebugResources'. Failed to process resources, see aapt output above for details.

  • 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 2s 50 actionable tasks: 3 executed, 47 up-to-date 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/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'
}
}

固定

我得到了熟悉原生端的人的帮助,他帮助我解决了很多错误。

  • 执行顺序很重要,这是对我有用的顺序

    implementation "com.facebook.react:react-native:+"  // From 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 文件,我的级别错误。我还必须更改 support 和 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"
    

从错误日志中我可以看到 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

将此代码放在 android/build.gradle 的末尾 compileSdkVersionbuildToolsVersion

使用您自己的编号
subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion "27.0.2"
            }
        }
    }
}