[英]Android Material and appcompat Manifest merger failed in react-native or ExpoKit
我將 'android.support:appcompat-v7' 更新為28.0.0
。
但它帶來了構建錯誤。
Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:8:5-23:19 to override.
然后我在我的 Logcat 中收到此錯誤:
清單合並失敗
我的 app.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:design:28.0.0'
resolutionStrategy.force "com.android.support:support-v4:28.0.0"
resolutionStrategy.force "com.android.support:support-media-compat:28.0.0"
}
...
dependencies {
implementation 'com.android.support:multidex:1.0.1'
// Our dependencies
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
我如何解決它?
我需要你的解決方案。
先感謝您。
將'react-native-device-info'
升級到version 2.1.2
為我修復了錯誤。 見github.com/facebook/react-native/issues/25294#issuecomment-503024749
簡而言之:庫使用了"services-gcm:+"
作為依賴,最新的gcm版本導致了這個問題。
根本原因是遷移到Androidx
相關,google play 服務更新到 androidX 感謝MR03web這個問題屬於 react-native-device-info? 最好的選擇是使用升級react-native-device-info
yarn upgrade react-native-device-info@2.1.2
cd android && gradlew clean
react-native run-android
或者如果你不想升級,你應該像這樣從react-native-device-info
排除com.google.android.gms
。 謝謝
implementation(project(":react-native-device-info"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-gcm:16.0.0"
將以下內容添加到您的 gradle.properties 然后清理/重建
googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0
我通過參考@MehulSolanki 答案通過搜索找到了解決方案。
我加
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
在我的AndroidManifest.xml
並更新 com.android.tools.build:gradl:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
並將其添加到您的 gradle.properties 文件中
android.useAndroidX=true
android.enableJetifier=true
錯誤:[TAG] 無法解析變量“${animal.sniffer.version}”
錯誤:[TAG] 無法解析變量“${junit.version}”
如果出現上述錯誤
錯誤:包 android.support.annotation 不存在錯誤:找不到符號類 Nullable
如果出現上述錯誤
添加implementation 'androidx.annotation:annotation:1.1.0'
更改import android.support.annotation.Nullable;
=> androidx.annotation.Nullable;
更改import android.support.annotation.NonNull;
=> androidx.annotation.NonNull;
編譯版本和目標版本應該是28。
在<application>
標簽內的AndroidManifest.xml
添加'tools:replace="android:appComponentFactory"'
你的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>
降級 Google Play 服務版本。 在android/app/build.gradle
更改
compile 'com.google.android.gms:play-services-<service_name>:+'
到
compile 'com.google.android.gms:play-services-<service_name>:16.0.0'
所以在我的情況下< sevice_name >是location
。 但在其他情況下,它可能是任何其他 Google Play 服務(如http://www.androiddocs.com/google/play-services/setup.html中的列表)。
在這個問題上花了一整天之后。 最后,我已經解決了這個問題。
我從 react-native-device-info 和 react-native-fast-image 庫中得到了那個錯誤。 我只是從 package.json 文件中刪除該庫,然后安裝
"react-native-device-info": "^2.1.2", "react-native-fast-image": "^6.0.3"這個最新版本
我使用了以下 gradle 版本
classpath 'com.android.tools.build:gradle:3.3.1'
我使用了以下屬性版本
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
我使用過以下版本
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
根據@Frank 的回答,庫使用services-gcm:+
作為依賴項,最新的 gcm 版本導致了這個問題。
我在我的項目中使用了:react-native-admob
。 所以我只是在android/app/build.gradle
更改以下幾行
從:
implementation project(':react-native-admob')
到 :
implementation(project(":react-native-admob"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"
這個答案應該可以幫助大多數人。 如果它仍然沒有那么解決這個問題的方法(不是那么好)是你在android studio中打開android項目。 那應該獲取所有的gradle文件。 在右側,視圖應該是 android。
從這里開始,只需在 google play 服務或 firebase 服務或任何此類庫之前檢查每個 gradle 構建文件是否有+號。 這在這個答案中也有解釋。
之后,您可以按照上面的答案中的說明進行更改。 像這樣。
implementation(project(":react-native-admob"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"
或者,如果庫正在使用一個變量,或者作為最后的手段更改它本身,則您提供一個變量。
我把它放在這里的原因是,任何對這個突然突然出現的錯誤感到厭煩的新手都可以有效地解決它,而不是……死。 哈哈。
我遇到了同樣的問題,只需升級react-native-device-info
並運行以下命令
npm upgrade react-native-device-info@latest
react-native run-android
將react-native-device-info
升級到版本 2.1.2 修復我的問題
如果你沒有使用react-native-device-info
,但有同樣的錯誤,它可能是你項目中的另一個庫。
使用它來查找有問題的庫:
cd your-react-native-project/android
./gradlew app:dependencies > deps.txt
然后檢查 deps.txt 文件中的關鍵字“androidx”。 然后你可以快速找到哪個原生模塊正在使用它。
就我而言,它是react-native-camera
,上面的解決方案很好但還不夠,所以我不得不將它添加到 local.properties 中:
firebaseVersion=17.6.0
googlePlayServicesVersion=16.1.0
googlePlayServicesVisionVersion=16.2.0
編輯:在這些修復之后,運行./gradlew app:dependencies > deps.txt
並搜索“androidx”沒有返回任何結果 - 這就是我們正在尋找的。
在項目上運行干凈后,構建工作。
谷歌播放服務重大變化。 請參閱發行說明。
解決此問題的簡單方法就是更改 Google Play 服務的版本。
將所有com.google.android.gms:play-services-*
依賴項更改為版本 16
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.