Cocos2d-js use firebase but get error, SDKBOX_CORE: Checking plugin status for unknown plugin: Firebase

We are going to use firebase from JS to Android.

The enviroment:

Cocos Creator 3.0.1
SDKBOX GUI 1.5.1
Firebase Plugin 2.7.5.0
NDK 19.2.5345600
PROP_COMPILE_SDK_VERSION=30
PROP_TARGET_SDK_VERSION=30
PROP_BUILD_TOOLS_VERSION=30.0.2

Here is our JS code:

        console.log(`sdkbox.firebase.Analytics.init() ..`);
        try {
            sdkbox.firebase.Analytics.init();
        } catch (error) {
            console.error(error.toString());
            console.log(error.stack);
        }

Here is the logcat log:

2021-05-06 17:39:31.691 26877-27052/? E/SDKBOX_CORE: Checking plugin status for unknown plugin: Firebase
2021-05-06 17:39:31.691 26877-27052/? W/System.err: java.lang.ClassNotFoundException: com.sdkbox.plugin.SdkboxLog
2021-05-06 17:39:31.691 26877-27052/? W/System.err: java.lang.NoSuchMethodError: no static method "Lcom/sdkbox/plugin/SdkboxLog;.NewLog(Ljava/lang/String;)V"
2021-05-06 17:39:31.691 26877-27052/? E/SDKBOX_CORE: JNI_BRIDGE Not found static method NewLog, for clazz com/sdkbox/plugin/SdkboxLog and signature (Ljava/lang/String;)V
2021-05-06 17:39:31.691 26877-27052/? W/System.err: java.lang.ClassNotFoundException: com.sdkbox.plugin.SdkboxLog
2021-05-06 17:39:31.691 26877-27052/? W/System.err: java.lang.NoSuchMethodError: no static method "Lcom/sdkbox/plugin/SdkboxLog;.setLevelForTag(Ljava/lang/String;I)V"
2021-05-06 17:39:31.691 26877-27052/? E/SDKBOX_CORE: JNI_BRIDGE Not found static method setLevelForTag, for clazz com/sdkbox/plugin/SdkboxLog and signature (Ljava/lang/String;I)V

We have reference below link, but still not solve our problem:

the content of assets/skdbox_config.json in unpack APK as below:

{
    "android": {
        "Firebase": {}
    },
    "ios": {
        "Firebase": {}
    }
}

Reference the Firebase Integration Guide(JS version):
http://docs.sdkbox.com/en/plugins/firebase/v3-js/
We add some code in jsb_module_register.cpp as below:


#include "PluginFirebaseJS.hpp"
#include "PluginFirebaseJSHelper.h"

bool jsb_register_all_modules() {
    ....
    se->addRegisterCallback(register_all_PluginFirebaseJS);
    se->addRegisterCallback(register_all_PluginFirebaseJS_helper);
    return true;
}

Here is our AppActivity.java

...
import com.cocos.service.SDKWrapper;
import com.cocos.lib.CocosActivity;

public class AppActivity extends com.sdkbox.plugin.SDKBoxCocosActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
        if (!isTaskRoot()) {
            // Android launched another instance of the root activity into an existing task
            //  so just quietly finish and go away, dropping the user back into the activity
            //  at the top of the stack (ie: the last state of this task)
            // Don't need to finish it again since it's finished in super.onCreate .
            return;
        }
        // DO OTHER INITIALIZATION BELOW
        SDKWrapper.shared().init(this);
    }
...

What we are missing?
We need help, thanks.

seem like, jar file missing.

the sample is not use the lastest sdk, but you can take it as reference.

We put those 4 jar filles, android-support-v4.jar, PluginFirebase.jar, sdkbox.jar, and sdkbox-firebase.jar, the got the Duplicate problem as below:

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable

Duplicate class android.support.v4.app.INotificationSideChannel found in modules android-support-v4 (android-support-v4.jar) and core-1.0.0-runtime (androidx.core:core:1.0.0)

Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules play-services-measurement-impl-18.0.3-runtime (com.google.android.gms:play-services-measurement-impl:18.0.3) and sdkbox-firebase (sdkbox-firebase.jar)

Duplicate class com.google.firebase.FirebaseApp found in modules firebase-common-19.5.0-runtime (com.google.firebase:firebase-common:19.5.0) and sdkbox-firebase (sdkbox-firebase.jar)

Duplicate class com.google.firebase.analytics.FirebaseAnalytics found in modules play-services-measurement-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-api:18.0.3) and sdkbox-firebase (sdkbox-firebase.jar)

What should we try to fix this?

image

Here is the folder /native/engin/android/app/jni

Thanks for the response.

We are trying to add the *.jar from sample, then facing some build problem so we edit some files to fix and build a APK, but still got the error log:
SDKBOX_CORE: Checking plugin status for unknown plugin: Firebase

