修改生成好的AndroidMainfest.xml文件,添加自定义的application
<?xml version="1.0" encoding="utf-8"?> <!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN--> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools"> <application android:name=".TheApplication"> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> </activity> </application> </manifest>
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN allprojects { buildscript { repositories {**ARTIFACTORYREPOSITORY** maven { url 'https://artifact.bytedance.com/repository/Volcengine/' } google() jcenter() } dependencies { // If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity // See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html // See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle // To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version classpath 'com.android.tools.build:gradle:3.4.0' **BUILD_SCRIPT_DEPS** } } repositories {**ARTIFACTORYREPOSITORY** maven { url 'https://artifact.bytedance.com/repository/Volcengine/' } google() jcenter() flatDir { dirs "${project(':unityLibrary').projectDir}/libs" } } } task clean(type: Delete) { delete rootProject.buildDir }
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN buildscript { repositories { mavenCentral() google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.0' } } allprojects { repositories { mavenCentral() google() jcenter() flatDir { dirs 'libs' } } } apply plugin: 'com.android.library' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61' implementation 'com.bytedance.frameworks.baselib:utility:2.0.11' implementation 'com.bytedance.frameworks:encryptor:0.0.9-rc.2-private' implementation 'com.bytedance.applog:RangersAppLog-Lite-cn:6.3.0' **DEPS**} android { compileSdkVersion **APIVERSION** buildToolsVersion '**BUILDTOOLS**' defaultConfig { consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD** minSdkVersion **MINSDKVERSION** targetSdkVersion **TARGETSDKVERSION** ndk { abiFilters **ABIFILTERS** } versionCode **VERSIONCODE** versionName '**VERSIONNAME**' } lintOptions { abortOnError false } aaptOptions { noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS** } **SIGN** buildTypes { debug { minifyEnabled **MINIFY_DEBUG** useProguard **PROGUARD_DEBUG** proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD** jniDebuggable true } release { minifyEnabled **MINIFY_RELEASE** useProguard **PROGUARD_RELEASE** proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD** **SIGNCONFIG** } } **PACKAGING_OPTIONS** } **SOURCE_BUILD_SETUP**
/* 初始化开始 */ final InitConfig config = new InitConfig("175128", "cuckoo"); // appid和渠道,appid如不清楚请联系客户成功经理,注意第二个参数 channel 不能为空 config.setUriConfig(UriConstants.DEFAULT);//上报地址 config.setAbEnable(true); // 开启 AB 测试 // 是否在控制台输出日志,可用于观察用户行为日志上报情况,上线之前可去掉 config.setLogger(new ILogger() { @Override public void log(String s, Throwable throwable) { Log.d("AppLog------->: ", "" + s); } }); // 加密开关,SDK 5.5.1 及以上版本支持,false 为关闭加密,上线前建议设置为 true AppLog.setEncryptAndCompress(false); config.setAutoStart(true); AppLog.init(this, config); /* 初始化结束 */
在Build Setting 平台切换到iOS,在导出工程中找到UnityAppController.mm文件,在didFinishLaunchingWithOptions函数,加入初始化代码
pod setup pod init
# Uncomment the next line to define a global platform for your project platform :ios, '9.0' source 'https://github.com/volcengine/volcengine-specs.git' target 'Unity-iPhone' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for Unity-iPhone target 'Unity-iPhone Tests' do inherit! :search_paths # Pods for testing end end target 'UnityFramework' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # applog的版本 pod 'RangersAppLog', '6.2.3', :subspecs => [ 'Host/CN', 'Core', 'Unique', 'Log', 'CBridge' ] end
pod install --repo-update
#import <RangersAppLog/BDAutoTrack.h> - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { //Init RangersAppLog BDAutoTrackConfig *config = [BDAutoTrackConfig configWithAppID:@"123456" launchOptions:launchOptions]; //debug日志开关,正式版本修改修改为NO config.showDebugLog = YES; config.logger = ^(NSString * _Nullable log) { NSLog(@"%@", log); }; config.appName = @"Unity test app"; //加密开关,正式版本修改修改为YES config.logNeedEncrypt = NO; [BDAutoTrack startTrackWithConfig:config]; return YES; }
在xCode中查看
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class lay_playGame : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void EventV3() { Dictionary<string, object> param = new Dictionary<string, object>(); param.Add("aaa", "111"); param.Add("bbb", "222"); RangersAppLog.Wrapper.RangersAppLog.EventV3("test", param); print("事件上报"); } public void SetCustomHeaderInfo() { RangersAppLog.Wrapper.RangersAppLog.SetCustomHeaderInfo("u_h_name", "my_first_unity"); print("设置消息头"); } public void RemoveCustomHeaderInfo() { RangersAppLog.Wrapper.RangersAppLog.RemoveCustomHeaderInfo("u_h_name"); print("移除消息头"); } public void ProfileSet() { Dictionary<string, object> param = new Dictionary<string, object>(); param.Add("u_p_age", 100); RangersAppLog.Wrapper.RangersAppLog.ProfileSet(param); print("调用ProfileSet"); } public void ProfileSetOnce() { Dictionary<string, object> param = new Dictionary<string, object>(); param.Add("u_p_name", "i am a unity project"); RangersAppLog.Wrapper.RangersAppLog.ProfileSetOnce(param); print("调用ProfileSetOnce"); } public void ProfileUnset() { RangersAppLog.Wrapper.RangersAppLog.ProfileUnset("u_p_name"); RangersAppLog.Wrapper.RangersAppLog.ProfileUnset("u_p_age"); } public void ProfileIncrement() { Dictionary<string, object> param = new Dictionary<string, object>(); param.Add("u_p_age", 1); RangersAppLog.Wrapper.RangersAppLog.ProfileIncrement(param); } public void ProfileAppend() { Dictionary<string, object> param = new Dictionary<string, object>(); param.Add("u_p_fav", "游泳"); RangersAppLog.Wrapper.RangersAppLog.ProfileAppend(param); print("调用ProfileAppend"); } public void GetAllABConfig() { Dictionary<string, object> config = RangersAppLog.Wrapper.RangersAppLog.GetAllAbTestConfig(); foreach (var item in config) { print("abtest,key is " + item.Key + " value is " + ((Dictionary<string, object>)item.Value)["val"]); object value = RangersAppLog.Wrapper.RangersAppLog.GetABTestConfigValueForKey(item.Key, "default"); Type type = value.GetType(); print("type is" + type.Name); print("abtest,曝光" + item.Key + "value is " + (string)value); } print("调用GetAllAbTestConfigs"); } public void GetAbSdkVersion() { string version = RangersAppLog.Wrapper.RangersAppLog.GetAbSdkVersion(); print("版本号:" + version); } public void SetExternalVersion() { RangersAppLog.Wrapper.RangersAppLog.SetExternalAbVersion("100,101"); print("设置SetExternalAbVersion"); } public void ChangeUser() { string[] malePetNames = { "Rufus", "Bear", "Dakota", "Fido", "Vanya", "Samuel", "Koani", "Volodya", "Prince", "Yiska" }; System.Random rnd = new System.Random(); int index = rnd.Next(malePetNames.Length); string user = malePetNames[index]; RangersAppLog.Wrapper.RangersAppLog.SetUserUniqueID(user); print("切换用户" + user); } public void Flush() { RangersAppLog.Wrapper.RangersAppLog.Flush(); print("立即推送"); } public void GetSDKLogInfo() { string aid = RangersAppLog.Wrapper.RangersAppLog.GetAid(); string did = RangersAppLog.Wrapper.RangersAppLog.GetDeviceId(); string iid = RangersAppLog.Wrapper.RangersAppLog.GetInstallId(); string uuid = RangersAppLog.Wrapper.RangersAppLog.GetUserUniqueID(); print(String.Format("aid is {0},did is {1},iid is {2},uuid is {3}", aid, did, iid, uuid)); } }