Gradle 编译失败(检索项目的父级时出错)



在我的 React Native 项目中,Gradle 构建给了我这个错误:

> Task :app:processDebugGoogleServices
Parsing json file: /Users/valentinmourot/ODE/Dev/mobile-app/android/app/google-services.json
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/234563a256b75883624274d32dc30b63/res/values-v24/values-v24.xml:3:5-157: AAPT
: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/234563a256b75883624274d32dc30b63/res/values-v24/values-v24.xml:4:5-135: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/234563a256b75883624274d32dc30b63/res/values-v26/values-v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.

一些线程说这是由于build.gradle文件中的错误配置。这是我的:

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "-----------"
minSdkVersion 19
targetSdkVersion 23
versionCode 8
versionName "0.0.8"
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-view-overflow')
compile(project(':react-native-firebase')) {
transitive = false
}
compile "com.google.android.gms:play-services-base:15.0.0"
compile "com.google.firebase:firebase-core:15.0.2"
compile project(':react-native-i18n')
compile project(':react-native-vector-icons')
compile project(':react-native-fs')
compile project(':react-native-image-to-base64')
compile project(':rn-fetch-blob')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.3"
compile "com.facebook.react:react-native:+"
compile project(':react-native-smart-splash-screen')
compile project(':react-native-cookies')
compile "com.google.firebase:firebase-analytics:15.0.2"
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true
}
compile "com.google.firebase:firebase-perf:15.1.0"
compile "com.google.firebase:firebase-messaging:15.0.2"
compile project(':react-native-image-picker')
compile project(':react-native-mixpanel')
}
// 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 from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply plugin: 'com.google.gms.google-services'

错误似乎与谷歌服务(Firebase?(有关。我不知道为什么在这里使用appcompat-v7-27.1.1。 更新 Android Studio 后引发的错误。

这是我的 React 原生环境:

React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 59.94 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.9.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 23.0.1, 26.0.2, 27.0.3
API Levels: 23, 25, 26, 27
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
@types/react: 16.4.14 => 16.4.14
@types/react-native: 0.57.1 => 0.57.1
react: 16.5.0 => 16.5.0
react-native: 0.57.1 => 0.57.1
npmGlobalPackages:
react-native-cli: 2.0.1

感谢您的帮助! :)

后记:

有时错误是不同的(似乎来自 react-native-i18n(:

> Task :react-native-i18n:compileDebugJavaWithJavac
Note: /Users/valentinmourot/ODE/Dev/mobile-app/node_modules/react-native-i18n/android/
src/main/java/com/AlexanderZaytsev/RNI18n/RNI18nModule.java uses or overrides a deprec
ated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/b8
5fe69b67b83a703766c9386b9fdeb8/res/values-v24/values-v24.xml:3:5-157: AAPT: Error retr
ieving parent for item: No resource found that matches the given name 'android:TextApp
earance.Material.Widget.Button.Borderless.Colored'.
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/b85fe69b67b83a703766c9386b9fdeb8/res/values-v24/values-v24.xml:4:5-135: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/Users/valentinmourot/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/b85fe69b67b83a703766c9386b9fdeb8/res/values-v26/values-v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'

。有时是另一个 :> Task :react-native-cookies:compileDebugJavaWithJavac相同的消息。

您是否尝试过在android/目录中运行gradlew clean

有时我会收到此错误并执行此操作可以修复它,尽管我不知道是什么原因造成的。

您可以尝试添加构建工具版本吗?

构建工具版本"23.X.X">

更新为:

api "com.android.support:appcompat-v7:28.0.0"

虽然还有更多过时的版本。

最新更新