案子
我在我的 react native 应用程序中使用了 Mesibo sdk。在调试时它按预期工作,但在发布版本中它在 Mesibo 源代码中显示以下错误。
问题
我不确定调试和发布版本中的getReactApplicationContext()是否存在差异,但由于错误出现在api.init(getReactApplicationContext()); 会是这样吗?还是Mesibo源代码有错误?
错误:
--------- beginning of main
--------- beginning of system
03-31 18:45:51.205 3176 3275 F zygote64: thread.cc:2023] Throwing new exception 'no static method "Lcom/mesibo/api/Mesibo;.on_file(IIJJJIILjava/lang/String;IILjava/lang/String;[B[B[BLjava/lang/String;Ljava/lang/String;IFFJI)I"' with unexpected pending exception: java.lang.NoSuchMethodError: no static method "Lcom/mesibo/api/Mesibo;.on_message(IIJJJIILjava/lang/String;[BIJII)I"
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at boolean com.mesibo.api.JNIAPI.setup(android.content.Context, java.lang.String, java.lang.String) (SourceFile:-2)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at boolean com.mesibo.api.Mesibo.init(android.content.Context) (SourceFile:1255)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.appname.MesiboModule.setCaller(java.lang.String) (MesiboModule.java:65)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.facebook.react.bridge.JavaMethodWrapper.invoke(com.facebook.react.bridge.JSInstance, com.facebook.react.bridge.ReadableArray) (JavaMethodWrapper.java:372)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.facebook.react.bridge.JavaModuleWrapper.invoke(int, com.facebook.react.bridge.ReadableNativeArray) (JavaModuleWrapper.java:151)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.facebook.react.bridge.queue.NativeRunnable.run() (NativeRunnable.java:-2)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:789)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(android.os.Message) (MessageQueueThreadHandler.java:27)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void android.os.Looper.loop() (Looper.java:164)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run() (MessageQueueThreadImpl.java:226)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023] at void java.lang.Thread.run() (Thread.java:764)
03-31 18:45:51.206 3176 3275 F zygote64: thread.cc:2023]
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:508] Runtime aborting...
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:508]
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] Throwing new exception 'no static method "Lcom/mesibo/api/Mesibo;.on_file(IIJJJIILjava/lang/String;IILjava/lang/String;[B[B[BLjava/lang/String;Ljava/lang/String;IFFJI)I"' with unexpected pending exception: java.lang.NoSuchMethodError: no static method "Lcom/mesibo/api/Mesibo;.on_message(IIJJJIILjava/lang/String;[BIJII)I"
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at boolean com.mesibo.api.JNIAPI.setup(android.content.Context, java.lang.String, java.lang.String) (SourceFile:-2)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at boolean com.mesibo.api.Mesibo.init(android.content.Context) (SourceFile:1255)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.appname.MesiboModule.setCaller(java.lang.String) (MesiboModule.java:65)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.facebook.react.bridge.JavaMethodWrapper.invoke(com.facebook.react.bridge.JSInstance, com.facebook.react.bridge.ReadableArray) (JavaMethodWrapper.java:372)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.facebook.react.bridge.JavaModuleWrapper.invoke(int, com.facebook.react.bridge.ReadableNativeArray) (JavaModuleWrapper.java:151)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.facebook.react.bridge.queue.NativeRunnable.run() (NativeRunnable.java:-2)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void android.os.Handler.handleCallback(android.os.Message) (Handler.java:789)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(android.os.Message) (MessageQueueThreadHandler.java:27)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void android.os.Looper.loop() (Looper.java:164)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run() (MessageQueueThreadImpl.java:226)
03-31 18:45:51.206 3176 3275 F zygote64: runtime.cc:516] at void java.lang.Thread.run() (Thread.java:764)
代码
Mesibo模块:
@ReactMethod
public void setCaller(String token) {
try {
Mesibo api = Mesibo.getInstance();
api.init(getReactApplicationContext());
Mesibo.addListener(this);
Mesibo.setSecureConnection(true);
Mesibo.setAccessToken(token);
Mesibo.start();
} catch (Exception e) {
Log.e(TAG + " : SetCallerError", e.toString());
}
}
构建.gradle:
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = true
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.appid"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 6
versionName "6.0-Beta"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
packagingOptions {
pickFirst '**/*.so'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
//Mesibo Dependencies
implementation 'com.mesibo.api:mesibo:1.2.70'
implementation 'com.mesibo.api:calls:1.2.82'
implementation 'com.mesibo.api:ui:1.2.81'
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
包.json:
{
"dependencies": {
"react": "16.13.1",
"react-native": "0.63.4"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/runtime": "^7.12.13",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.20.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.65.1",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}