Android Studio 下载文件归档 | Android Developers
Android--混淆配置(比较详细的混淆规则)_android 混淆规则-CSDN博客
Unity版本:2019.4.0f1
Gradle版本:5.6.4(或5.1.1)
Gradle Plugin版本:3.4.0
Android Studio版本:3.6.3
新建空工程,转Android平台,配置情况如下:
想尝试使用Gradle 6.7.1 Gradle Plguin 4.2.0打包空项目,反反复复出问题(失败)
为什么尝试这个是因为有些Google插件要求这些版本,如果只是测试Java混淆的可以不需要这么麻烦,全部使用默认的即可。
baseProjectTemplate.gradle
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAINallprojects {buildscript {repositories {**ARTIFACTORYREPOSITORY** // maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }// mavenLocal()// mavenCentral()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 versionclasspath 'com.android.tools.build:gradle:4.2.0'**BUILD_SCRIPT_DEPS**}}repositories {**ARTIFACTORYREPOSITORY**// maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }// maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }// mavenLocal()// mavenCentral()google()jcenter()flatDir {dirs "${project(':unityLibrary').projectDir}/libs"}} }task clean(type: Delete) {delete rootProject.buildDir }
classpath 'com.android.tools.build:gradle:4.2.0',可自行找网上找到对应关系
gradle plugin 4.2.0版本对应gradle 6.7.1版本distributionUrl=https\://mirrors.cloud.tencent.com/gradle//gradle-6.7.1-all.zip
利用镜像地址加速下载gradle-6.7.1-all gradle压缩包,下载到C:\Users\用户名\.gradle\wrapper\dists下。
Build时发生报错:
* What went wrong:
This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.2 or newer.调整Gradle 6.6.1,发现还是不行。调整回使用5.1.1或5.6.4推荐的gradle版本。Unity 2019.4.0默认是5.1.1版本
D:\UnityHubInstallPath\2019.4.0f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib
可通过观察这些文件后缀版本名看自己的对应多少版本或网上查询,这些版本不对应上就会出很多编译问题,即使你是空工程!!!
全部使用默认打包Android工程
只有上面的这种成功信息,不要只看CONFIGURE SUCCESSFUl,而是其他相关的警告也没有才正常,正常后就能看到Build Apk,否则是无法看到的。
解决jcenter相关的包下载不到问题 使用镜像地址 gradle plugin保持默认3.4.0
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAINallprojects {buildscript {repositories {// maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }// mavenLocal()// mavenCentral()google()jcenter()}dependencies {classpath 'com.android.tools.build:gradle:3.4.0'}}repositories {// maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }// mavenLocal()// mavenCentral()google()jcenter()flatDir {dirs "${project(':unityLibrary').projectDir}/libs"}}
}task clean(type: Delete) {delete rootProject.buildDir
}
gradle版本改用5.6.4-all
#Wed Jan 08 16:45:43 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
#distributionUrl=https\://mirrors.cloud.tencent.com/gradle//gradle-6.7.1-all.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle//gradle-5.6.4-all.zip
org.gradle.jvmargs=-Xmx4096M
org.gradle.parallel=true
android.injected.studio.version.check = false
加上这行避免一些提示你要去更新Android Studio版本的报错。
完成打包APK如下
可调整为release版本和签名形式打包apk或aab
混淆Java部分:
将false改为true,开启混淆,proguard-android.txt是默认混淆文件,不用管。
开启混淆后就会使用
proguard-unity.txt文件进行混淆,里面有各种混淆规则
-keep class bitter.jnibridge.* { *; }
-keep class com.unity3d.player.* { *; }
-keep interface com.unity3d.player.IUnityPlayerLifecycleEvents { *; }
-keep class org.fmod.* { *; }
-keep class com.google.androidgamesdk.ChoreographerCallback { *; }
-keep class com.google.androidgamesdk.SwappyDisplayManager { *; }
-ignorewarnings
混淆前后比对,通过Android Studio 查看apk的classes.dex