文章目录
1.Unity快速接入
进入官网,下载最新版本,然后按接入文档接入
1.baseProjectTemplate的设置
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
allprojects {
buildscript {
repositories {
**ARTIFACTORYREPOSITORY**
google()
jcenter()
// hms, 若不集成华为厂商通道,可直接跳过
maven {
url 'http://developer.huawei.com/repo/'}
// fcm, 若不集成 FCM 通道,可直接跳过
maven {
url "https://maven.google.com" }
}
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:4.0.1'
// fcm,若不集成 FCM 通道,可直接跳过
//classpath 'com.google.gms:google-services:4.3.8'
// hms,若不集成华为厂商通道,可直接跳过
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
**BUILD_SCRIPT_DEPS**
}
}
repositories {
**ARTIFACTORYREPOSITORY**
google()
jcenter()
// hms, 若不集成华为厂商通道,可直接跳过
maven {
url 'http://developer.huawei.com/repo/'}
// fcm, 若不集成 FCM 通道,可直接跳过
maven {
url "https://maven.google.com" }
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2.mainTemplate.gradle 的设置
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.library'
//apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.huawei.agconnect'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//方便控制一些jar包,直接将一些jar包放置到libs目录下即可
// 此处以JCore 3.2.2 版本为例。
//implementation 'cn.jiguang.sdk:jcore:3.2.2'
// 此处以JPush 4.6.2 版本为例
//implementation 'cn.jiguang.sdk:jpush:4.6.2'
//若不集成厂商通道,可直接跳过以下依赖
// 接入华为厂商
//implementation 'com.huawei.hms:push:6.1.0.300'
//仅使用 com.huawei.hms:push:6.1.0.XXX 版本需要加 base 依赖,其他版本不需要
//implementation 'com.huawei.hms:base:6.2.0.300'
// 极光厂商插件版本与接入 JPush 版本保持一致,下同
//implementation 'cn.jiguang.sdk.plugin:huawei:4.6.2'
// 接入 FCM 厂商
//implementation 'com.google.firebase:firebase-messaging:23.0.0'
//implementation 'cn.jiguang.sdk.plugin:fcm:4.6.2'
// 接入魅族厂商
//implementation 'cn.jiguang.sdk.plugin:meizu:4.6.2'
// 接入 VIVO 厂商
//implementation 'cn.jiguang.sdk.plugin:vivo:4.6.2'
// 接入小米厂商
//implementation 'cn.jiguang.sdk.plugin:xiaomi:4.6.2'
// 接入 OPPO 厂商
//implementation 'cn.jiguang.sdk.plugin:oppo:4.6.2'
// oppo 厂商 aar 需要单独引入,请将 jpush-android-xxx-release/third-push/oppo/libs 下 com.heytap.msp-push-x.x.x.aar 单独拷贝一份到应用 module/libs 下
implementation(name: 'com.heytap.msp-push-3.0.0', ext: 'aar')
//以下为 OPPO 3.0.0 aar需要依赖
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'commons-codec:commons-codec:1.6'
implementation 'androidx.annotation:annotation:1.1.0'
//AAPT: error: style attribute 'attr/colorPrimary (aka com.szw.jg0412:attr/colorPrimary)' not found.
//implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
**DEPS**}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}**PACKAGING_OPTIONS**
}**REPOSITORIES**
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**
3.Android/libs 的配置
直接拷贝极光的libs和src到unity的Android目录
4.AndroidManifest的配置
Activity的设置
<activity android:name="com.longtugame.rjsdk.MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize"
android:allowEmbedded="@string/app_name"
android:exported = "true"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAI