简单记录
由于工程targetSdkVersion升级到28之后,并且compileSdkVersion 也使用28之后就会出现上述报错。这是由于一些第三方库没有做及时的兼容。很多React Native工程第三库都会报这个错误。如下所示
<pre class="console-output" style="box-sizing: border-box; white-space: pre-wrap; word-wrap: break-word; margin: 0px; position: relative; font-size: 14px; background: rgb(38, 50, 56); color: rgb(233, 237, 237); cursor: text; font-family: "Roboto Mono", monospace !important; padding: 10px 20px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':lottie-react-native:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/lottie-react-native/src/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/lottie-react-native/src/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/lottie-react-native/src/android/build/intermediates/res/merged/release/values/values.xml:2602: error: resource android:attr/fontVariationSettings not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/lottie-react-native/src/android/build/intermediates/res/merged/release/values/values.xml:2603: error: resource android:attr/ttcIndex not found.
error: failed linking references.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':react-native-fs:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/react-native-fs/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/react-native-fs/android/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/react-native-fs/android/build/intermediates/res/merged/release/values/values.xml:2714: error: resource android:attr/fontVariationSettings not found.
/Users/jinwenwu/.jenkins/workspace/_feature_INS_APP_DV_2019.11-ULZZDDRITLP453WEMM3EK6BSLW3Q3OCKQGKLLPOKJBCMRR5F2YLA/node_modules/react-native-fs/android/build/intermediates/res/merged/release/values/values.xml:2715: error: resource android:attr/ttcIndex not found.
error: failed linking references.
* 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](https://help.gradle.org/)</pre>
解决方法
既然知道了是由于编译问题导致的Bug,那么我们强制修改第三库里的targetSdkVersion和compileSdkVersion 就可以了,解决方法如下,在主工程build.gradle文件中加入下段代码,望对大家有帮助!
allprojects {
repositories {
google()
mavenLocal()
............
}
subprojects {
afterEvaluate {
project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion = 28
buildToolsVersion = "28.0.3"
}
}
}
}
}