Giter Club home page Giter Club logo

cocosandroid's Introduction

Cocos Android

Android dynamic load cocos create game framework.

Click to download sample apk.

Download apk

Environment

  • Ndk version less than 17

Structure

  • libcocos2dx
  • libcocos2djs
  • script

Libcocos2dx

  • Java files cp from /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/platform/android/java/src
  • Jar files cp from /Applications/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/platform/android/java/libs
  • Load game resource Need modify default game resource from assets to custom!!!

Libcocos2djs

Just contain jni files, ndk compile output libcocos2djs.so file.

  • Classes cp from jsb-binary/frameworks/runtime-src/Classes
  • hellojavascript cp from proj.android-studio/app/jni
  • Android.mk compile cocos2djs native library

Game pack

  • res, src, main.js, project.json copy from ${buildDir}/../../../../../
  • script copy from "/Applications/CocosCreator.app/Contents/Resources/cocos2d-x/cocos/scripting/js-bindings/script"

Test

Just run app module as apk.

Issue

  • decrypt AppDelegate.cpp jsb_set_xxtea_key("key-value")
  • game back key handle(Modify game activity to another process)

Patch for cocos android

  • Dynamic load game
// Load game by AssetManager.addAssetPath method
public static boolean addAssetPath(Activity activity, String path) {
        try {
            AssetManager assetManager = activity.getAssets();
            Object result = AssetManager.class.getDeclaredMethod("addAssetPath", String.class).invoke(
                    assetManager, path);
            Log.i(TAG, "addAssetPath result:" + result.toString());

            int resultInt = (int) result;
            if (resultInt != 0) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
}
  • Disable check task root
protected final static boolean IS_CHECK_ROOT = false;
if (IS_CHECK_ROOT && !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;
}
  • Disable decrypt js
Modify AppDelegate.cpp, need dynamic set decrypt key, or set the default key for all game.
// jsb_set_xxtea_key("3b4139a4-456c-42");

cocosandroid's People

Contributors

kylingo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

html5-game

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.