一些简单的sdk接入可考虑修改模板直接打包
1.新版本直接勾选即可修改在项目中修改 gradle模板文件。
模板地址:C:\Program Files\Unity2018.4.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates
unity用到的gradle版本地址:C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle
android studio grade下载地址:C:\Program Files\Android\Android Studio\gradle\gradle-5.1.1
将模板拷贝到Android目录下,按自己的需求编写即可
//特别注意://这里需要特别注意:有密钥的将 debug 中的内容删除,因为sha1 在debug 和release 生成的apk 不一样
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
**BUILD_SCRIPT_DEPS**}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.application'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// 引入libs文件夹下所有的aar文件,不需要引入的建议删除,在需要时再添加
fileTree(dir: 'libs', include: ['*.aar']).each { file ->
api(name: file.name.lastIndexOf('.').with {
it != -1 ? file.name[0..<it] : file.name
}, ext: 'aar')
}
// 公共
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
**DEPS**}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
}
**SIGN**
buildTypes {
//这里需要特别注意:有密钥的将 debug 中的内容删除,因为sha1 在debug 和release 生成的apk 不一样
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****SPLITS**
**BUILT_APK_LOCATION**
bundle {
language {
enableSplit = false
}
density {
enableSplit = false
}
abi {
enableSplit = true
}
}
}**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**