找回密码
 立即注册
查看: 596|回复: 3

Unity 出包 总是卡在Building Gradle project?

[复制链接]
发表于 2021-4-20 10:00 | 显示全部楼层 |阅读模式
Unity版本 2018.4.3f1
 楼主| 发表于 2021-4-20 10:09 | 显示全部楼层
也是在昨天刚学这一块,被卡了将近大半天。
之前一直在Building Gradle project这里卡着,十分钟没动静我就给关了,没想到要那么长时间。挂上VPN结果网络一波动就挂掉。
折腾了将近一天。在https://github.com/googlesamples/unity-jar-resolver/issues/63其提到的gradle/gradle#1747有这样一句。
删掉.gradle/daemon文件夹。(我的是C:\Users\Administrator\.gradle\daemon)
神奇的事情发生了,我几十秒就Build成功。


至于github中提到的--no-daemon方法。
在Unity的gradle.properties则可以通过IPostGenerateGradleAndroidProject接口进行修改。
(类似该问题https://zhuanlan.zhihu.com/p/83162670)
添加一个脚本。
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. #if UNITY_EDITOR
  5. using UnityEditor.Android;
  6. public class AndroidPostBuildProcessor : IPostGenerateGradleAndroidProject
  7. {
  8.     public int callbackOrder
  9.     {
  10.         get
  11.         {
  12.             return 999;
  13.         }
  14.     }
  15.     void IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject(string path)
  16.     {
  17.         Debug.Log("Bulid path : " + path);
  18.         //读取gradle.properties中的内容
  19.         string gradlePropertiesFile = path + "/gradle.properties";
  20.         List<string> properties = new List<string>(File.ReadAllLines(gradlePropertiesFile));
  21.         //添加 no daemon设置
  22.         properties.Add("org.gradle.daemon=false");
  23.         File.WriteAllLines(gradlePropertiesFile,properties);
  24.     }
  25. }
  26. #endif
复制代码
AndroidStudio的使用过程中也有人提到了类似的方法https://blog.csdn.net/marryvivien/article/details/54573645
注:
因为在我的电脑上使用第一种方法后,立刻流畅了起来。
在此基础上干掉守护进程后,只是感觉上快了一些。
至于第二种方法究竟有没有效果,有这种问题的可以试一下。
1月24日补充。
值得注意的是,在进行了以上设置后,开启vpn仍然会出现连接上的error导致build失败。
我在关闭vpn后,该问题便消失了。
发表于 2021-4-20 10:10 | 显示全部楼层
请问下 题主  这个问题是怎么解决的呢?
发表于 2021-4-20 10:13 | 显示全部楼层
build.gradle文件:
  1. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
  2. buildscript {
  3.     repositories {
  4.         google()
  5.         jcenter()
  6.                 mavenCentral()
  7.                 maven{
  8.                         url 'https://maven.google.com/'
  9.                         name 'Google'
  10.                 }
  11.     }
  12.     dependencies {
  13.         classpath 'com.android.tools.build:gradle:3.2.0'
  14. }
  15. }
  16. allprojects {
  17.     repositories {
  18.         google()
  19.         jcenter()
  20.         flatDir {
  21.             dirs 'libs'
  22.         }
  23.                 mavenCentral()
  24.                 maven{
  25.                         url 'https://maven.google.com/'
  26.                         name 'Google'
  27.                 }
  28.     }
  29. }
  30. // Android Resolver Repos Start
  31. ([rootProject] + (rootProject.subprojects as List)).each {
  32.     ext {
  33.         it.setProperty("android.useAndroidX", true)
  34.         it.setProperty("android.enableJetifier", true)
  35.     }
  36. }
  37. ([rootProject] + (rootProject.subprojects as List)).each { project ->
  38.     project.repositories {
  39.         maven {
  40.             url "https://maven.google.com"
  41.         }
  42.         maven {
  43.             url "file:///F:/WorkSpace/Project/Client/Assets/GeneratedLocalRepo/Firebase/m2repository" // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/MessagingDependencies.xml:20
  44.         }
  45.         maven {
  46.             url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
  47.         }
  48.         maven {
  49.             url "file:///F:/WorkSpace/Project/Client/Assets/GeneratedLocalRepo/GooglePlayGames/Editor/m2repository" // Assets/GooglePlayGames/Editor/GooglePlayGamesPluginDependencies.xml:11
  50.         }
  51.         mavenLocal()
  52.         jcenter()
  53.         mavenCentral()
  54.     }
  55. }
  56. // Android Resolver Repos End
  57. apply plugin: 'com.android.application'
  58. dependencies {
  59. // Android support Start
  60.     implementation 'com.android.support:support-v4:28.0.0'
  61.     implementation 'com.android.support:customtabs:28.0.0'
  62.     implementation 'com.android.support:appcompat-v7:28.0.0'
  63.     implementation 'com.android.support:recyclerview-v7:28.0.0'
  64.     implementation 'com.android.support:cardview-v7:28.0.0'
  65. // Android support End
  66. // Android gms Start
  67.     implementation 'com.google.android.gms:play-services-ads:18.0.0'
  68. // Android gms End
  69.     implementation fileTree(dir: 'libs', include: ['*.jar'])
  70. // Android Resolver Dependencies Start
  71.     implementation 'com.android.support:appcompat-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency(System.Object
  72.     implementation 'com.android.support:cardview-v7:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency(System.Object
  73.     implementation 'com.android.support:customtabs:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency(System.Object
  74.     implementation 'com.android.support:support-v4:25.3.1' // Facebook.Unity.Editor.AndroidSupportLibraryResolver.addSupportLibraryDependency(System.Object
  75.     implementation 'com.facebook.android:facebook-applinks:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:6
  76.     implementation 'com.facebook.android:facebook-core:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:5
  77.     implementation 'com.facebook.android:facebook-gamingservices:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:9
  78.     implementation 'com.facebook.android:facebook-login:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:7
  79.     implementation 'com.facebook.android:facebook-share:[8.0, 9)' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:8
  80.     implementation 'com.google.android.gms:play-services-ads:19.5.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
  81.     implementation 'com.google.android.gms:play-services-base:17.5.0' // Assets/Firebase/Editor/AppDependencies.xml:17
  82.     implementation 'com.google.firebase:firebase-analytics:18.0.0' // Assets/Firebase/Editor/MessagingDependencies.xml:15
  83.     implementation 'com.google.firebase:firebase-analytics-unity:7.0.2' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
  84.     implementation 'com.google.firebase:firebase-app-unity:7.0.2' // Assets/Firebase/Editor/AppDependencies.xml:22
  85.     implementation 'com.google.firebase:firebase-common:19.3.1' // Assets/Firebase/Editor/AppDependencies.xml:13
  86.     implementation 'com.google.firebase:firebase-messaging:21.0.0' // Assets/Firebase/Editor/MessagingDependencies.xml:13
  87.     implementation 'com.google.firebase:firebase-messaging-unity:7.0.2' // Assets/Firebase/Editor/MessagingDependencies.xml:20
  88.     implementation 'com.google.games:gpgs-plugin-support:0.10.12' // Assets/GooglePlayGames/Editor/GooglePlayGamesPluginDependencies.xml:11
  89.     implementation 'com.parse.bolts:bolts-android:1.4.0' // Assets/FacebookSDK/Plugins/Editor/Dependencies.xml:4
  90. // Android Resolver Dependencies End
  91.     implementation(name: 'billing-3.0.1', ext:'aar')
  92.     implementation(name: 'common', ext:'aar')
  93.     implementation(name: 'facebook-android-wrapper-8.1.1', ext:'aar')
  94.     implementation(name: 'googlemobileads-unity', ext:'aar')
  95.     implementation(name: 'unityOBBDownloader', ext:'aar')
  96.     implementation project(':FirebaseApp.androidlib')
  97.     implementation project(':GoogleMobileAdsPlugin.androidlib')
  98.     implementation project(':GooglePlayGamesManifest.plugin')
  99.     implementation project(':unity-android-resources')
  100. }
  101. // Android Resolver Exclusions Start
  102. android {
  103.   packagingOptions {
  104.       exclude ('/lib/armeabi/*' + '*')
  105.       exclude ('/lib/mips/*' + '*')
  106.       exclude ('/lib/mips64/*' + '*')
  107.       exclude ('/lib/x86/*' + '*')
  108.       exclude ('/lib/x86_64/*' + '*')
  109.   }
  110. }
  111. // Android Resolver Exclusions End
  112. android {
  113.     compileSdkVersion 29
  114.     buildToolsVersion '30.0.3'
  115.        
  116.         dexOptions{
  117.                 javaMaxHeapSize "4g"
  118.         }
  119.        
  120.     compileOptions {
  121.         sourceCompatibility JavaVersion.VERSION_1_8
  122.         targetCompatibility JavaVersion.VERSION_1_8
  123.     }
  124.     defaultConfig {
  125.         minSdkVersion 24
  126.         targetSdkVersion 29
  127.                 multiDexEnabled true
  128.         applicationId 'com.sturgeon.test'
  129.         ndk {
  130.             abiFilters 'armeabi-v7a', 'arm64-v8a'
  131.         }
  132.         versionCode 4
  133.         versionName '0.9.0'
  134.     }
  135.     lintOptions {
  136.                 disable 'MissingTranslation'
  137.         abortOnError false
  138.     }
  139.     aaptOptions {
  140.         noCompress = ['.unity3d', '.ress', '.resource', '.obb']
  141.     }
  142.     signingConfigs {
  143.         release {
  144.             storeFile file('F:/WorkSpace/Project/Client//user.keystore')
  145.             storePassword 'dw'
  146.             keyAlias 'test'
  147.             keyPassword '12345678'
  148.         }
  149.     }
  150.     buildTypes {
  151.         debug {
  152.             minifyEnabled false
  153.             useProguard false
  154.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
  155.             jniDebuggable true
  156.         }
  157.         release {
  158.             minifyEnabled false
  159.             useProguard false
  160.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
  161.             signingConfig signingConfigs.release
  162.         }
  163.     }
  164.     packagingOptions {
  165.         doNotStrip '*/armeabi-v7a/*.so'
  166.         doNotStrip '*/arm64-v8a/*.so'
  167.     }
  168.     bundle {
  169.         language {
  170.             enableSplit = false
  171.         }
  172.         density {
  173.             enableSplit = false
  174.         }
  175.         abi {
  176.             enableSplit = true
  177.         }
  178.     }
  179. }
复制代码
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-26 00:32 , Processed in 0.089955 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表