diff --git a/.DS_Store b/.DS_Store index 4c8349b..bb2a1d4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/assets/btn_click.ts b/assets/btn_click.ts index 8b8f05a..11bb6d0 100644 --- a/assets/btn_click.ts +++ b/assets/btn_click.ts @@ -1,4 +1,4 @@ -import { _decorator, Component, Node, native } from "cc"; +import { _decorator, Component, Node, native,sys } from "cc"; const { ccclass, property } = _decorator; import { createRequestData } from "./WalletSdkUtils"; @@ -21,11 +21,20 @@ export class btn_click extends Component { */ public btn_onclick1() { console.info("点击了按钮"); - var ret = native.reflection.callStaticMethod( - "JSHandleClass", - "walleConnectFun:", - "imtokenv2" - ); + if (sys.platform == sys.Platform.ANDROID) { + var ret = native.reflection.callStaticMethod( + 'com/cocos/game/AppActivity', + "initWallet", + "()V" + ); + } else if (sys.platform == sys.Platform.IOS) { + var ret = native.reflection.callStaticMethod( + "JSHandleClass", + "walleConnectFun:", + "imtokenv2" + ); + } + } //发送交易 @@ -37,18 +46,33 @@ export class btn_click extends Component { "Mint", "0x4eDE150f62dc21aDC0F39a2A02c95A5Cc1FD7B2C", ); - var jsonObj = { - "method": "eth_sendTransaction", - "params": JSON.stringify(temp) - }; - var jsonStr = JSON.stringify(jsonObj); - ///0x2eB535d54382eA5CED9183899916A9d39e093877 - - var ret = native.reflection.callStaticMethod( - "JSHandleClass", - "sendContractFun:", - jsonStr - ); + if (sys.platform == sys.Platform.ANDROID) { + var ret = native.reflection.callStaticMethod( + 'com/cocos/game/AppActivity', + 'sendCustomMessage', + '(Ljava/lang/String;)Ljava/lang/String;', + JSON.stringify({ + method: 'eth_sendTransaction', + params: [ + temp + ], + }) + ); + } else if (sys.platform == sys.Platform.IOS) { + var jsonObj = { + "method": "eth_sendTransaction", + "params": JSON.stringify(temp) + }; + var jsonStr = JSON.stringify(jsonObj); + ///0x2eB535d54382eA5CED9183899916A9d39e093877 + + var ret = native.reflection.callStaticMethod( + "JSHandleClass", + "sendContractFun:", + jsonStr + ); + } + } public async btn_onclick3() { // console.info("点击了按钮"); diff --git a/native/.DS_Store b/native/.DS_Store index 139a048..1d97f0f 100644 Binary files a/native/.DS_Store and b/native/.DS_Store differ diff --git a/native/engine/.DS_Store b/native/engine/.DS_Store index 4dd4f2e..31e896f 100644 Binary files a/native/engine/.DS_Store and b/native/engine/.DS_Store differ diff --git a/native/engine/android/.DS_Store b/native/engine/android/.DS_Store new file mode 100644 index 0000000..99f81d5 Binary files /dev/null and b/native/engine/android/.DS_Store differ diff --git a/native/engine/android/CMakeLists.txt b/native/engine/android/CMakeLists.txt new file mode 100755 index 0000000..39a67f3 --- /dev/null +++ b/native/engine/android/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.8) + +option(APP_NAME "Project Name" "cocos_demo_3") +project(${APP_NAME} CXX) +set(CC_LIB_NAME cocos) +set(CC_PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(CC_PROJ_SOURCES) +set(CC_COMMON_SOURCES) +set(CC_ALL_SOURCES) + +include(${CMAKE_CURRENT_LIST_DIR}/../common/CMakeLists.txt) + +cc_android_before_target(${CC_LIB_NAME}) +add_library(${CC_LIB_NAME} SHARED ${CC_ALL_SOURCES}) +cc_android_after_target(${CC_LIB_NAME}) diff --git a/native/engine/android/Post-service.cmake b/native/engine/android/Post-service.cmake new file mode 100644 index 0000000..16fd033 --- /dev/null +++ b/native/engine/android/Post-service.cmake @@ -0,0 +1 @@ +# Supported for Cocos Service! \ No newline at end of file diff --git a/native/engine/android/Pre-service.cmake b/native/engine/android/Pre-service.cmake new file mode 100644 index 0000000..16fd033 --- /dev/null +++ b/native/engine/android/Pre-service.cmake @@ -0,0 +1 @@ +# Supported for Cocos Service! \ No newline at end of file diff --git a/native/engine/android/app/.DS_Store b/native/engine/android/app/.DS_Store new file mode 100644 index 0000000..ee0ccef Binary files /dev/null and b/native/engine/android/app/.DS_Store differ diff --git a/native/engine/android/app/AndroidManifest.xml b/native/engine/android/app/AndroidManifest.xml new file mode 100644 index 0000000..9f5c4f5 --- /dev/null +++ b/native/engine/android/app/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/native/engine/android/app/build.gradle b/native/engine/android/app/build.gradle new file mode 100644 index 0000000..f199209 --- /dev/null +++ b/native/engine/android/app/build.gradle @@ -0,0 +1,115 @@ +import org.apache.tools.ant.taskdefs.condition.Os + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +RES_PATH = RES_PATH.replace("\\", "/") +COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/") + +buildDir = "${RES_PATH}/proj/build/$project.name" +android { + compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() + buildToolsVersion PROP_BUILD_TOOLS_VERSION + ndkPath PROP_NDK_PATH + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + applicationId APPLICATION_ID + minSdkVersion PROP_MIN_SDK_VERSION + targetSdkVersion PROP_TARGET_SDK_VERSION + versionCode 1 + versionName "1.0" + + externalNativeBuild { + cmake { + targets "cocos" + arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=gold" + } + ndk { abiFilters PROP_APP_ABI.split(':') } + } + } + + sourceSets.main { + java.srcDirs "../src", "src" + res.srcDirs "../res", 'res' + jniLibs.srcDirs "../libs", 'libs' + manifest.srcFile "AndroidManifest.xml" + assets.srcDir "${RES_PATH}/data" + jniLibs { + // Vulkan validation layer + // srcDir "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs" + } + } + + externalNativeBuild { + cmake { + path "../CMakeLists.txt" + buildStagingDirectory "${RES_PATH}/proj/build" + } + } + + signingConfigs { + + release { + if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) { + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD + } + } + } + + buildTypes { + release { + debuggable false + jniDebuggable false + renderscriptDebuggable false + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.release + } + // resValue "string", "app_name", PROP_APP_NAME + } + + debug { + debuggable true + jniDebuggable true + renderscriptDebuggable true + // resValue "string", "app_name", "${PROP_APP_NAME}-dbg" + // applicationIdSuffix ".debug" + } + } +} + +dependencies { + implementation fileTree(dir: '../libs', include: ['*.jar','*.aar']) + implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) + implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar']) + implementation project(':libservice') + implementation project(':libcocos') + + implementation "org.java-websocket:Java-WebSocket:1.4.0" + + implementation "com.github.komputing:khex:1.0.0-RC6" + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin" + + implementation 'com.github.WalletConnect:kotlin-walletconnect-lib:0.9.6' + + implementation "androidx.appcompat:appcompat:$versions.androidx_app_compat" + implementation "androidx.multidex:multidex:$versions.multidex" + + implementation 'com.squareup.moshi:moshi:1.8.0' + implementation "com.squareup.okhttp3:okhttp:$versions.okhttp" + + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0' + + implementation 'com.google.code.gson:gson:2.9.1' +} diff --git a/native/engine/android/app/proguard-rules.pro b/native/engine/android/app/proguard-rules.pro new file mode 100644 index 0000000..dbb43fb --- /dev/null +++ b/native/engine/android/app/proguard-rules.pro @@ -0,0 +1,42 @@ +# 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 *; +#} + +# Proguard Cocos2d-x-lite for release +-keep public class com.cocos.** { *; } +-dontwarn com.cocos.** + +# Proguard Apache HTTP for release +-keep class org.apache.http.** { *; } +-dontwarn org.apache.http.** + +# Proguard okhttp for release +-keep class okhttp3.** { *; } +-dontwarn okhttp3.** + +-keep class okio.** { *; } +-dontwarn okio.** + +# Proguard Android Webivew for release. you can comment if you are not using a webview +-keep public class android.net.http.SslError +-keep public class android.webkit.WebViewClient + +-keep public class com.google.** { *; } + +-dontwarn android.webkit.WebView +-dontwarn android.net.http.SslError +-dontwarn android.webkit.WebViewClient diff --git a/native/engine/android/app/src/.DS_Store b/native/engine/android/app/src/.DS_Store new file mode 100644 index 0000000..40a1e2a Binary files /dev/null and b/native/engine/android/app/src/.DS_Store differ diff --git a/native/engine/android/app/src/com/.DS_Store b/native/engine/android/app/src/com/.DS_Store new file mode 100644 index 0000000..9044e66 Binary files /dev/null and b/native/engine/android/app/src/com/.DS_Store differ diff --git a/native/engine/android/app/src/com/cocos/.DS_Store b/native/engine/android/app/src/com/cocos/.DS_Store new file mode 100644 index 0000000..c258f59 Binary files /dev/null and b/native/engine/android/app/src/com/cocos/.DS_Store differ diff --git a/native/engine/android/app/src/com/cocos/game/.DS_Store b/native/engine/android/app/src/com/cocos/game/.DS_Store new file mode 100644 index 0000000..f3711bc Binary files /dev/null and b/native/engine/android/app/src/com/cocos/game/.DS_Store differ diff --git a/native/engine/android/app/src/com/cocos/game/AppActivity.kt b/native/engine/android/app/src/com/cocos/game/AppActivity.kt new file mode 100644 index 0000000..5a5f747 --- /dev/null +++ b/native/engine/android/app/src/com/cocos/game/AppActivity.kt @@ -0,0 +1,250 @@ +@file:JvmName("AppActivity") +/**************************************************************************** + * 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 com.cocos.game + +import android.content.res.Configuration + +import com.cocos.service.SDKWrapper +import com.cocos.lib.CocosActivity + +import android.os.Bundle +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.view.View +import com.example.walletconnect_demo.server.BridgeServer +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import okhttp3.OkHttpClient +import org.komputing.khex.extensions.toNoPrefixHexString +import org.walletconnect.Session +import org.walletconnect.impls.* +import org.walletconnect.nullOnThrow +import java.io.File +import java.util.* +import com.google.gson.Gson +import kotlinx.coroutines.launch +import com.squareup.moshi.Moshi + +public class AppActivity : CocosActivity(), Session.Callback { + override fun onCreate(savedInstanceState: Bundle?) { + 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) +// initBridge() + initMoshi() + initClient() + initSessionStorage() + + instance = this; + } + + override fun onStatus(status: Session.Status) { + when(status) { + Session.Status.Approved -> sessionApproved() + Session.Status.Closed -> sessionClosed() + Session.Status.Connected, + Session.Status.Disconnected, + is Session.Status.Error -> { + // Do Stuff + } + } + } + + override fun onMethodCall(call: Session.MethodCall) { + } + + private fun sessionApproved() { + println("--------sessionApproved--------------") + println(session.approvedAccounts()) + + } + + private fun sessionClosed() { + println("--------sessionClosed--------------") + println(session.approvedAccounts()) + } + + private fun initClient() { + client = OkHttpClient.Builder().build() + } + + private fun initMoshi() { + moshi = Moshi.Builder().build() + } + + private fun initBridge() { + bridge = BridgeServer(moshi) + bridge.start() + } + + private fun initSessionStorage() { + storage = FileWCSessionStore(File(cacheDir, "session_store.json").apply { createNewFile() }, moshi) + } + + override fun onResume() { + super.onResume() + SDKWrapper.shared().onResume() + } + + override fun onPause() { + super.onPause() + SDKWrapper.shared().onPause() + } + + override fun onDestroy() { + super.onDestroy() + // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508 + if (!isTaskRoot()) { + return + } + SDKWrapper.shared().onDestroy() + } + +// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { +// super.onActivityResult(requestCode, resultCode, data) +// SDKWrapper.shared().onActivityResult(requestCode, resultCode, data) +// } + + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + SDKWrapper.shared().onNewIntent(intent) + } + + override fun onRestart() { + super.onRestart() + SDKWrapper.shared().onRestart() + } + + override fun onStop() { + super.onStop() + SDKWrapper.shared().onStop() + } + + override fun onBackPressed() { + SDKWrapper.shared().onBackPressed() + super.onBackPressed() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + SDKWrapper.shared().onConfigurationChanged(newConfig) + super.onConfigurationChanged(newConfig) + } + + override protected fun onRestoreInstanceState(savedInstanceState: Bundle) { + SDKWrapper.shared().onRestoreInstanceState(savedInstanceState) + super.onRestoreInstanceState(savedInstanceState) + } + + override protected fun onSaveInstanceState(outState: Bundle) { + SDKWrapper.shared().onSaveInstanceState(outState) + super.onSaveInstanceState(outState) + } + + override protected fun onStart() { + SDKWrapper.shared().onStart() + super.onStart() + } + + + override fun onLowMemory() { + SDKWrapper.shared().onLowMemory() + super.onLowMemory() + } + + fun test(){ + } + + companion object { + lateinit var instance: AppActivity ; + private lateinit var client: OkHttpClient + private lateinit var moshi: Moshi + private lateinit var bridge: BridgeServer + private lateinit var storage: WCSessionStore + lateinit var config: Session.Config + lateinit var session: Session + + fun resetSession() { + nullOnThrow { session }?.clearCallbacks() + val key = ByteArray(32).also { Random().nextBytes(it) }.toNoPrefixHexString() + config = Session.Config(UUID.randomUUID().toString(), "https://bridge.walletconnect.org/", key) + session = WCSession(config, + MoshiPayloadAdapter(moshi), + storage, + OkHttpTransport.Builder(client, moshi), + Session.PeerMeta(name = "Example App") + ) + session.offer() + } + @JvmStatic public fun initWallet() { + println("--------initWallet--------------") + resetSession() + session.addCallback(instance) + val i = Intent(Intent.ACTION_VIEW) + i.data = Uri.parse(config.toWCUri()) + instance.startActivity(i) + // instance.test() + } + ///解析庄给的json字符串 并且使用custom方法发送给钱包 + @JvmStatic public fun sendCustomMessage(jsonStr:String):String{ + ///解析成实体类 + var str = Gson().fromJson(jsonStr,argsModel::class.java); + session.performMethodCall( + Session.MethodCall.Custom( + System.currentTimeMillis(), + str.method!!, + str.params!!, + ), + ::handleResponse + ) + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse("wc:") + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + instance.startActivity(intent) + return "ok" + } + private fun handleResponse(resp: Session.MethodCall.Response) { + println(resp.result as? String) + } + } +} +class argsModel { + var method: String? = null + var params: List? = null + + override fun toString(): String { + return "argsModel(method=$method, params=$params)" + } +} + diff --git a/native/engine/android/app/src/com/cocos/game/Server/BridgeServer.kt b/native/engine/android/app/src/com/cocos/game/Server/BridgeServer.kt new file mode 100644 index 0000000..3a94b83 --- /dev/null +++ b/native/engine/android/app/src/com/cocos/game/Server/BridgeServer.kt @@ -0,0 +1,98 @@ +package com.example.walletconnect_demo.server + + +import android.util.Log +import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import org.java_websocket.WebSocket +import org.java_websocket.handshake.ClientHandshake +import org.java_websocket.server.WebSocketServer +import java.lang.Exception +import java.lang.ref.WeakReference +import java.net.InetSocketAddress +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) { + + private val adapter = moshi.adapter>( + Types.newParameterizedType( + Map::class.java, + String::class.java, + String::class.java + ) + ) + + private val pubs: MutableMap>> = ConcurrentHashMap() + private val pubsLock = Any() + private val pubsCache: MutableMap = ConcurrentHashMap() + + override fun onOpen(conn: WebSocket?, handshake: ClientHandshake?) { + Log.d("#####", "onOpen: ${conn?.remoteSocketAddress?.address?.hostAddress}") + } + + override fun onClose(conn: WebSocket?, code: Int, reason: String?, remote: Boolean) { + Log.d("#####", "onClose: ${conn?.remoteSocketAddress?.address?.hostAddress}") + conn?.let { cleanUpSocket(it) } + } + + override fun onMessage(conn: WebSocket?, message: String?) { + Log.d("#####", "Message: $message") + try { + conn ?: error("Unknown socket") + message?.also { + val msg = adapter.fromJson(it) ?: error("Invalid message") + val type: String = msg["type"] ?: error("Type not found") + val topic: String = msg["topic"] ?: error("Topic not found") + when (type) { + "pub" -> { + var sendMessage = false + pubs[topic]?.forEach { r -> + r.get()?.apply { + send(message) + sendMessage = true + } + } + if (!sendMessage) { + Log.d("#####", "Cache message: $message") + pubsCache[topic] = message + } + } + "sub" -> { + pubs.getOrPut(topic, { mutableListOf() }).add(WeakReference(conn)) + pubsCache[topic]?.let { cached -> + Log.d("#####", "Send cached: $cached") + conn.send(cached) + } + } + else -> error("Unknown type") + } + } + } catch (e: Exception) { + e.printStackTrace() + } + } + + override fun onStart() { + Log.d("#####", "Server started") + connectionLostTimeout = 0 + } + + override fun onError(conn: WebSocket?, ex: Exception?) { + Log.d("#####", "onError") + ex?.printStackTrace() + conn?.let { cleanUpSocket(it) } + } + + private fun cleanUpSocket(conn: WebSocket) { + synchronized(pubsLock) { + pubs.forEach { + it.value.removeAll { r -> r.get().let { v -> v == null || v == conn } } + } + } + } + + companion object { + val PORT = 5000 + Random().nextInt(60000) + } +} \ No newline at end of file diff --git a/native/engine/android/build-cfg.json b/native/engine/android/build-cfg.json new file mode 100644 index 0000000..fb658e2 --- /dev/null +++ b/native/engine/android/build-cfg.json @@ -0,0 +1,8 @@ +{ + "ndk_module_path" :[ + "${COCOS_ROOT}", + "${COCOS_ROOT}/cocos", + "${COCOS_ROOT}/external" + ], + "copy_resources": [] +} diff --git a/native/engine/android/build.gradle b/native/engine/android/build.gradle new file mode 100644 index 0000000..88ad761 --- /dev/null +++ b/native/engine/android/build.gradle @@ -0,0 +1,63 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext { + versions = [ + kotlin : "1.4.31", + moshi : '1.8.0', + okhttp : '3.11.0', + jupiter : '5.7.0', + + 'minSdk' : 14, + 'compileSdk' : 28, + 'buildTools' : '28.0.3', + 'androidPlugin' : '3.4.0', + + androidx_app_compat : '1.0.2', + androidx_card_view : '1.0.0', + androidx_constraint_layout: '1.1.3', + androidx_lifecycle : '2.0.0', + androidx_test_ext : '1.1.0', + androidx_recycler_view : '1.0.0', + androidx_room : '2.0.0', + + multidex : '2.0.1', + ] + + ext.deps = [ + android: [ + 'runtime' : 'com.google.android:android:4.1.1.4', + 'gradlePlugin': "com.android.tools.build:gradle:${versions.androidPlugin}", + ] + ] + } + repositories { + google() + jcenter() + maven { url="https://jitpack.io" } + } + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" + classpath "org.jetbrains.kotlin:kotlin-android-extensions:$versions.kotlin" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + flatDir { + dirs 'libs' + } + mavenCentral() + maven { url "https://jitpack.io" } + } +} + + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/native/engine/android/gradle/.DS_Store b/native/engine/android/gradle/.DS_Store new file mode 100644 index 0000000..e4651c9 Binary files /dev/null and b/native/engine/android/gradle/.DS_Store differ diff --git a/native/engine/android/gradle/wrapper/gradle-wrapper.jar b/native/engine/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/native/engine/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/native/engine/android/gradle/wrapper/gradle-wrapper.properties b/native/engine/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..32af2dc --- /dev/null +++ b/native/engine/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Sep 05 15:37:26 CST 2022 +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/engine/android/instantapp/AndroidManifest.xml b/native/engine/android/instantapp/AndroidManifest.xml new file mode 100644 index 0000000..15f7b34 --- /dev/null +++ b/native/engine/android/instantapp/AndroidManifest.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/native/engine/android/instantapp/build.gradle b/native/engine/android/instantapp/build.gradle new file mode 100644 index 0000000..1d322ae --- /dev/null +++ b/native/engine/android/instantapp/build.gradle @@ -0,0 +1,93 @@ +import org.apache.tools.ant.taskdefs.condition.Os + +apply plugin: 'com.android.application' + +RES_PATH = RES_PATH.replace("\\", "/") +COCOS_ENGINE_PATH = COCOS_ENGINE_PATH.replace("\\", "/") +buildDir = "${RES_PATH}/proj/build/$project.name" + +android { + compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() + buildToolsVersion PROP_BUILD_TOOLS_VERSION + ndkPath PROP_NDK_PATH + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + applicationId "com.example.walletconnect_demo" + minSdkVersion PROP_MIN_SDK_VERSION + targetSdkVersion PROP_TARGET_SDK_VERSION + versionCode 1 + versionName "1.0" + + externalNativeBuild { + cmake { + targets "cocos" + arguments "-DRES_DIR=${RES_PATH}", "-DCOCOS_X_PATH=${COCOS_ENGINE_PATH}","-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_LD=gold" + cppFlags "-frtti -fexceptions -fsigned-char -DANDROID_INSTANT=1" + } + ndk { abiFilters PROP_APP_ABI.split(':') } + } + } + + sourceSets.main { + java.srcDirs "../src", "src" + res.srcDirs "../res", 'res' + jniLibs.srcDirs "../libs", 'libs' + manifest.srcFile "AndroidManifest.xml" + assets.srcDir "${RES_PATH}/data" + } + + externalNativeBuild { + cmake { + path "../CMakeLists.txt" + buildStagingDirectory "${RES_PATH}/proj/build" + } + } + + signingConfigs { + + release { + if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) { + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD + } + } + } + + buildTypes { + release { + debuggable false + jniDebuggable false + renderscriptDebuggable false + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.release + } + // resValue "string", "app_name", PROP_APP_NAME + } + + debug { + debuggable true + jniDebuggable true + renderscriptDebuggable true + // resValue "string", "app_name", "${PROP_APP_NAME}-dbg" + // applicationIdSuffix ".debug" + } + } +} + +dependencies { + implementation fileTree(dir: '../libs', include: ['*.jar','*.aar']) + implementation fileTree(dir: 'libs', include: ['*.jar','*.aar']) + implementation fileTree(dir: "${COCOS_ENGINE_PATH}/cocos/platform/android/java/libs", include: ['*.jar']) + implementation project(':libservice') + implementation project(':libcocos') +} diff --git a/native/engine/android/instantapp/proguard-rules.pro b/native/engine/android/instantapp/proguard-rules.pro new file mode 100644 index 0000000..dbb43fb --- /dev/null +++ b/native/engine/android/instantapp/proguard-rules.pro @@ -0,0 +1,42 @@ +# 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 *; +#} + +# Proguard Cocos2d-x-lite for release +-keep public class com.cocos.** { *; } +-dontwarn com.cocos.** + +# Proguard Apache HTTP for release +-keep class org.apache.http.** { *; } +-dontwarn org.apache.http.** + +# Proguard okhttp for release +-keep class okhttp3.** { *; } +-dontwarn okhttp3.** + +-keep class okio.** { *; } +-dontwarn okio.** + +# Proguard Android Webivew for release. you can comment if you are not using a webview +-keep public class android.net.http.SslError +-keep public class android.webkit.WebViewClient + +-keep public class com.google.** { *; } + +-dontwarn android.webkit.WebView +-dontwarn android.net.http.SslError +-dontwarn android.webkit.WebViewClient diff --git a/native/engine/android/instantapp/src/com/cocos/game/InstantActivity.java b/native/engine/android/instantapp/src/com/cocos/game/InstantActivity.java new file mode 100644 index 0000000..318e839 --- /dev/null +++ b/native/engine/android/instantapp/src/com/cocos/game/InstantActivity.java @@ -0,0 +1,125 @@ +/**************************************************************************** +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 com.cocos.game; + +import android.os.Bundle; +import android.content.Intent; +import android.content.res.Configuration; + +import com.cocos.service.SDKWrapper; +import com.cocos.lib.CocosActivity; + +public class InstantActivity extends CocosActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // DO OTHER INITIALIZATION BELOW + SDKWrapper.shared().init(this); + + } + + @Override + protected void onResume() { + super.onResume(); + SDKWrapper.shared().onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + SDKWrapper.shared().onPause(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + // Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508 + if (!isTaskRoot()) { + return; + } + SDKWrapper.shared().onDestroy(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + SDKWrapper.shared().onActivityResult(requestCode, resultCode, data); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + SDKWrapper.shared().onNewIntent(intent); + } + + @Override + protected void onRestart() { + super.onRestart(); + SDKWrapper.shared().onRestart(); + } + + @Override + protected void onStop() { + super.onStop(); + SDKWrapper.shared().onStop(); + } + + @Override + public void onBackPressed() { + SDKWrapper.shared().onBackPressed(); + super.onBackPressed(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + SDKWrapper.shared().onConfigurationChanged(newConfig); + super.onConfigurationChanged(newConfig); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + SDKWrapper.shared().onRestoreInstanceState(savedInstanceState); + super.onRestoreInstanceState(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + SDKWrapper.shared().onSaveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + @Override + protected void onStart() { + SDKWrapper.shared().onStart(); + super.onStart(); + } + + @Override + public void onLowMemory() { + SDKWrapper.shared().onLowMemory(); + super.onLowMemory(); + } +} diff --git a/native/engine/android/jni/main.cpp b/native/engine/android/jni/main.cpp new file mode 100644 index 0000000..3fa0653 --- /dev/null +++ b/native/engine/android/jni/main.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** + Copyright (c) 2017-2020 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 "Game.h" + +cc::Application *cocos_main(int width, int height) { + return new Game(width, height); +} diff --git a/native/engine/android/res/mipmap-hdpi/ic_launcher.png b/native/engine/android/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..888c0d5 Binary files /dev/null and b/native/engine/android/res/mipmap-hdpi/ic_launcher.png differ diff --git a/native/engine/android/res/mipmap-mdpi/ic_launcher.png b/native/engine/android/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..d5e3c77 Binary files /dev/null and b/native/engine/android/res/mipmap-mdpi/ic_launcher.png differ diff --git a/native/engine/android/res/mipmap-xhdpi/ic_launcher.png b/native/engine/android/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..2b6f32a Binary files /dev/null and b/native/engine/android/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/native/engine/android/res/mipmap-xxhdpi/ic_launcher.png b/native/engine/android/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..2f1e5a6 Binary files /dev/null and b/native/engine/android/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/native/engine/android/res/mipmap-xxxhdpi/ic_launcher.png b/native/engine/android/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..a9ebc79 Binary files /dev/null and b/native/engine/android/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/native/engine/android/res/values/strings.xml b/native/engine/android/res/values/strings.xml new file mode 100644 index 0000000..337f48f --- /dev/null +++ b/native/engine/android/res/values/strings.xml @@ -0,0 +1,3 @@ + + cocos_demo_3 +