Skip to content

React native 0.72.4 targeting android 13 build issues #10

@ShevO27

Description

@ShevO27

Hi! 👋

I've recently upgraded react-native version to 0.72.4 and found that android no longer builds due to a couple of issues, you can check both of them on reproducible repo https://github.com/Oleksii27/DfuExample on master branch. To reproduce:

cd android
./gradlew build

And you'll notice couple of build errors

  1. minSdkVersion incompatibility:
> Task :react-native-nordic-dfu:processDebugAndroidTestManifest FAILED
/dev/AwesomeProject/node_modules/react-native-nordic-dfu/android/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest8717370557204022401.xml:5:5-74 Error:
        uses-sdk:minSdkVersion 18 cannot be smaller than version 21 declared in library [com.facebook.react:react-android:0.72.4] /Users/.gradle/caches/transforms-3/6fe00d6361b0f0c55549aec89a7f6742/transformed/jetified-react-android-0.72.4-debug/AndroidManifest.xml as the library might be using APIs not available in 18
        Suggestion: use a compatible library with a minSdk of at most 18,
                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)

See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger.

Which is caused by minSdkVersion 18 in build.gradle

I've solved it by applying a patch, where I inherited projects minSdkVersion, which I believe is a good solution. I could submit a pull request for that if it's fine.

diff --git a/node_modules/react-native-nordic-dfu/android/build.gradle b/node_modules/react-native-nordic-dfu/android/build.gradle
index 548c19d..6ddc13d 100644
--- a/node_modules/react-native-nordic-dfu/android/build.gradle
+++ b/node_modules/react-native-nordic-dfu/android/build.gradle
@@ -15,13 +15,14 @@ apply plugin: 'com.android.library'
 def DEFAULT_COMPILE_SDK_VERSION = 31
 def DEFAULT_BUILD_TOOLS_VERSION = '31.0.0'
 def DEFAULT_TARGET_SDK_VERSION = 31
+def DEFAULT_MIN_SDK_VERSION = 18
 
 android {
     compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
     buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
 
     defaultConfig {
-        minSdkVersion 18
+        minSdkVersion project.hasProperty('minSdkVersion') ? project.minSdkVersion : DEFAULT_MIN_SDK_VERSION
         targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
         versionCode 1
         versionName "1.0"
  1. The second one is a gradle lint problem which appears after applying the above patch:
> Task :app:lintDebug FAILED
Lint found 1 errors, 5 warnings. First failure:

/dev/AwesomeProject/android/app/src/main/AndroidManifest.xml: Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from no.nordicsemi.android.dfu.DfuBaseService) [NotificationPermission]

   Explanation for issues of type "NotificationPermission":
   When targeting Android 13 and higher, posting permissions requires holding
   the runtime permission android.permission.POST_NOTIFICATIONS.


The full lint text report is located at:
  /dev/AwesomeProject/android/app/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

Which is caused by a native no.nordicsemi.android.dfu.DfuBaseService class, I believe it has something to do with DfuBaseService class using some notification posting, but I don't have much experience with java and I haven't really looked at their code. I have found that Android-DFU-Library uses this permission in their AndroidManifest in the example https://github.com/NordicSemiconductor/Android-DFU-Library/blob/b37200033f5d3fe412994e05dd20dd57e14acfe5/app/src/main/AndroidManifest.xml

Which I suppressed by creating a lint config

<?xml version="1.0" encoding="utf-8" ?>
<lint>
    <issue id="NotificationPermission">
        <ignore regexp="no.nordicsemi.android.dfu.DfuBaseService" />
    </issue>
</lint>
lint {
        // https://github.com/bumptech/glide/issues/4940 which I adapted from here
        lintConfig = file("$rootDir/lintConfig.xml")
    }

But as far as I understand this only "suppresses" the error and I don't know about the consequences.

You can check both fixes on a patched branch of an example repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions