unity 卡在 building gradle project 的解决方法:

unity 卡在 building gradle project 的解决方法:

1. 避免从google下载 Gradle :

除了使用VPN以外,还可以使用阿里云的镜像,如下: (参考 https://jkchen.blog.csdn.net/article/details/107182562)

找到这个文件夹C:\Program Files\Unity\Hub\Editor\2019.3.5f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates

把baseProjectTemplate.gradle里面的

repositories {**ARTIFACTORYREPOSITORY**
            google()
            jcenter()
        }

改为

repositories {**ARTIFACTORYREPOSITORY**
            maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
            google()
            jcenter()
        }

2. 对于使用了 Google Admob Ads 的情况下

对于使用 GoogleAdmobAds 的情况下,会使用 Google Play Service,在 Assets->Play Service Resolver 里点击 Resolver 或者 Force Resolver,会修改工程里 Assets\Plugins\Android\mainTemplate.gradle文件,也会引用 maven.google.com 来加载相关的依赖包,同样的道理,可以进行修改为使用阿里云的。 修改后,注意设置 Assets->Play Service Resolver-->Setting ,避免它每次打包的时候去合并修改 mainTemplate.gradle

以下是一个完整的例子 mainTemplate.gradle:

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

buildscript {
    repositories {**ARTIFACTORYREPOSITORY**
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
**BUILD_SCRIPT_DEPS**}
}

allprojects {
    repositories {**ARTIFACTORYREPOSITORY**
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

// A(hwj---)  AAAndroid Resolver Repos Start , 这一段是用 Assets->Play Service Resolver 生成的,把 maven.google.com 修改成了阿里云的,注意这个注释里把 Android 改成了 AAAndroid,避免被Resolver自动修改了
([rootProject] + (rootProject.subprojects as List)).each { project ->
    project.repositories {
        def unityProjectPath = "file:///" + file(rootProject.projectDir.path + "/../../").absolutePath
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        maven {
            url "https://maven.aliyun.com/repository/google/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
        }
        mavenLocal()
        jcenter()
        mavenCentral()
    }
}
// A(hwj---)  AAAndroid Resolver Repos End
apply plugin: 'com.android.library'
**APPLY_PLUGINS**

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.google.android.gms:play-services-ads:19.5.0' // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7
// Android Resolver Dependencies End
**DEPS**}

// Android Resolver Exclusions Start
android {
  packagingOptions {
      exclude ('/lib/armeabi/*' + '*')
      exclude ('/lib/mips/*' + '*')
      exclude ('/lib/mips64/*' + '*')
      exclude ('/lib/x86/*' + '*')
      exclude ('/lib/x86_64/*' + '*')
  }
}
// Android Resolver Exclusions End
android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
        minSdkVersion **MINSDKVERSION**
        targetSdkVersion **TARGETSDKVERSION**
        
        ndk {
            abiFilters **ABIFILTERS**
        }
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**SIGN**

    buildTypes {
        debug {
            minifyEnabled **MINIFY_DEBUG**
            useProguard **PROGUARD_DEBUG**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
            jniDebuggable true
        }
        release {
            minifyEnabled **MINIFY_RELEASE**
            useProguard **PROGUARD_RELEASE**
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
        }
    }**PACKAGING_OPTIONS**
**BUILT_APK_LOCATION**
**EXTERNAL_SOURCES**
    
}**REPOSITORIES****SOURCE_BUILD_SETUP**

 

你可能感兴趣的:(Unity3D)