赞
踩
目录
1.如何在 module 的 gradle 中添加依赖和 AndroidManifest 的替换变量。
android插件版本与gradle版本的对应关系:
Android Gradle 插件版本说明 | Android 开发者 | Android Developers
gradle 各版本下载:
http://services.gradle.org/distributions/
查看最新的Android Plugin Version:https://jcenter.bintray.com/com/android/tools/build/gradle/
查看最新的Gradle:Gradle Distributions。
jar包仓库:https://mvnrepository.com/
Unity的所有与android相关的设定与配置都放在AndroidPlayer目录下:
C:\Program Files\Unity\Hub\Editor\2020.3.32f1c1\Editor\Data\PlaybackEngines\AndroidPlayer
知道了原理后就可以自己为不同的Unity版本配置它专属的Android开发与发布环境
从官网下载自己想下的NDK,然后替换掉文件夹的内容
从官网下载自己想下的NDK,然后替换掉文件夹的内容
从官网下载自己想下的NDK,然后替换掉文件夹的内容
从官网下载自己想下的Gradle,然后替换掉文件夹的内容
Unity设置中,勾选选择自己版本路径内的,取消勾选选定自己电脑中其它目录下的
1.新版本直接勾选即可修改在项目中修改 gradle模板文件。
将模板拷贝到Android目录下,按自己的需求编写即可
模板地址: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 {
- ......
- defaultConfig {
- applicationId "com.xxx.xxx" //JPush 上注册的包名.
- ......
-
- ndk {
- //选择要添加的对应 cpu 类型的 .so 库。
- abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
- // 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
- }
-
- manifestPlaceholders = [
- JPUSH_PKGNAME : applicationId,
- JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey.
- JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
- ]
- ......
- }
- ......
- }
-
- dependencies {
- ......
-
- compile 'cn.jiguang.sdk:jpush:3.6.0' // 此处以JPush 3.6.0 版本为例。
- compile 'cn.jiguang.sdk:jcore:2.3.4' // 此处以JCore 2.3.4 版本为例。
- ......
- }

- <activity
- android:name="cn.jpush.android.ui.PopWinActivity"
- android:exported="true"
- tools:node="replace"
- android:theme="@style/MyDialogStyle">
- <intent-filter>
- <category android:name="android.intent.category.DEFAULT" />
- <action android:name="cn.jpush.android.ui.PopWinActivity" />
- <category android:name="${applicationId}" />
- </intent-filter>
- </activity>
- //读取不到jar包后,如何读取aar
-
- implementation 'demo.xiaxiayige.com:testmaven:1.0.0@aar'
批量引用aar导致的重复包问题
- dependencies {
-
- implementation fileTree(dir: 'libs', include: ['*.jar'])
-
-
- //直接使用 implementation fileTree(dir: 'libs', include: ['*.aar'])会导致包重复问题
- //使用下面的方法可解决
-
- // 引入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')
- }
-
- //必须 :该库因为SDK内部使用
- //noinspection GradleCompatible
- implementation 'com.android.support:cardview-v7:28.0.0'
- //必须:这个库是加载一些广告中gif文件 所以需要依赖
- implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.18'
- //必须:这个库是内部SDK用到 需要依赖
- implementation 'com.google.code.gson:gson:2.8.6'
- //必须:这个库保证版本在24以上即可
- //noinspection GradleCompatible
- implementation 'com.android.support:support-v4:26.1.0'
-
- **DEPS**}

//特别注意://这里需要特别注意:有密钥的将 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**

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。