import java.nio.file.Files// This file contents should be placed at Assets/Plugins/Android/settingsTemplate.gradle// This works around Unity's 2019.3 bug where their root build.gradle is placing buildscript under allprojects// On it's own it doesn't create issues however doing so means including a buildscript block in any sub projects// such as "unityLibrary" which is generated from the template Assets/Plugins/Android/mainTemplate.gradle does not work.// It results in a build error of "Configuration with name 'compileClasspath' not found." on a lint task.// Normally adding "lintOptions { abortOnError false }" bypasses any lint task errors however// either due to a bug with the Android Gradle plugin or an order of operations this does seem to be applying in this case.// Until Unity fixes their root build.gradle we will need to keep using this file to enable any additional Gradle plugins.static void enableJetifier(Project project) { project.ext['android.useAndroidX'] = true project.ext['android.enableJetifier'] = true}static void addBuildscript(Project project) { project.buildscript { repositories { maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal maven { url 'http://developer.huawei.com/repo/' } } dependencies { classpath 'com.huawei.agconnect:agcp:1.6.5.300' } }}static void applyPlugins(Project project) { // Only apply to the :app project. (Unity calls this :launcher) if (project.name != 'launcher') return project.afterEvaluate { it.apply plugin: 'com.huawei.agconnect' }}static void copyHMSFile(Project project) { // Only apply to the :app project. (Unity calls this :launcher) if (project.name != 'launcher') return def newFile = new File("${project.rootDir}/launcher/agconnect-services.json") if (newFile.exists()) return def file = new File("${project.rootDir}/unityLibrary/OneSignalConfig/agconnect-services.json") Files.copy(file.toPath(), newFile.toPath())}gradle.rootProject { it.afterEvaluate { it.allprojects { // Since Unity 2019.3 enabling Jetifier via mainTemplate.gradle is no longer working // Enabling it for all gradle projects here. enableJetifier(it) addBuildscript(it) applyPlugins(it) copyHMSFile(it) } }}// Per Unity's docs /*/*INCLUDES/*/* should be at the bottom.// https://docs.unity3d.com/Manual/android-gradle-overview.html// However it seem to have left out this include lineinclude ':launcher', ':unityLibrary'**INCLUDES**
allprojects { ...}task copyReport(type: Copy) { from file("$projectDir/OneSignalConfig/agconnect-services.json") into file("$projectDir")}allprojects { afterEvaluate { for (def task in it.tasks) if (task != rootProject.tasks.copyReport) task.dependsOn rootProject.tasks.copyReport }}