Here is the change.

  • Add jar files, there are 4 jar files under \native\engine\android\app\libs
    These three files, android-async-http-1.4.8.jar, PluginGoogleAnalytics.jar, and sdkbox.jar, are from the sample.
    The PluginFirebase.jar is imported from SDKBox.

  • In app build.gradle

...
dependencies {
    // implementation 'com.google.firebase:firebase-analytics:17.4.4'
    // Import the Firebase BoM
    // implementation 'com.google.android.gms:play-services:9.2.1'
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation platform('com.google.firebase:firebase-bom:27.1.0')
}

We zip some files of our project, hope that could help to find the problem out.
files.zip (82.8 KB)

We still need some guide to use the Google Analytics of Firebase on cocos project, thanks.

my fault, you use Creator 3, i thought you use cocos2d-js.

integrate firebase on creator3 steps:

  1. run cd $CREATE3ProjectRoot
  2. run sdkbox import firebase
  3. modify gradle.properties like follow
...
PROP_COMPILE_SDK_VERSION=28  // It doesn't have to be set to 28, as long as the compile, target, tool are consistent.
PROP_MIN_SDK_VERSION=16
PROP_TARGET_SDK_VERSION=28
PROP_BUILD_TOOLS_VERSION=28.0.2
...

android.useAndroidX=true

  1. modify jsb_module_register.cpp like follow
    
    // register firebase into js
    se->addRegisterCallback(register_all_PluginFirebaseJS);
    se->addRegisterCallback(register_all_PluginFirebaseJS_helper);

    se->addAfterCleanupHook([]() {
        PoolManager::getInstance()->getCurrentPool()->clear();
        JSBClassType::destroy();
    });
  1. compile and run.

@htlxyz
We found 2 problem of import firebase.

  1. Send message to Google Analytics success only in debug build
  2. Got some error log in logcat, even if the send message to Google Analytics success

Problem 1: run google analytics of firebase without problem

Here is our operation for building a debug apk:

  1. Create project, adding TS file to connecting firebase for google analytics using
  2. Build project, set ‘debug’ in build config
  3. Download SDKBox from store and install SDKBox in Extension Manager
  4. Import Firebase via SDKBox
  5. Firebase for android config
    file \build\android\proj\build.gradle of proj, follow the guide
...
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        // add this line
        classpath 'com.google.gms:google-services:4.3.5'  // Google Services plugin
...

