diff --git a/native/templates/js-template-android-instant/cocos-project-template.json b/native/templates/js-template-android-instant/cocos-project-template.json new file mode 100755 index 0000000000..f6df80526a --- /dev/null +++ b/native/templates/js-template-android-instant/cocos-project-template.json @@ -0,0 +1,66 @@ +{ + "do_default": { + "exclude_from_template": [ + "frameworks/runtime-src" + ] + }, + "do_add_native_support": { + "append_from_template": { + "from": "frameworks/runtime-src", + "to": "frameworks/runtime-src", + "exclude": [ + ] + }, + "append_dir": [ + { + "from": "extensions/anysdk/platform/android/src", + "to": "frameworks/runtime-src/proj.android-studio/app/src" + }, + { + "from": "extensions/anysdk/platform/android/src", + "to": "frameworks/runtime-src/proj.android-studio/game/src" + } + ], + "append_file": [ + { + "from": "cocos/scripting/js-bindings/manual/jsb_module_register.cpp", + "to": "frameworks/runtime-src/Classes/jsb_module_register.cpp" + } + ], + "append_x_engine": { + "from": ".", + "to": "frameworks/cocos2d-x" + }, + "project_rename": { + "src_project_name": "HelloJavascript", + "files": [ + ] + }, + "project_replace_project_name": { + "src_project_name": "HelloJavascript", + "files": [ + "frameworks/runtime-src/proj.android-studio/settings.gradle", + "frameworks/runtime-src/proj.android-studio/app/res/values/strings.xml", + "frameworks/runtime-src/proj.android-studio/game/res/values/strings.xml", + "frameworks/runtime-src/Classes/AppDelegate.cpp" + ] + }, + "project_replace_package_name": { + "src_package_name": "org.cocos2dx.hellojavascript", + "files": [ + "frameworks/runtime-src/proj.android-studio/app/build.gradle", + "frameworks/runtime-src/proj.android-studio/app/AndroidManifest.xml" + ] + }, + "project_replace_mac_bundleid": { + "src_bundle_id": "org.cocos2dx.hellojavascript", + "files": [ + ] + }, + "project_replace_ios_bundleid": { + "src_bundle_id": "org.cocos2dx.hellojavascript", + "files": [ + ] + } + } +} \ No newline at end of file diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.cpp b/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.cpp new file mode 100755 index 0000000000..29b443ff08 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "AppDelegate.h" + +#include "cocos2d.h" + +#include "cocos/scripting/js-bindings/manual/jsb_module_register.hpp" +#include "cocos/scripting/js-bindings/manual/jsb_global.h" +#include "cocos/scripting/js-bindings/jswrapper/SeApi.h" +#include "cocos/scripting/js-bindings/event/EventDispatcher.h" +#include "cocos/scripting/js-bindings/event/CustomEventTypes.h" +#include "cocos/scripting/js-bindings/manual/jsb_classtype.hpp" + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS +#include "SDKManager.h" +#include "jsb_anysdk_protocols_auto.hpp" +#include "manualanysdkbindings.hpp" +using namespace anysdk::framework; +#endif + +USING_NS_CC; + +AppDelegate::AppDelegate(int width, int height) : Application("Cocos Game", width, height) +{ +} + +AppDelegate::~AppDelegate() +{ +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS + SDKManager::getInstance()->purge(); +#endif +} + +bool AppDelegate::applicationDidFinishLaunching() +{ +#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS && PACKAGE_AS + SDKManager::getInstance()->loadAllPlugins(); +#endif + + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + + jsb_set_xxtea_key(""); + jsb_init_file_operation_delegate(); + +#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) + // Enable debugger here + jsb_enable_debugger("0.0.0.0", 5086); +#endif + + se->setExceptionCallback([](const char* location, const char* message, const char* stack){ + // Send exception information to server like Tencent Bugly. + + }); + + jsb_register_all_modules(); + +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) && PACKAGE_AS + se->addRegisterCallback(register_all_anysdk_framework); + se->addRegisterCallback(register_all_anysdk_manual); +#endif + + se->start(); + + se::AutoHandleScope hs; + jsb_run_script("jsb-adapter/jsb-builtin.js"); + jsb_run_script("main.js"); + + se->addAfterCleanupHook([](){ + JSBClassType::destroy(); + }); + + return true; +} + +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void AppDelegate::applicationDidEnterBackground() +{ + CustomEvent event; + event.name = EVENT_COME_TO_BACKGROUND; + EventDispatcher::dispatchCustomEvent(event); + EventDispatcher::dispatchEnterBackgroundEvent(); +} + +// this function will be called when the app is active again +void AppDelegate::applicationWillEnterForeground() +{ + CustomEvent event; + event.name = EVENT_COME_TO_FOREGROUND; + EventDispatcher::dispatchCustomEvent(event); + EventDispatcher::dispatchEnterForegroundEvent(); +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.h b/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.h new file mode 100755 index 0000000000..47bad3646d --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/Classes/AppDelegate.h @@ -0,0 +1,57 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#pragma once + +#include "platform/CCApplication.h" +/** + @brief The cocos2d Application. + + The reason for implement as private inheritance is to hide some interface call by Director. + */ +class AppDelegate : public cocos2d::Application +{ +public: + AppDelegate(int width, int height); + virtual ~AppDelegate(); + + /** + @brief Implement Director and Scene init code here. + @return true Initialize success, app continue. + @return false Initialize failed, app terminate. + */ + virtual bool applicationDidFinishLaunching() override; + + /** + @brief The function be called when the application enter background + @param the pointer of the application + */ + virtual void applicationDidEnterBackground() override; + + /** + @brief The function be called when the application enter foreground + @param the pointer of the application + */ + virtual void applicationWillEnterForeground() override; +}; diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/.gitignore b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/.gitignore new file mode 100755 index 0000000000..9c4de5825b --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/.gitignore b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/.gitignore new file mode 100755 index 0000000000..1de99493d6 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/.gitignore @@ -0,0 +1,2 @@ +/build +/jniLibs diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/AndroidManifest.xml b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/AndroidManifest.xml new file mode 100755 index 0000000000..7c1619b531 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/AndroidManifest.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/build.gradle b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/build.gradle new file mode 100755 index 0000000000..54747452aa --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/build.gradle @@ -0,0 +1,125 @@ +import org.apache.tools.ant.taskdefs.condition.Os + +apply plugin: 'com.android.application' + +android { + compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() + buildToolsVersion PROP_BUILD_TOOLS_VERSION + + defaultConfig { + applicationId "org.cocos2dx.hellojavascript" + minSdkVersion PROP_MIN_SDK_VERSION + targetSdkVersion PROP_TARGET_SDK_VERSION + versionCode 1 + versionName "1.0" + + externalNativeBuild { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + targets 'cocos2djs' + arguments 'NDK_TOOLCHAIN_VERSION=4.9' + + def module_paths = [project.file("../../../cocos2d-x"), + project.file("../../../cocos2d-x/cocos"), + project.file("../../../cocos2d-x/external")] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + arguments 'NDK_MODULE_PATH=' + module_paths.join(";") + } + else { + arguments 'NDK_MODULE_PATH=' + module_paths.join(':') + } + + arguments '-j' + Runtime.runtime.availableProcessors() + abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String}) + } + } + } + } + + sourceSets.main { + java.srcDir "src" + res.srcDir "res" + jniLibs.srcDir "libs" + manifest.srcFile "AndroidManifest.xml" + } + + externalNativeBuild { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + path "jni/Android.mk" + } + } + } + + signingConfigs { + + release { + if (project.hasProperty("RELEASE_STORE_FILE")) { + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.release + } + + externalNativeBuild { + ndkBuild { + arguments 'NDK_DEBUG=0' + } + } + } + + debug { + externalNativeBuild { + ndkBuild { + arguments 'NDK_DEBUG=1' + } + } + } + } +} + +android.applicationVariants.all { variant -> + // delete previous files first + delete "${buildDir}/intermediates/assets/${variant.dirName}" + + variant.mergeAssets.doLast { + copy { + from "${buildDir}/../../../../../res" + into "${buildDir}/intermediates/assets/${variant.dirName}/res" + } + + copy { + from "${buildDir}/../../../../../src" + into "${buildDir}/intermediates/assets/${variant.dirName}/src" + } + + copy { + from "${buildDir}/../../../../../jsb-adapter" + into "${buildDir}/intermediates/assets/${variant.dirName}/jsb-adapter" + } + + copy { + from "${buildDir}/../../../../../main.js" + from "${buildDir}/../../../../../project.json" + into "${buildDir}/intermediates/assets/${variant.dirName}" + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: "../../../cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar']) + implementation project(':libcocos2dx') +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Android.mk b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Android.mk new file mode 100755 index 0000000000..a151978ed2 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Android.mk @@ -0,0 +1,38 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := cocos2djs_shared + +LOCAL_MODULE_FILENAME := libcocos2djs + +ifeq ($(USE_ARM_MODE),1) +LOCAL_ARM_MODE := arm +endif + +LOCAL_SRC_FILES := hellojavascript/main.cpp \ + ../../../Classes/AppDelegate.cpp \ + ../../../Classes/jsb_module_register.cpp \ + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes + +ifeq ($(USE_ANY_SDK),1) +LOCAL_SRC_FILES += ../../../Classes/anysdk/SDKManager.cpp \ + ../../../Classes/anysdk/jsb_anysdk_basic_conversions.cpp \ + ../../../Classes/anysdk/manualanysdkbindings.cpp \ + ../../../Classes/anysdk/jsb_anysdk_protocols_auto.cpp + +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../Classes/anysdk + +LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic +endif + + +LOCAL_STATIC_LIBRARIES := cocos2dx_static + +LOCAL_EXPORT_CFLAGS := -DCOCOS2D_DEBUG=2 + +include $(BUILD_SHARED_LIBRARY) + + +$(call import-module, cocos) diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk new file mode 100755 index 0000000000..028bd310bd --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/Application.mk @@ -0,0 +1,30 @@ +APP_STL := gnustl_static + +# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices +APP_ABI := armeabi-v7a + +APP_CPPFLAGS := -frtti -std=c++11 -fsigned-char +APP_LDFLAGS := -latomic + +# To solve windows commands char length too long +APP_SHORT_COMMANDS := true + +USE_ARM_MODE := 1 +USE_ANY_SDK := 1 + +ifeq ($(USE_ANY_SDK),1) +APP_CPPFLAGS += -DPACKAGE_AS +endif + +ifeq ($(NDK_DEBUG),1) + APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 + APP_CFLAGS += -DCOCOS2D_DEBUG=1 + APP_OPTIM := debug +else + APP_CPPFLAGS += -DNDEBUG + APP_CFLAGS += -DNDEBUG + APP_OPTIM := release +endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/hellojavascript/main.cpp b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/hellojavascript/main.cpp new file mode 100755 index 0000000000..caeac73cd8 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/jni/hellojavascript/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "AppDelegate.h" +#include "cocos2d.h" +#include "platform/android/jni/JniHelper.h" +#include +#include +#if PACKAGE_AS +#include "PluginJniHelper.h" +#include "SDKManager.h" +#endif + +#define LOG_TAG "main" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +using namespace cocos2d; +#if PACKAGE_AS +using namespace anysdk::framework; +#endif + +//called when JNI_OnLoad() +void cocos_jni_env_init (JNIEnv* env) { + LOGD("cocos_jni_env_init"); +#if PACKAGE_AS + JavaVM *vm; + env->GetJavaVM(&vm); + PluginJniHelper::setJavaVM(vm); +#endif +} + +//called when onSurfaceCreated() +Application* cocos_android_app_init (JNIEnv* env, int width, int height) { + LOGD("cocos_android_app_init"); + auto app = new AppDelegate(width, height); + return app; +} + +extern "C" +{ + void Java_org_cocos2dx_javascript_SDKWrapper_nativeLoadAllPlugins(JNIEnv* env, jobject thiz) + { +#if PACKAGE_AS + SDKManager::getInstance()->loadAllPlugins(); +#endif + } +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/proguard-rules.pro b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/proguard-rules.pro new file mode 100755 index 0000000000..6618e28017 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in E:\developSoftware\Android\SDK/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-hdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-hdpi/ic_launcher.png new file mode 100755 index 0000000000..8aa4767c2f Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-hdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-mdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-mdpi/ic_launcher.png new file mode 100755 index 0000000000..d53fbdd8cb Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-mdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xhdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xhdpi/ic_launcher.png new file mode 100755 index 0000000000..2f72eac17f Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xxhdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xxhdpi/ic_launcher.png new file mode 100755 index 0000000000..1526615c02 Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/values/strings.xml b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/values/strings.xml new file mode 100755 index 0000000000..a88810e3a9 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/res/values/strings.xml @@ -0,0 +1,3 @@ + + HelloJavascript + diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/javascript/AppActivity.java b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/javascript/AppActivity.java new file mode 100755 index 0000000000..e46c46608a --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/app/src/org/cocos2dx/javascript/AppActivity.java @@ -0,0 +1,145 @@ +/**************************************************************************** +Copyright (c) 2015-2016 Chukong Technologies Inc. +Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.javascript; + +import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.Cocos2dxGLSurfaceView; + +import android.os.Bundle; +import org.cocos2dx.javascript.SDKWrapper; +import com.cocos.analytics.CAAgent; + +import android.content.Context; +import android.content.Intent; +import android.content.res.Configuration; + +public class AppActivity extends Cocos2dxActivity { + + @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.getInstance().init(this); + CAAgent.enableDebug(false); + } + + @Override + public Cocos2dxGLSurfaceView onCreateView() { + Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); + // TestCpp should create stencil buffer + glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); + + SDKWrapper.getInstance().setGLSurfaceView(glSurfaceView); + + return glSurfaceView; + } + + @Override + protected void onResume() { + super.onResume(); + SDKWrapper.getInstance().onResume(); + if (CAAgent.isInited()) + CAAgent.onResume(this); + } + + @Override + protected void onPause() { + super.onPause(); + SDKWrapper.getInstance().onPause(); + if (CAAgent.isInited()) + CAAgent.onPause(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + SDKWrapper.getInstance().onDestroy(); + if (CAAgent.isInited()) + CAAgent.onDestroy(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + SDKWrapper.getInstance().onNewIntent(intent); + } + + @Override + protected void onRestart() { + super.onRestart(); + SDKWrapper.getInstance().onRestart(); + } + + @Override + protected void onStop() { + super.onStop(); + SDKWrapper.getInstance().onStop(); + } + + @Override + public void onBackPressed() { + SDKWrapper.getInstance().onBackPressed(); + super.onBackPressed(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + SDKWrapper.getInstance().onConfigurationChanged(newConfig); + super.onConfigurationChanged(newConfig); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + SDKWrapper.getInstance().onRestoreInstanceState(savedInstanceState); + super.onRestoreInstanceState(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + SDKWrapper.getInstance().onSaveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + @Override + protected void onStart() { + SDKWrapper.getInstance().onStart(); + super.onStart(); + } +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build-cfg.json b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build-cfg.json new file mode 100755 index 0000000000..8e0cf8bba8 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build-cfg.json @@ -0,0 +1,8 @@ +{ + "ndk_module_path" :[ + "../../cocos2d-x", + "../../cocos2d-x/cocos", + "../../cocos2d-x/external" + ], + "copy_resources": [] +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build.gradle b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build.gradle new file mode 100755 index 0000000000..2b56747de5 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/build.gradle @@ -0,0 +1,27 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.0.0' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/.gitignore b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/.gitignore @@ -0,0 +1 @@ +/build diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml new file mode 100644 index 0000000000..e9db9d3d7e --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/build.gradle b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/build.gradle new file mode 100644 index 0000000000..5a6bc8e0fe --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/build.gradle @@ -0,0 +1,126 @@ +import org.apache.tools.ant.taskdefs.condition.Os +apply plugin: 'com.android.feature' +android { + baseFeature true + compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() + buildToolsVersion PROP_BUILD_TOOLS_VERSION + + defaultConfig { + minSdkVersion PROP_MIN_SDK_VERSION + targetSdkVersion PROP_TARGET_SDK_VERSION + versionCode 1 + versionName "1.0" + + externalNativeBuild { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + targets 'cocos2djs' + arguments 'NDK_TOOLCHAIN_VERSION=4.9' + + def module_paths = [project.file("../../../cocos2d-x"), + project.file("../../../cocos2d-x/cocos"), + project.file("../../../cocos2d-x/external")] + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + arguments 'NDK_MODULE_PATH=' + module_paths.join(";") + } + else { + arguments 'NDK_MODULE_PATH=' + module_paths.join(':') + } + + arguments '-j' + Runtime.runtime.availableProcessors() + abiFilters.addAll(PROP_APP_ABI.split(':').collect{it as String}) + } + } + } + } + + sourceSets.main { + java.srcDir "src" + res.srcDir "res" + jniLibs.srcDir "libs" + manifest.srcFile "AndroidManifest.xml" + } + + externalNativeBuild { + ndkBuild { + if (!project.hasProperty("PROP_NDK_MODE") || PROP_NDK_MODE.compareTo('none') != 0) { + // skip the NDK Build step if PROP_NDK_MODE is none + path "jni/Android.mk" + } + } + } + + signingConfigs { + + release { + if (project.hasProperty("RELEASE_STORE_FILE")) { + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.release + } + + externalNativeBuild { + ndkBuild { + arguments 'NDK_DEBUG=0' + } + } + } + + debug { + externalNativeBuild { + ndkBuild { + arguments 'NDK_DEBUG=1' + } + } + } + } + +} + +android.featureVariants.all { variant -> + // delete previous files first + delete "${buildDir}/intermediates/assets/${variant.dirName}" + + variant.mergeAssets.doLast { + copy { + from "${buildDir}/../../../../../res" + into "${buildDir}/intermediates/assets/${variant.dirName}/res" + } + + copy { + from "${buildDir}/../../../../../src" + into "${buildDir}/intermediates/assets/${variant.dirName}/src" + } + + copy { + from "${buildDir}/../../../../../jsb-adapter" + into "${buildDir}/intermediates/assets/${variant.dirName}/jsb-adapter" + } + + copy { + from "${buildDir}/../../../../../main.js" + from "${buildDir}/../../../../../project.json" + into "${buildDir}/intermediates/assets/${variant.dirName}" + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation fileTree(dir: "../../../cocos2d-x/cocos/platform/android/java/libs", include: ['*.jar']) + implementation 'com.google.android.instantapps:instantapps:1.1.0' + implementation 'com.google.android.gms:play-services-instantapps:16.0.0' + implementation project(':libcocos2dx') +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Android.mk b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Android.mk new file mode 100755 index 0000000000..a151978ed2 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Android.mk @@ -0,0 +1,38 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := cocos2djs_shared + +LOCAL_MODULE_FILENAME := libcocos2djs + +ifeq ($(USE_ARM_MODE),1) +LOCAL_ARM_MODE := arm +endif + +LOCAL_SRC_FILES := hellojavascript/main.cpp \ + ../../../Classes/AppDelegate.cpp \ + ../../../Classes/jsb_module_register.cpp \ + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes + +ifeq ($(USE_ANY_SDK),1) +LOCAL_SRC_FILES += ../../../Classes/anysdk/SDKManager.cpp \ + ../../../Classes/anysdk/jsb_anysdk_basic_conversions.cpp \ + ../../../Classes/anysdk/manualanysdkbindings.cpp \ + ../../../Classes/anysdk/jsb_anysdk_protocols_auto.cpp + +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../Classes/anysdk + +LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic +endif + + +LOCAL_STATIC_LIBRARIES := cocos2dx_static + +LOCAL_EXPORT_CFLAGS := -DCOCOS2D_DEBUG=2 + +include $(BUILD_SHARED_LIBRARY) + + +$(call import-module, cocos) diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Application.mk b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Application.mk new file mode 100755 index 0000000000..f27ec63ec2 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/Application.mk @@ -0,0 +1,33 @@ +APP_STL := gnustl_static + +# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices +APP_ABI := armeabi-v7a + +APP_CPPFLAGS := -frtti -std=c++11 -fsigned-char +APP_LDFLAGS := -latomic + +# To solve windows commands char length too long +APP_SHORT_COMMANDS := true + +USE_ARM_MODE := 1 +USE_ANY_SDK := 1 + +ifeq ($(USE_ANY_SDK),1) +APP_CPPFLAGS += -DPACKAGE_AS +endif + +ifeq ($(NDK_DEBUG),1) + APP_CPPFLAGS += -DCOCOS2D_DEBUG=1 + APP_CFLAGS += -DCOCOS2D_DEBUG=1 + APP_OPTIM := debug +else + APP_CPPFLAGS += -DNDEBUG + APP_CFLAGS += -DNDEBUG + APP_OPTIM := release +endif + +# Some Android Simulators don't support SSE instruction, so disable it for x86 arch. +APP_CPPFLAGS += -U__SSE__ + +# Android instant apps flag +APP_CPPFLAGS += -DANDROID_INSTANT=1 diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/hellojavascript/main.cpp b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/hellojavascript/main.cpp new file mode 100755 index 0000000000..caeac73cd8 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/jni/hellojavascript/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "AppDelegate.h" +#include "cocos2d.h" +#include "platform/android/jni/JniHelper.h" +#include +#include +#if PACKAGE_AS +#include "PluginJniHelper.h" +#include "SDKManager.h" +#endif + +#define LOG_TAG "main" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +using namespace cocos2d; +#if PACKAGE_AS +using namespace anysdk::framework; +#endif + +//called when JNI_OnLoad() +void cocos_jni_env_init (JNIEnv* env) { + LOGD("cocos_jni_env_init"); +#if PACKAGE_AS + JavaVM *vm; + env->GetJavaVM(&vm); + PluginJniHelper::setJavaVM(vm); +#endif +} + +//called when onSurfaceCreated() +Application* cocos_android_app_init (JNIEnv* env, int width, int height) { + LOGD("cocos_android_app_init"); + auto app = new AppDelegate(width, height); + return app; +} + +extern "C" +{ + void Java_org_cocos2dx_javascript_SDKWrapper_nativeLoadAllPlugins(JNIEnv* env, jobject thiz) + { +#if PACKAGE_AS + SDKManager::getInstance()->loadAllPlugins(); +#endif + } +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/proguard-rules.pro b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-hdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-hdpi/ic_launcher.png new file mode 100755 index 0000000000..8aa4767c2f Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-hdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-mdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-mdpi/ic_launcher.png new file mode 100755 index 0000000000..d53fbdd8cb Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-mdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xhdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xhdpi/ic_launcher.png new file mode 100755 index 0000000000..2f72eac17f Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xxhdpi/ic_launcher.png b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xxhdpi/ic_launcher.png new file mode 100755 index 0000000000..1526615c02 Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/values/strings.xml b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/values/strings.xml new file mode 100755 index 0000000000..a88810e3a9 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/res/values/strings.xml @@ -0,0 +1,3 @@ + + HelloJavascript + diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/AppActivity.java b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/AppActivity.java new file mode 100755 index 0000000000..e46c46608a --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/AppActivity.java @@ -0,0 +1,145 @@ +/**************************************************************************** +Copyright (c) 2015-2016 Chukong Technologies Inc. +Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ +package org.cocos2dx.javascript; + +import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.Cocos2dxGLSurfaceView; + +import android.os.Bundle; +import org.cocos2dx.javascript.SDKWrapper; +import com.cocos.analytics.CAAgent; + +import android.content.Context; +import android.content.Intent; +import android.content.res.Configuration; + +public class AppActivity extends Cocos2dxActivity { + + @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.getInstance().init(this); + CAAgent.enableDebug(false); + } + + @Override + public Cocos2dxGLSurfaceView onCreateView() { + Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); + // TestCpp should create stencil buffer + glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); + + SDKWrapper.getInstance().setGLSurfaceView(glSurfaceView); + + return glSurfaceView; + } + + @Override + protected void onResume() { + super.onResume(); + SDKWrapper.getInstance().onResume(); + if (CAAgent.isInited()) + CAAgent.onResume(this); + } + + @Override + protected void onPause() { + super.onPause(); + SDKWrapper.getInstance().onPause(); + if (CAAgent.isInited()) + CAAgent.onPause(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + SDKWrapper.getInstance().onDestroy(); + if (CAAgent.isInited()) + CAAgent.onDestroy(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + SDKWrapper.getInstance().onActivityResult(requestCode, resultCode, data); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + SDKWrapper.getInstance().onNewIntent(intent); + } + + @Override + protected void onRestart() { + super.onRestart(); + SDKWrapper.getInstance().onRestart(); + } + + @Override + protected void onStop() { + super.onStop(); + SDKWrapper.getInstance().onStop(); + } + + @Override + public void onBackPressed() { + SDKWrapper.getInstance().onBackPressed(); + super.onBackPressed(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + SDKWrapper.getInstance().onConfigurationChanged(newConfig); + super.onConfigurationChanged(newConfig); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + SDKWrapper.getInstance().onRestoreInstanceState(savedInstanceState); + super.onRestoreInstanceState(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + SDKWrapper.getInstance().onSaveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + @Override + protected void onStart() { + SDKWrapper.getInstance().onStart(); + super.onStart(); + } +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/InstantHelper.java b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/InstantHelper.java new file mode 100644 index 0000000000..500c0377a3 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/src/org/cocos2dx/javascript/InstantHelper.java @@ -0,0 +1,114 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +package org.cocos2dx.javascript; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.util.Log; + +import com.google.android.gms.instantapps.InstantApps; +import com.google.android.gms.instantapps.PackageManagerCompat; + +public class InstantHelper { + private static final String TAG = "InstantHelper"; + private Context mCtx = null; + private static InstantHelper mHelper = null; + + public static InstantHelper getInstance() { + if (null == mHelper) { + mHelper = new InstantHelper(); + } + return mHelper; + } + + public void init(Context ctx) { + this.mCtx = ctx; + } + + private void _showInstallPrompt() { + Activity act = ((Activity) mCtx); + Uri a = act.getIntent().getData(); + Intent postInstallIntent = new Intent(Intent.ACTION_VIEW, a); + postInstallIntent.addCategory(Intent.CATEGORY_BROWSABLE); + com.google.android.instantapps.InstantApps.showInstallPrompt(act, postInstallIntent, 0, "AppActivity"); + } + + private boolean _isInstantApp() { + PackageManagerCompat compact = InstantApps.getPackageManagerCompat(mCtx); + return compact.isInstantApp(); + } + + private boolean _setInstantAppCookie(String ck) { + PackageManagerCompat compact = InstantApps.getPackageManagerCompat(mCtx); + if (null == ck || "null".equals(ck)) { + return compact.setInstantAppCookie(null); + } + return compact.setInstantAppCookie(ck.getBytes()); + } + + private String _getInstantAppCookie() { + String result; + PackageManagerCompat compact = InstantApps.getPackageManagerCompat(mCtx); + byte[] bt = compact.getInstantAppCookie(); + if (bt != null) { + result = new String(bt); + } else { + result = "null"; + } + return result; + } + + private int _getInstantAppCookieMaxSize() { + PackageManagerCompat compact = InstantApps.getPackageManagerCompat(mCtx); + return compact.getInstantAppCookieMaxSize(); + } + + public static boolean isInstantApp() { + return InstantHelper.getInstance()._isInstantApp(); + } + + public static String getInstantAppCookie() { + return InstantHelper.getInstance()._getInstantAppCookie(); + } + + public static boolean setInstantAppCookie(final String ck) { + return InstantHelper.getInstance()._setInstantAppCookie(ck); + } + + public static boolean clearInstantAppCookie() { + return InstantHelper.getInstance()._setInstantAppCookie(null); + } + + public static int getInstantAppCookieMaxSize() { + return InstantHelper.getInstance()._getInstantAppCookieMaxSize(); + } + + public static void showInstallPrompt() { + InstantHelper.getInstance()._showInstallPrompt(); + } +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle.properties b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle.properties new file mode 100755 index 0000000000..42616f98de --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle.properties @@ -0,0 +1,42 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true + +# Android SDK version that will be used as the compile project +PROP_COMPILE_SDK_VERSION=27 + +# Android SDK version that will be used as the earliest version of android this application can run on +PROP_MIN_SDK_VERSION=16 + +# Android SDK version that will be used as the latest version of android this application has been tested on +PROP_TARGET_SDK_VERSION=27 + +# Android Build Tools version that will be used as the compile project +PROP_BUILD_TOOLS_VERSION=27.0.3 + +# List of CPU Archtexture to build that application with +# Available architextures (armeabi-v7a | arm64-v8a | x86) +# To build for multiple architexture, use the `:` between them +# Example - PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86 +PROP_APP_ABI=armeabi-v7a + +# fill in sign information for release mode +RELEASE_STORE_FILE= +RELEASE_STORE_PASSWORD= +RELEASE_KEY_ALIAS= +RELEASE_KEY_PASSWORD= diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.jar b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.jar new file mode 100755 index 0000000000..8c0fb64a86 Binary files /dev/null and b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.jar differ diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.properties b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 0000000000..1c6b75e38f --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Oct 27 10:18:28 CST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew new file mode 100755 index 0000000000..91a7e269e1 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew.bat b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew.bat new file mode 100755 index 0000000000..8a0b282aa6 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/.gitignore b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/.gitignore @@ -0,0 +1 @@ +/build diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/build.gradle b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/build.gradle new file mode 100644 index 0000000000..a980b3cfa8 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/instantapp/build.gradle @@ -0,0 +1,5 @@ +apply plugin: 'com.android.instantapp' + +dependencies { + implementation project(':game') +} diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/settings.gradle b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/settings.gradle new file mode 100755 index 0000000000..6a2182e2e2 --- /dev/null +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/settings.gradle @@ -0,0 +1,4 @@ +include ':libcocos2dx',':game', ':instantapp' +project(':libcocos2dx').projectDir = new File(settingsDir, '../../cocos2d-x/cocos/platform/android/libcocos2dx') +include ':HelloJavascript' +project(':HelloJavascript').projectDir = new File(settingsDir, 'app') diff --git a/native/templates/js-template-android-instant/main.js b/native/templates/js-template-android-instant/main.js new file mode 100755 index 0000000000..12dd8b8770 --- /dev/null +++ b/native/templates/js-template-android-instant/main.js @@ -0,0 +1,92 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +/** + * A brief explanation for "project.json": + * Here is the content of project.json file, this is the global configuration for your game, you can modify it to customize some behavior. + * The detail of each field is under it. + { + "project_type": "javascript", + // "project_type" indicate the program language of your project, you can ignore this field + + "debugMode" : 1, + // "debugMode" possible values : + // 0 - No message will be printed. + // 1 - cc.error, cc.assert, cc.warn, cc.log will print in console. + // 2 - cc.error, cc.assert, cc.warn will print in console. + // 3 - cc.error, cc.assert will print in console. + // 4 - cc.error, cc.assert, cc.warn, cc.log will print on canvas, available only on web. + // 5 - cc.error, cc.assert, cc.warn will print on canvas, available only on web. + // 6 - cc.error, cc.assert will print on canvas, available only on web. + + "showFPS" : true, + // Left bottom corner fps information will show when "showFPS" equals true, otherwise it will be hide. + + "frameRate" : 60, + // "frameRate" set the wanted frame rate for your game, but the real fps depends on your game implementation and the running environment. + + "id" : "gameCanvas", + // "gameCanvas" sets the id of your canvas element on the web page, it's useful only on web. + + "renderMode" : 0, + // "renderMode" sets the renderer type, only useful on web : + // 0 - Automatically chosen by engine + // 1 - Forced to use canvas renderer + // 2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers + + "engineDir" : "frameworks/cocos2d-html5/", + // (Deprecated) In debug mode, if you use the whole engine to develop your game, you should specify its relative path with "engineDir", + // but if you are using a single engine file, you can ignore it. + + "modules" : ["cocos2d"], + // "modules" defines which modules you will need in your game, it's useful only on web, + // using this can greatly reduce your game's resource size, and the cocos console tool can package your game with only the modules you set. + // For details about modules definitions, you can refer to "../../frameworks/cocos2d-html5/modulesConfig.json". + + "jsList" : [ + ] + // "jsList" sets the list of js files in your game. + } + * + */ + +cc.game.onStart = function(){ + if(!cc.sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it + document.body.removeChild(document.getElementById("cocosLoading")); + + // Pass true to enable retina display, disabled by default to improve performance + cc.view.enableRetina(false); + // Adjust viewport meta + cc.view.adjustViewPort(true); + // Setup the resolution policy and design resolution size + cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.SHOW_ALL); + // The game will be resized when browser size change + cc.view.resizeWithBrowserSize(true); + //load resources + cc.LoaderScene.preload(g_resources, function () { + cc.director.runScene(new HelloWorldScene()); + }, this); +}; +cc.game.run(); \ No newline at end of file diff --git a/native/templates/js-template-android-instant/project.json b/native/templates/js-template-android-instant/project.json new file mode 100755 index 0000000000..e54f870660 --- /dev/null +++ b/native/templates/js-template-android-instant/project.json @@ -0,0 +1,17 @@ +{ + "project_type": "javascript", + + "debugMode" : 1, + "showFPS" : true, + "frameRate" : 60, + "id" : "gameCanvas", + "renderMode" : 0, + "engineDir":"frameworks/cocos2d-html5", + + "modules" : ["cocos2d"], + + "jsList" : [ + "src/resource.js", + "src/app.js" + ] +} diff --git a/native/templates/js-template-android-instant/res/CloseNormal.png b/native/templates/js-template-android-instant/res/CloseNormal.png new file mode 100755 index 0000000000..5657a13b58 Binary files /dev/null and b/native/templates/js-template-android-instant/res/CloseNormal.png differ diff --git a/native/templates/js-template-android-instant/res/CloseSelected.png b/native/templates/js-template-android-instant/res/CloseSelected.png new file mode 100755 index 0000000000..e4c82da775 Binary files /dev/null and b/native/templates/js-template-android-instant/res/CloseSelected.png differ diff --git a/native/templates/js-template-android-instant/res/HelloWorld.png b/native/templates/js-template-android-instant/res/HelloWorld.png new file mode 100755 index 0000000000..3a20f2538a Binary files /dev/null and b/native/templates/js-template-android-instant/res/HelloWorld.png differ diff --git a/native/templates/js-template-android-instant/res/favicon.ico b/native/templates/js-template-android-instant/res/favicon.ico new file mode 100755 index 0000000000..1ad6a0907b Binary files /dev/null and b/native/templates/js-template-android-instant/res/favicon.ico differ diff --git a/native/templates/js-template-android-instant/res/loading.js b/native/templates/js-template-android-instant/res/loading.js new file mode 100755 index 0000000000..0a653601fb --- /dev/null +++ b/native/templates/js-template-android-instant/res/loading.js @@ -0,0 +1,26 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +(function(){var createStyle=function(){return".cocosLoading{position:absolute;margin:-30px -60px;padding:0;top:50%;left:50%}"+".cocosLoading ul{margin:0;padding:0;}"+".cocosLoading span{color:#FFF;text-align:center;display:block;}"+".cocosLoading li{list-style:none;float:left;border-radius:15px;width:15px;height:15px;background:#FFF;margin:5px 0 0 10px}"+".cocosLoading li .ball,.cocosLoading li .unball{background-color:#2187e7;background-image:-moz-linear-gradient(90deg,#2187e7 25%,#a0eaff);background-image:-webkit-linear-gradient(90deg,#2187e7 25%,#a0eaff);width:15px;height:15px;border-radius:50px}"+".cocosLoading li .ball{transform:scale(0);-moz-transform:scale(0);-webkit-transform:scale(0);animation:showDot 1s linear forwards;-moz-animation:showDot 1s linear forwards;-webkit-animation:showDot 1s linear forwards}"+".cocosLoading li .unball{transform:scale(1);-moz-transform:scale(1);-webkit-transform:scale(1);animation:hideDot 1s linear forwards;-moz-animation:hideDot 1s linear forwards;-webkit-animation:hideDot 1s linear forwards}"+"@keyframes showDot{0%{transform:scale(0,0)}100%{transform:scale(1,1)}}"+"@-moz-keyframes showDot{0%{-moz-transform:scale(0,0)}100%{-moz-transform:scale(1,1)}}"+"@-webkit-keyframes showDot{0%{-webkit-transform:scale(0,0)}100%{-webkit-transform:scale(1,1)}}"+"@keyframes hideDot{0%{transform:scale(1,1)}100%{transform:scale(0,0)}}"+"@-moz-keyframes hideDot{0%{-moz-transform:scale(1,1)}100%{-moz-transform:scale(0,0)}}"+"@-webkit-keyframes hideDot{0%{-webkit-transform:scale(1,1)}100%{-webkit-transform:scale(0,0)}}"};var createDom=function(id,num){id=id||"cocosLoading";num=num||5;var i,item;var div=document.createElement("div");div.className="cocosLoading";div.id=id;var bar=document.createElement("ul");var list=[];for(i=0;i=list.length){direction=!direction;index=0;time=1000}else{time=300}animation()},time)};animation()};(function(){var bgColor=document.body.style.background;document.body.style.background="#000";var style=document.createElement("style");style.type="text/css";style.innerHTML=createStyle();document.head.appendChild(style);var list=createDom();startAnimation(list,function(){var div=document.getElementById("cocosLoading");if(!div){document.body.style.background=bgColor}return !!div})})()})(); \ No newline at end of file diff --git a/native/templates/js-template-android-instant/src/app.js b/native/templates/js-template-android-instant/src/app.js new file mode 100755 index 0000000000..eb4fd362e1 --- /dev/null +++ b/native/templates/js-template-android-instant/src/app.js @@ -0,0 +1,103 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + + +var HelloWorldLayer = cc.Layer.extend({ + sprite:null, + ctor:function () { + ////////////////////////////// + // 1. super init first + this._super(); + + ///////////////////////////// + // 2. add a menu item with "X" image, which is clicked to quit the program + // you may modify it. + // ask the window size + var size = cc.winSize; + + // add a "close" icon to exit the progress. it's an autorelease object + var closeItem = new cc.MenuItemImage( + res.CloseNormal_png, + res.CloseSelected_png, + function () { + cc.log("Menu is clicked!"); + }, this); + closeItem.attr({ + x: size.width - 20, + y: 20, + anchorX: 0.5, + anchorY: 0.5 + }); + + var menu = new cc.Menu(closeItem); + menu.x = 0; + menu.y = 0; + this.addChild(menu, 1); + + ///////////////////////////// + // 3. add your codes below... + // add a label shows "Hello World" + // create and initialize a label + var helloLabel = new cc.LabelTTF("Hello World", "Arial", 38); + // position the label on the center of the screen + helloLabel.x = size.width / 2; + helloLabel.y = 0; + // add the label as a child to this layer + this.addChild(helloLabel, 5); + + // add "HelloWorld" splash screen" + this.sprite = new cc.Sprite(res.HelloWorld_png); + this.sprite.attr({ + x: size.width / 2, + y: size.height / 2, + scale: 0.5, + rotation: 180 + }); + this.addChild(this.sprite, 0); + + this.sprite.runAction( + cc.sequence( + cc.rotateTo(2, 0), + cc.scaleTo(2, 1, 1) + ) + ); + helloLabel.runAction( + cc.spawn( + cc.moveBy(2.5, cc.p(0, size.height - 40)), + cc.tintTo(2.5,255,125,0) + ) + ); + return true; + } +}); + +var HelloWorldScene = cc.Scene.extend({ + onEnter:function () { + this._super(); + var layer = new HelloWorldLayer(); + this.addChild(layer); + } +}); + diff --git a/native/templates/js-template-android-instant/src/resource.js b/native/templates/js-template-android-instant/src/resource.js new file mode 100755 index 0000000000..35f6d4c324 --- /dev/null +++ b/native/templates/js-template-android-instant/src/resource.js @@ -0,0 +1,35 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +var res = { + HelloWorld_png : "res/HelloWorld.png", + CloseNormal_png : "res/CloseNormal.png", + CloseSelected_png : "res/CloseSelected.png" +}; + +var g_resources = []; +for (var i in res) { + g_resources.push(res[i]); +} \ No newline at end of file