由于 minSdkVersion 努力让 Android 构建工作

Ian*_*Ian 9 android react-native detox

我想我一定在这里遗漏了一些东西,据我所知,我在阅读了一些文章后尝试了这些方法,但似乎无法让事情正常工作。我目前正在手动触发这些构建,使用 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)
Run Code Online (Sandbox Code Playgroud)

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"
    }
Run Code Online (Sandbox Code Playgroud)

在我的android/app/build.gradle我有以下内容:

defaultConfig {
     minSdkVersion rootProject.ext.minSdkVersion
     targetSdkVersion rootProject.ext.targetSdkVersion
     multiDexEnabled true
     ...
}
Run Code Online (Sandbox Code Playgroud)

所以我真的相信以下已经完成。但它显然仍然抛出错误。

或将此项目的 minSdk 版本增加到至少 2

tools:overrideLibrary
我不太确定如何执行此操作,我已尝试在我的/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>
Run Code Online (Sandbox Code Playgroud)

这些排列似乎也没有帮助。

使用 minSdk 最多为 16 的兼容库
这只是让我有这个选项,为此我将针对相关包提出 PR。但是在发布新版本之前它仍然无法帮助我构建。

谁能看到我错过了什么?或者某些缓存会妨碍构建?

Sam*_*mpo 7

问题是 RN 0.64 将其minSdkVersion从 16 增加到 21。许多 RN 库minSdkVersion在 16 处进行了硬编码,这导致 Detox Android 构建失败

我不确定为什么常规 Android 构建成功而 Detox 构建失败,但解决方法是编辑库android/build.gradle并将其更改为minSdkVersion从根项目读取

minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : 16
Run Code Online (Sandbox Code Playgroud)

理想情况下,这将通过 PR 在核心库中修复(不要忘记制作一个)。同时,你可以自己fork项目,修复bug并在 中引用它来使用修复的项目package.json

"<lib-name>": "github:<username>/<lib-name>"
Run Code Online (Sandbox Code Playgroud)

或者您可以使用补丁包的补丁应用到node_modules/<libname>/android/build.gradle运行时npm install

这似乎是 RN 库中一个很常见的错误。在我们的中型 RN 项目中,我不得不修补三个库,包括react-native-webview