Kaynağa Gözat

新增原生桥接sdk

zhipeng 8 ay önce
ebeveyn
işleme
b542fc18e1

+ 8 - 7
build/android/proj/build.gradle

@@ -1,12 +1,6 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
-
-    repositories {
-        google()
-        mavenCentral()
-        // jcenter() // keeped as anchor, will be removed soon
-    }
     dependencies {
         classpath 'com.android.tools.build:gradle:8.0.2'
 
@@ -14,5 +8,12 @@ buildscript {
         // in the individual module build.gradle files
     }
 }
+plugins {
+    id 'com.android.application' version '8.0.2' apply false
+    id 'com.android.library' version '8.0.2' apply false
+}
 
-apply from: NATIVE_DIR +"/build.gradle"
+tasks.register('clean', Delete) {
+    delete rootProject.buildDir
+}
+//apply from: NATIVE_DIR + "/build.gradle"

+ 8 - 2
build/android/proj/gradle.properties

@@ -50,7 +50,7 @@ PROP_NDK_PATH=D:\\Android\\Sdk\\ndk\\23.2.8568313
 PROP_IS_DEBUG=false
 
 # Cocos Engine Path
-COCOS_ENGINE_PATH=C:/ProgramData/cocos/editors/Creator/3.8.6/resources/resources/3d/engine/native
+COCOS_ENGINE_PATH=C\:/ProgramData/cocos/editors/Creator/3.8.6/resources/resources/3d/engine/native
 
 # Res path
 RES_PATH=D:/Work/Eliminate/build/android
@@ -59,7 +59,7 @@ RES_PATH=D:/Work/Eliminate/build/android
 NATIVE_DIR=D:/Work/Eliminate/native/engine/android
 
 # Application ID
-APPLICATION_ID=com.cocos.eliminate
+APPLICATION_ID=com.dingxilong.fangkuai
 
 # List of CPU Archtexture to build that application with
 # Available architextures (armeabi-v7a | arm64-v8a | x86 | x86_64)
@@ -72,3 +72,9 @@ RELEASE_STORE_FILE=C:/ProgramData/cocos/editors/Creator/3.8.6/resources/tools/ke
 RELEASE_STORE_PASSWORD=123456
 RELEASE_KEY_ALIAS=debug_keystore
 RELEASE_KEY_PASSWORD=123456
+
+
+# atmob central app key
+atmob_central_app_key=aef9c479e4db48b990cd53537c2d57b1
+# gravity access token
+gravity_access_token=Mrwvguz0kJpQxcKNeXhn5jkimoSxiy1T

+ 8 - 1
build/android/proj/local.properties

@@ -1 +1,8 @@
-sdk.dir=D\:\\Android\\Sdk
+## This file must *NOT* be checked into Version Control Systems,
+# as it contains information specific to your local configuration.
+#
+# Location of the SDK. This is only used by Gradle.
+# For customization when using a Version Control System, please read the
+# header note.
+#Wed Apr 02 18:47:22 HKT 2025
+sdk.dir=C\:\\Users\\Administrator\\AppData\\Local\\Android\\Sdk

+ 36 - 5
build/android/proj/settings.gradle

@@ -1,10 +1,41 @@
-include ':libcocos',':libservice',':app'
-project(':libcocos').projectDir     = new File(COCOS_ENGINE_PATH,'cocos/platform/android/libcocos2dx')
-project(':app').projectDir    = new File(NATIVE_DIR, 'app')
+pluginManagement {
+    repositories {
+        google {
+            content {
+                includeGroupByRegex("com\\.android.*")
+                includeGroupByRegex("com\\.google.*")
+                includeGroupByRegex("androidx.*")
+            }
+        }
+        mavenCentral()
+        gradlePluginPortal()
+    }
+}
+dependencyResolutionManagement {
+    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+    repositories {
+        google()
+        mavenCentral()
+        maven {
+            credentials {
+                username "$atmob_maven_username"
+                password "$atmob_maven_password"
+            }
+            allowInsecureProtocol = true
+            url "$atmob_maven_url/repository/android-group/"
+        }
+        maven { url 'https://nexus.gravity-engine.com/repository/maven-releases/' }
+        maven { url 'https://nexus.gravity-engine.com/repository/maven-snapshots/' }
+        maven { url 'https://artifact.bytedance.com/repository/Volcengine/' }
+    }
+}
+include ':libcocos', ':libservice', ':app'
+project(':libcocos').projectDir = new File(COCOS_ENGINE_PATH, 'cocos/platform/android/libcocos2dx')
+project(':app').projectDir = new File(NATIVE_DIR, 'app')
 project(':app').name = "com-game-eliminate"
