我正在使用 Zoop SmartPOS SDK 为 Pax SmartPOS 构建一个应用程序,它使用 Android SDK 23,因此我需要使用 coreLibraryDesugaringEnabled 才能使用 java time Instant。
问题是,当我启用脱糖时,我的应用程序无法启动,它崩溃并出现以下错误:
无法在 /data/app/com.zoop-2/base.apk 中注册本机方法 com.facebook.react.devsupport.CxxInspectorPackagerConnection$WebSocketDelegate.didFailWithError(Ljava/util/OptionalInt;Ljava/lang/String;)V
完整的踪迹可以在这里找到。
我尝试过降级 Gradle 版本之类的方法,但似乎没有任何效果。
这是我的 build.gradle(应用程序)文件:
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)
还有我的 build.gradle(模块)文件:
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"
在你的gradle文件中添加脱糖sdk。
dependencies {
...
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6'
...
}
compileOptions {
//enable desugaring library
coreLibraryDesugaringEnabled = true
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
不要使用脱糖,但根据需要安装并使用 JDK 17:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}