I’m building a app for a Pax SmartPOS using the Zoop SmartPOS SDK, it uses Android SDK 23 so I need to use the coreLibraryDesugaringEnabled for it to be able to use the java time Instant.
The problem is that when I enable Desugaring my app doesn’t start, it crashes with the following error:
Failed to register native method com.facebook.react.devsupport.CxxInspectorPackagerConnection$WebSocketDelegate.didFailWithError(Ljava/util/OptionalInt;Ljava/lang/String;)V in /data/app/com.zoop-2/base.apk
The full trace can be found here.
I’ve tried things like downgrading Gradle version but nothing seems to work.
This is my build.gradle (app) file:
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"
react {
}
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion
namespace "com.zoop"
defaultConfig {
applicationId "com.zoop"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
compileOptions {
coreLibraryDesugaringEnabled = true
}
}
repositories {
mavenLocal()
maven {
url = uri("https://maven.pkg.github.com/getzoop/zoop-package-public")
credentials {
username = "" // Seu usuário do GitHub.
password = "" // Sua PAT do GitHub.
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("br.zoop.pos.plugin:smartpos-pax-a910:1.8.2")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.22")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation "com.google.code.gson:gson:2.10"
implementation("com.squareup.okhttp:okhttp:2.5.0")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
And my build.gradle (module) file:
buildscript {
ext {
buildToolsVersion = "34.0.0"
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.22"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
}
}
apply plugin: "com.facebook.react.rootproject"
2
Answers
Add desugarring sdk in you gradle file.
The documentation does not suggest to desugar anything.
Don’t use desugaring, but install and use JDK 17, as required:
"Failed to register native method" usually comes from obfuscation and missing
-keep
rules.