-if(PROP_ENABLE_INSTANT_APP == "true" || PROP_ENABLE_INSTANT_APP == "yes") {
+if (PROP_ENABLE_INSTANT_APP == "true" || PROP_ENABLE_INSTANT_APP == "yes") {
     include ':instantapp'
-    project(':instantapp').projectDir   = new File(NATIVE_DIR, 'instantapp')
+    project(':instantapp').projectDir = new File(NATIVE_DIR, 'instantapp')
 }
 
 rootProject.name = "com-game-eliminate"

+ 38 - 14
native/engine/android/app/AndroidManifest.xml

@@ -1,16 +1,40 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
-  <uses-permission android:name="android.permission.INTERNET"/>
-  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
-  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
-  <application android:extractNativeLibs="true" android:allowBackup="true" android:label="@string/app_name" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher" android:resizeableActivity="true">
-    <meta-data android:name="android.app.lib_name" android:value="cocos"/>
-    <activity android:name="com.cocos.game.AppActivity" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" android:exported="true">
-      <intent-filter>
-        <action android:name="android.intent.action.MAIN"/>
-        <category android:name="android.intent.category.LAUNCHER"/>
-      </intent-filter>
-    </activity>
-    <activity android:name="com.cocos.lib.CocosEditBoxActivity" android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize" android:screenOrientation="behind" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
-  </application>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    android:installLocation="auto">
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
+    <application
+        android:name="com.cocos.game.GameApp"
+        android:allowBackup="true"
+        android:extractNativeLibs="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/app_name"
+        android:resizeableActivity="true"
+        android:usesCleartextTraffic="true">
+        <meta-data
+            android:name="android.app.lib_name"
+            android:value="cocos" />
+
+        <activity
+            android:name="com.cocos.game.AppActivity"
+            android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize"
+            android:exported="true"
+            android:label="@string/app_name"
+            android:launchMode="singleTask"
+            android:screenOrientation="portrait"
+            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name="com.cocos.lib.CocosEditBoxActivity"
+            android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|smallestScreenSize"
+            android:screenOrientation="behind"
+            android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
+    </application>
 </manifest>

+ 15 - 7
native/engine/android/app/build.gradle

@@ -1,5 +1,3 @@
-import org.apache.tools.ant.taskdefs.condition.Os
-
 apply plugin: 'com.android.application'
 
 RES_PATH = RES_PATH.replace("\\", "/")
@@ -10,7 +8,7 @@ android {
     compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
     buildToolsVersion PROP_BUILD_TOOLS_VERSION
     ndkPath PROP_NDK_PATH
-    namespace APPLICATION_ID
+    namespace NAME_SPACE
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
@@ -55,7 +53,7 @@ android {
 
     signingConfigs {
 
-       release {
+        release {
             if (project.hasProperty("RELEASE_STORE_FILE") && !RELEASE_STORE_FILE.isEmpty()) {
                 storeFile file(RELEASE_STORE_FILE)
                 storePassword RELEASE_STORE_PASSWORD
@@ -76,7 +74,7 @@ android {
             if (project.hasProperty("RELEASE_STORE_FILE")) {
                 signingConfig signingConfigs.release
             }
-                        
+
             externalNativeBuild {
                 cmake {
                     // switch HIDE_SYMBOLS to OFF to skip compilation flag `-fvisibility=hidden`
@@ -88,6 +86,8 @@ android {
                 getIsDefault().set(true)
             }
 
+            buildConfigField "String", "ATMOB_CENTRAL_APP_KEY", "\"$atmob_central_app_key\""
+            buildConfigField "String", "GRAVITY_ACCESS_TOKEN", "\"$gravity_access_token\""
         }
 
         debug {
@@ -96,13 +96,20 @@ android {
             renderscriptDebuggable true
             // resValue  "string", "app_name", "${PROP_APP_NAME}-dbg"
             // applicationIdSuffix ".debug"
+
+            buildConfigField "String", "ATMOB_CENTRAL_APP_KEY", "\"$atmob_central_app_key\""
+            buildConfigField "String", "GRAVITY_ACCESS_TOKEN", "\"$gravity_access_token\""
         }
     }
+
+    buildFeatures {
+        buildConfig = true
+    }
 }
 
 dependencies {
-    implementation fileTree(dir: '../libs', include: ['*.jar','*.aar'])
-    implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
+    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')
@@ -110,4 +117,5 @@ dependencies {
         implementation 'com.google.android.libraries.play.games:inputmapping:1.1.0-beta'
         implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
     }
+    implementation "atmob.central:cocos-bridge:0.0.1-SNAPSHOT"
 }

+ 21 - 0
native/engine/android/app/src/com/cocos/game/GameApp.java

@@ -0,0 +1,21 @@
+package com.cocos.game;
+
+import android.app.Application;
+
+import com.atmob.cocos.bridge.AtmobCocosBridge;
+import com.atmob.cocos.bridge.Config;
+import com.atmob.compliance.AtmobCompliance;
+import com.game.eliminate.BuildConfig;
+
+public class GameApp extends Application {
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        AtmobCocosBridge.getInstance().init(this, new Config.Builder()
+                .debug(BuildConfig.DEBUG)
+                .appKey(BuildConfig.ATMOB_CENTRAL_APP_KEY)
+                .gravityAccessToken(BuildConfig.GRAVITY_ACCESS_TOKEN)
+                .complianceStrategy(AtmobCompliance.Strategy.CHINA)
+                .build());
+    }
+}