file `\native\engine\android\app\build.gradle of app

apply plugin: 'com.android.application'
\\ add this line
apply plugin: 'com.google.gms.google-services'  // Google Services plugin
...
dependencies { 
    implementation 'com.google.firebase:firebase-analytics:17.4.4'
    \\ add this line
    implementation platform('com.google.firebase:firebase-bom:27.1.0')
}
...

file \build\android\proj\gradle.properties

...
PROP_COMPILE_SDK_VERSION=28  // It doesn't have to be set to 28, as long as the compile, target, tool are consistent.
PROP_MIN_SDK_VERSION=16
PROP_TARGET_SDK_VERSION=28
PROP_BUILD_TOOLS_VERSION=28.0.2
...

android.useAndroidX=true

Here has one question, why the PROP_COMPILE_SDK_VERSION and PROP_TARGET_SDK_VERSION will rollback to 27, is there a config to make this always be 30 after each time of build project.

  1. Binding Firebase, make sure the jsb bind, file \native\engine\common\Classes\jsb_module_register.cpp
...
#include "cocos/bindings/manual/jsb_xmlhttprequest.h"

// js-binding-Firebase, add below two lines
#include "PluginFirebaseJS.hpp"
#include "PluginFirebaseJSHelper.h"

#if USE_GFX_RENDERER
#endif
...
    se->addRegisterCallback(register_all_pipeline_manual);
    // js-binding-Firebase, add below two lines
    se->addRegisterCallback(register_all_PluginFirebaseJS);
    se->addRegisterCallback(register_all_PluginFirebaseJS_helper);

#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS || CC_PLATFORM == CC_PLATFORM_MAC_OSX)
    se->addRegisterCallback(register_javascript_objc_bridge);
#endif
...
  1. Make project, generate apk
  2. Run project, install apk on android device and launch app

Got unknown plugin: Firebase error log, but google analytics receive the logEvent successfully

2021-05-12 12:03:38.030 16251-16321/com.abc.cde.dev E/SDKBOX_CORE: Checking plugin status for unknown plugin: Firebase
2021-05-12 12:03:38.031 16251-16321/com.abc.cde.dev W/System.err: java.lang.ClassNotFoundException: Didn't find class "com.sdkbox.plugin.SdkboxLog" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /oppo_product/lib, /system/lib, /system/product/lib, /oppo_product/lib]]
2021-05-12 12:03:38.031 16251-16321/com.abc.cde.dev W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
2021-05-12 12:03:38.031 16251-16321/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
2021-05-12 12:03:38.031 16251-16321/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
2021-05-12 12:03:38.032 16251-16321/com.abc.cde.dev W/System.err: java.lang.ClassNotFoundException: Didn't find class "com.sdkbox.plugin.SDKBox" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /oppo_product/lib, /system/lib, /system/product/lib, /oppo_product/lib]]
2021-05-12 12:03:38.032 16251-16321/com.abc.cde.dev W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
2021-05-12 12:03:38.032 16251-16321/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
2021-05-12 12:03:38.032 16251-16321/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
2021-05-12 12:03:38.032 16251-16321/com.abc.cde.dev I/SDKBOX_CORE: Initialization request for plugin: 'com/sdkbox/plugin/firebase/Analytics/Analytics'
  1. Re-make project, execute step 4, 6, and 7

Got different error log, but google analytics receive the logEvent successfully

2021-05-12 12:16:25.477 20214-20300/com.abc.cde.dev D/jswrapper: JS: bangyno init e
2021-05-12 12:16:25.478 20214-20300/com.abc.cde.dev W/System.err: java.lang.ClassNotFoundException: Didn't find class "com.sdkbox.plugin.TrackingInfoAndroid" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /oppo_product/lib, /system/lib, /system/product/lib, /oppo_product/lib]]
2021-05-12 12:16:25.478 20214-20300/com.abc.cde.dev W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
2021-05-12 12:16:25.478 20214-20300/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
2021-05-12 12:16:25.478 20214-20300/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
2021-05-12 12:16:25.479 20214-20300/com.abc.cde.dev W/System.err: java.lang.ClassNotFoundException: Didn't find class "com.sdkbox.plugin.TrackingInfoAndroid" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/product/lib, /oppo_product/lib, /system/lib, /system/product/lib, /oppo_product/lib]]
2021-05-12 12:16:25.479 20214-20300/com.abc.cde.dev W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
2021-05-12 12:16:25.479 20214-20300/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
2021-05-12 12:16:25.480 20214-20300/com.abc.cde.dev W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Here is the question, what is the error and we need to care this error log?

Problem 2: build release apk for google analytics of firebase

Our final goal is build a release apk, but now we only could build a debug apk for google analytics of firebase.

Follow the steps 1-8 but skip step 2, we build the release apk.
Got unknown plugin: Firebase error log, and google analytics logEvent didn’t receive

2021-05-12 11:57:20.326 14332-14390/? E/SDKBOX_CORE: Checking plugin status for unknown plugin: Firebase
2021-05-12 11:57:20.326 14332-14390/? W/System.err: java.lang.ClassNotFoundException: com.sdkbox.plugin.SdkboxLog
2021-05-12 11:57:20.326 14332-14390/? W/System.err: java.lang.NoSuchMethodError: no static method "Lcom/sdkbox/plugin/SdkboxLog;.NewLog(Ljava/lang/String;)V"
2021-05-12 11:57:20.326 14332-14390/? E/SDKBOX_CORE: JNI_BRIDGE Not found static method NewLog, for clazz com/sdkbox/plugin/SdkboxLog and signature (Ljava/lang/String;)V

What is the problem?

Could you give us some guide?
Thanks.

1.

seemlike creator’s build setting is 27.

2.

check proguard?

# firebase
-keep class com.firebase.** { *; }
-dontwarn com.firebase.**

# cocos2d-x
-keep public class org.cocos2dx.** { *; }
-dontwarn org.cocos2dx.**
-keep public class com.chukong.** { *; }
-dontwarn com.chukong.**

# google play service
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**

#sdkbox
-keep public class com.sdkbox.** { *; }
-dontwarn com.sdkbox.**

http://docs.sdkbox.com/en/plugins/firebase/v3-js/#proguard-optional

3.

you can ignore this for now, we will fix this later.

@htlxyz
Thanks for your guide, we success generate the release apk.
All we need to do is adding those code in \native\engine\android\app\proguard-rules.pro

# firebase
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**


# cocos2d-x
-keep public class org.cocos2dx.** { *; }
-dontwarn org.cocos2dx.**
-keep public class com.chukong.** { *; }
-dontwarn com.chukong.**

# google play service
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**

-keep class com.google.protobuf.** { *; }
-dontwarn com.google.protobuf.**

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

#sdkbox
-keep public class com.sdkbox.** { *; }
-dontwarn com.sdkbox.**

We are still curious about how to set PROP_COMPILE_SDK_VERSION and PROP_TARGET_SDK_VERSION just once, not each time we build the project.

This is how we set the SDK version(30).
Snipaste_2021-05-20_17-14-33

Check the Edit Build Config(30).
Snipaste_2021-05-20_17-22-34

But the gradle.properties is different after each build finish
Snipaste_2021-05-20_17-25-55

gradle.properties not changed.

you can try Cocos Creator 3.1.1 for this issue.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.