- Home /
Gradle file for Unity
I saw mentioned in another post that from the newest versions of Unity you can define your own gradle file. I need this in order to include support libraries and compat libraries.
I created a file called dfwvr.gradle in the Plugins/Android directory but it doesn't seem to help. Renaming it to build.gradle made no difference. I took the basic one from the one supplied.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:24.2.1"
compile "com.android.support:support-v4:24.2.1"
**DEPS**}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
defaultConfig {
targetSdkVersion **TARGETSDKVERSION**
}
lintOptions {
abortOnError false
}
**SIGN**
buildTypes {
debug {
jniDebuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
**SIGNCONFIG**
}
}
}
I followed what it says here but it doesn't work: http://answers.unity3d.com/questions/1308071/use-android-plugin-with-android-support-library-de.html
what Unity version are you using? custom gradle support was added in some 5.5.x patch (cant recall the exact version)
Answer by liortal · Feb 27, 2017 at 08:12 PM
You should name your custom gradle build file Assets/Plugins/Android/mainTemplate.gradle as documented here: https://docs.unity3d.com/Manual/android-gradle-overview.html
The easiest way to check if your custom Gradle build file is being picked up or not, is by exporting a project (check the "Export Project" checkbox).
After the build completes, you can see if the build.gradle file in the output folder matches the one you used or not.
Its documented at https://docs.unity3d.com/$$anonymous$$anual/android-gradle-overview.html but not well documented
I follow the guide doc that you attached, https://docs.unity3d.com/$$anonymous$$anual/android-gradle-overview.html
$$anonymous$$ade a file mainTemplate.gradle and put it in the project like below. "Assets/Plugins/Android/Android$$anonymous$$anifest.xml"
But still, when I export the Gradle project it didn't overwrite build.gradle.
Has anyone same problem like me?
Never had this issue. Unity has a default mainTemplate.gradle file in unity installation folder. Try using it as a base because you might have some error which might be causing it.
Secondly "Assets/Plugins/Android/Android$$anonymous$$anifest.xml" is not the path. Custom gradle path is supposed to be "Assets/Plugins/Android/mainTemplate.gradle"
Answer by NOGOODGAMES · Aug 06, 2020 at 11:17 PM
@theblitz make sure that your custom Gradle is checked in player settings. Check custom Gradle. You should be good to go. If the .Gradle file seems to be reverting after build I am also experiencing the same issue ;)