我想我一定在这里遗漏了一些东西,据我所知,我在阅读了许多文章后尝试了这些方法,但我似乎无法让事情正常进行。我目前正在手动触发这些构建,使用 detox 将使用的命令 ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug
虽然我也尝试过使用 npx detox build --configuration android.emu.debug
也直接。
我的错误是典型的 minSdkVersion 不匹配:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [com.facebook.react:react-native:0.64.0] /home/iw651/.gradle/caches/transforms-2/files-2.1/354c8f3d479b5a1203bfff874da058bc/jetified-react-native-0.64.0/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.facebook.react" to force usage (may lead to runtime failures)
build.gradle 所以让我有些困惑的事情首先是我的项目的
minSdkVersion
设置为至少 21... 这是我的 /android/build.gradle
的顶部文件:buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 23
compileSdkVersion = 29
targetSdkVersion = 29
kotlinVersion = '1.3.61'
ndkVersion = "20.1.5948944"
}
在我的android/app/build.gradle
我有以下内容:defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
...
}
所以我真的相信以下事情已经完成。但它显然仍然抛出错误。or increase this project's minSdk version to at least 2
工具:覆盖库
我不完全确定如何执行此操作,我已尝试在我的
/android/app/src/debug/AndroidManifest.xml
中进行设置文件。我尝试了一些排列:<uses-sdk minSdkVersion="16" tools:overrideLibrary="com.facebook.react"/>
<uses-sdk minSdkVersion="21" tools:overrideLibrary="com.facebook.react"/>
<uses-sdk tools:overrideLibrary="com.facebook.react"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk minSdkVersion="16" tools:overrideLibrary="com.facebook.react"/>
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
这些排列似乎也无济于事。使用 minSdk 最多为 16 的兼容库
这只是给我留下了这个选项,为此我将针对相关软件包提出 PR。但在发布新版本之前,它仍然无法帮助我构建。
谁能看到我错过了什么?或者在构建之间可能会有一些缓存阻碍?
最佳答案
问题是 RN 0.64 增加了它的 minSdkVersion
从 16 到 21。许多 RN 库都有 minSdkVersion
硬编码为 16,即 causing Detox Android builds to fail .
我不确定为什么常规的 Android 构建成功而 Detox 构建失败,但解决方法是编辑库的 android/build.gradle
和 change it to read minSdkVersion
from the root project :
minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16
理想情况下,这将通过 PR 在核心库中修复(不要忘记制作一个)。同时,您可以自己 fork 项目,修复错误并通过在 package.json
中引用修复的项目来使用它。 :"<lib-name>": "github:<username>/<lib-name>"
或者,您可以使用 patch-package将修复应用于 node_modules/<libname>/android/build.gradle
运行时npm install
.这似乎是 RN 库中很常见的错误。在我们的中型 RN 项目中,我不得不修补三个库,包括 react-native-webview .
关于android - 由于 minSdkVersion 正在努力让 Android 构建工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67021833/