Due to project reasons, I need to access the game written by Cocos2DX-JS in the application. I have never come into contact with such requirements before, and I am not familiar with JS. Therefore, I write this article to record the problems I have encountered. (Permanent update)

  1. Error compiling Android project using Cocos Creator

     The "android" command is deprecated.
     For manual SDK, AVD, and project management, please use Android Studio.
     For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
     Invalid or unsupported command "update project -t android-22 -p /Users/XXXX/Documents/XXXX/build/jsb-link/frameworks/runtime-src/proj.android-studio/app"
     Supported commands are:
     android list target
     android list avd
     android list device
     android create avd
     android move avd
     android delete avd
     android list sdk
     android update sdk
     Error running command, return code: 2.
    Copy the code

Cause: The SDK/Tools version is too high. Use tools of an earlier version to override the SDK/Tools version

  1. When using a third-party packaged framework, if other third-party libraries are loaded in the framework, pay attention to the version of the library in the framework, because the version of the library may be too low, so that there is no new version of the method and therefore error. Situation: jump cocos2dx game interface in the application, has been an error. The Java lang. NoSuchMethodError: No virtual method newWebSocket (Lokhttp3 / Request; Lokhttp3/WebSocketListener;) Lokhttp3/WebSocket; in class Lokhttp3/OkHttpClient; or its super classes (declaration of ‘okhttp3.OkHttpClient’ appears in /data/app/com.quangames.a.paiju-1/split_lib_dependencies_apk.apk:classes22.dex)

    The reason is that OKGO is encapsulated in the network framework I use, and the version of OKHttp in OKGO is 3.4.1, while the version of network class encapsulated in Cocos2DX needs to use 3.5.0. The version is too low, so the method does not exist.

  2. After entering the game interface of Cocos2DX-JS, clicking the back button in the game interface will cause the app process to be killed.

    The call to / / game exits, js code PaiJuAppClient. Prototype. JsbEnd = function () {if (DeviceUtils. IsIOS ()) {cc. Director. StopAnimation (); jsb.reflection.callStaticMethod("TGGameStaticController",popVC"); } else { cc.director.end(); // Android calls method}};Copy the code

Cc.director. End (); Causes the application to be killed and then uses reflection to call the local activity method instead

jsb.reflection.callStaticMethod(".. /GameActivity", "stopGameControl","()V");Copy the code

But the app will still be killed. After a Google search, it is found that the process is killed because terminateProces() in Cocos2dxHelper will be called after clicking exit. Just comment out this line of code. Then click Exit and the reflection calls the locally written method

    public static void terminateProcess() {
    //  android.os.Process.killProcess(android.os.Process.myPid());
    }
Copy the code
  1. When you finish the activity, the threads in the runOnGlThread() are still executing. When you finish the activity, the runOnGlThread() is still executing. Cocos2dxGLSurfaceView is not destroyed. Solution: In AndroidManifest, set up a separate process in the activity TAB where the game is located

     android:process="com.exam.game"
    Copy the code

Then if you have commented out the terminateProcess() content in Cocos2dxHelper, uncomment it, and in return listener, set to kill the current thread. android.os.Process.killProcess(android.os.Process.myPid()); // Kill process this method does not need to call the local method in JS, this is whether the game exit, or return exit, will kill the process, re-initialization of the game interface. Black screen no longer appears. 5. After submitting the project embedded in the game to SVN, the. So file in LIBS and. A file in OBj failed to be uploaded to SVN. The default configuration of the SVN ignores many files with suffix endings such as. So /. A. Igonre can be removed. I used Cornerstone for MAC to commit to SVN. Open Cornerstone’s Settings and, as shown, remove user Default Global from it, and then delete the file suffix you wish to remove.