Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Gradle Build Error: Gradle version 2.10 is required. Current version is 4.0.1.

Discussion in 'Android' started by CyborgMannen, Oct 10, 2017.

  1. CyborgMannen

    CyborgMannen

    Joined:
    Sep 21, 2017
    Posts:
    2
    I can't build for android with gradle it says that I'm using the wrong version, where do I change it so it uses the right version?

    Or is it something else?

     
    Last edited: Oct 10, 2017
  2. NinjaCat

    NinjaCat

    R&D Minion Unity Technologies

    Joined:
    Aug 22, 2013
    Posts:
    69
    Hi!

    Are you using a custom mainTemplate.gradle ? It might be still trying to use an older android gradle plugin which doesn't work with gradle 4.0.1. If you're not using a custom template, could you please send us a bug report?
     
  3. DomRoberts

    DomRoberts

    Joined:
    Aug 11, 2017
    Posts:
    2
    Hi,

    I've also come into this issue when updating to Unity 2017.3.0f3. I do use a custom template gradle file (which works fine in 2017.2), my template does specify gradle:2.1.2 but doesn't seem to be respected, I've attached my full mainTemplate.gradle file.

    I do also set my GRADLE_HOME environment variable to a directory with gradle-4.3.1 which may be causing issue, but I use this elsewhere with Android Studio so don't want to change it.

    Is there a place in unity to set the gradle version? I'm not totally sure where it gets it from to start with, but I presume the environment variable.

    Thanks,
    Dominic

    Here's my full error:

    CommandInvokationFailure: Gradle build failed.
    /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/bin/java -classpath "/Volumes/Samsung_T5/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleDebug"

    stderr[

    FAILURE: Build failed with an exception.

    * Where:
    Build file '/Volumes/Samsung_T5/Repositories/xxx/unity-sdk/plugin/Temp/gradleOut/build.gradle' line: 19

    * What went wrong:
    A problem occurred evaluating root project 'gradleOut'.
    > Failed to apply plugin [id 'com.android.application']
    > Gradle version 2.10 is required. Current version is 4.0.1. If using the gradle wrapper, try editing the distributionUrl in /Volumes/Samsung_T5/Repositories/xxx/unity-sdk/plugin/Temp/gradleOut/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip
     
  4. kiwipxl

    kiwipxl

    Joined:
    Jun 9, 2015
    Posts:
    11
    @DomRoberts I think you'll need to change your gradle version in your custom template file.
    If you find the template gradle for your Unity version (Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/mainTemplate.gradle on OSX for example), you can see the gradle version being used.
    In Unity 2017.3.0f3 it's gradle:2.3.0, so just update your custom file with that.
    I'm not sure why it says the current version is 4.0.1 because the template seems to say otherwise. Either way, this worked for me.
     
    slumtrimpet and Nick62 like this.
  5. Nick62

    Nick62

    Joined:
    Jan 30, 2017
    Posts:
    11
    Hallo.
    Thank you about this information. It helps me do repair gradle buid in unity 2017.3.1p1
    how can I identify current gradle version in unity?
     
    CandraWi, DomRoberts and lukos like this.
  6. kiwipxl

    kiwipxl

    Joined:
    Jun 9, 2015
    Posts:
    11
    It should be the one mentioned in the mainTemplate.gradle file as far as I know. Not sure where that path is on windows, but you can find it on OSX with the path I mentioned above. :)
     
    Nick62 likes this.
  7. DomRoberts

    DomRoberts

    Joined:
    Aug 11, 2017
    Posts:
    2
  8. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    That saved my ass too, i changed to 4.0.1 according to the warning n didnt work. How a normal dev would know what gradle version 2017 uses!!!! (We just upgraded to 2017 so 2.0.1 was totally fine before in 5.6)
     
  9. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    Please don't mix up Gradle version and Android plugin version.

    What you specify in build.gradle by having

    Code (CSharp):
    1.     dependencies {
    2.         classpath 'com.android.tools.build:gradle:2.3.0'
    3.     }
    is the Android plugin version. (corresponds Android Studio version).
    The Gradle binary itself is shipped with Unity, and you can't change the version easily.

    So:

    2017.1 and 2017.2 use
    Android plugin version 2.1.0
    Gradle version 2.14

    2017.4 up to and including 2017.4.16 uses
    Android plugin version 2.3.0
    Gradle version 4.0.1

    2017.4 starting from 2017.4.17 uses
    Android plugin version 3.2
    Gradle version 4.6
    (added support for building Android app bundles)

    2018.1 uses
    Android plugin version 2.3.0
    Gradle version 4.0.1

    2018.2
    uses
    Android plugin version 3.0.1
    Gradle version 4.2.1

    2018.3, 2018.4
    up to and including 2018.4.3f1 and 2019.1 up to and including 2019.1.6f1 use
    Android plugin version 3.2
    Gradle version 4.6

    2018.4
    starting from 2018.4.4f1, 2019.1 starting from 2019.1.7f1, 2019.2 and 2019.3 use
    Android plugin version 3.4
    Gradle version 5.1.1
     
    Last edited: Sep 5, 2019
  10. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    101
    great! thx, it saved me!
     
  11. SocialFreak

    SocialFreak

    Joined:
    Dec 12, 2015
    Posts:
    37
    Thanks for all the great info! Helped me immensely!
     
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    Updated the post with versions for 2018.3.
     
    yasmo likes this.
  13. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    422
    After updading plugin version from 2.1.0 to 3.2 in gradle template i faced with this error
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:/Program Files/Java/jdk1.8.0_141\bin\java.exe -classpath "C:\Program Files\Unity 2018.3.0b5\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. A problem occurred configuring root project 'gradleOut'.
    10. > Could not resolve all artifacts for configuration ':classpath'.
    11.    > Could not find com.android.tools.build:gradle:3.2.
    12.      Searched in the following locations:
    13.          https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.pom
    14.          https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.jar
    15.      Required by:
    16.          project :
    17.  
    18. * Try:
    19. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    20.  
    21. * Get more help at https://help.gradle.org
    22.  
    23. BUILD FAILED in 13s
    24. ]
    25. stdout[
    26. Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
    27. ]
    28. exit code: 1
    29. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    30. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    31. UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    32. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <480e50343593457c94864bd38c09a2ca>:0)
    33. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <480e50343593457c94864bd38c09a2ca>:0)
    34. Rethrow as GradleInvokationException: Gradle build failed
    35. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <480e50343593457c94864bd38c09a2ca>:0)
    36. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
    37. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
    38. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    39.  
    Then after all fixes i've got this error
    Code (CSharp):
    1. FileNotFoundException: Temp\gradleOut\build\outputs\apk\release\gradleOut-release.apk does not exist
    2. System.IO.File.Move (System.String sourceFileName, System.String destFileName) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
    3. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <37ed2f677a93461fa013cddc2cc869d2>:0)
    4. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <37ed2f677a93461fa013cddc2cc869d2>:0)
    5. UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <37ed2f677a93461fa013cddc2cc869d2>:0)
    6. UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <37ed2f677a93461fa013cddc2cc869d2>:0)
    7. UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:287)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    9.  
     
    Last edited: Oct 15, 2018
  14. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    @justtime I think your build.gradle is missing google() in dependencies section, next to jcenter().
     
  15. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Since Gradle binary ships with Unity, is there any plan to make this modular and able to change it through settings or something? So we don't have to update a Unity version just for gradle versions
     
    Voxel-Busters likes this.
  16. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    We are planning that. However, why would you need to update gradle itself?
     
  17. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Thanks Yury for your answer.
    In the company we are providing different packages and different gradles version in Unity force us to create several mainTemplate. Perhaps with the possibility of choosing gradle version would be nice. It's not a big trouble.
     
  18. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    Martin_Gonzalez likes this.
  19. Yuneza

    Yuneza

    Joined:
    Feb 1, 2015
    Posts:
    3

    I am getting this error

    * What went wrong:
    A problem occurred evaluating root project 'gradleOut'.
    > Failed to apply plugin [id 'com.android.application']
    > Minimum supported Gradle version is 4.4. Current version is 4.2.1. If using the gradle wrapper, try editing the distributionUrl in....

    My unity version is 2018.2.17f (the latest one) and I used 3.0.1 like you said but still was getting gradle errors... then I tried 3.1.0 it took more time then other build but this time I am facing this...
    Please help
     
  20. vitorbarbosa

    vitorbarbosa

    Joined:
    Jan 3, 2019
    Posts:
    1
    Is there any documentation page that contains this information? If not, it'd be nice to have this is the Unity docs.
     
    neonblitzer and heguchi like this.
  21. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    Updated the post to include changes to 17.4.
     
  22. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    422
    Hi!Unity 2017.4.19f
    gradle template:
    Code (CSharp):
    1. buildscript {
    2.     repositories {
    3.         jcenter()
    4.         google()
    5.     }
    6.  
    7.     dependencies {
    8.         classpath 'com.android.tools.build:gradle:3.2'
    9.     }
    10. }
    11.  
    12. allprojects {
    13.    repositories {
    14.       flatDir {
    15.         dirs 'libs'
    16.       }
    17.    }
    18. }
    19.  
    20. apply plugin: 'com.android.application'
    21.  
    22. dependencies {
    23.     compile 'com.android.support:multidex:1.0.1'
    24.     compile fileTree(dir: 'libs', include: ['*.jar'])
    25.     compile 'com.android.support:multidex:1.0.1'
    26. **DEPS**}
    27.  
    28. android {
    29.     compileSdkVersion **APIVERSION**
    30.     buildToolsVersion '**BUILDTOOLS**'
    31.  
    32.     defaultConfig {
    33.         targetSdkVersion **TARGETSDKVERSION**
    34.         applicationId '**APPLICATIONID**'
    35.         multiDexEnabled true
    36.        
    37.         versionCode 25
    38.     }
    39.  
    40.     lintOptions {
    41.         abortOnError false
    42.     }
    43.  
    44.     aaptOptions {
    45.         noCompress '.unity3d', '.ress', '.resource', '.obb'
    46.     }
    47.  
    48. **SIGN**
    49.     buildTypes {
    50.           debug {
    51.              //minifyEnabled **MINIFY_DEBUG**
    52.              //useProguard **PROGUARD_DEBUG**
    53.              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    54.               jniDebuggable true
    55.           }
    56.           release {
    57.              //minifyEnabled **MINIFY_RELEASE**
    58.              //useProguard **PROGUARD_RELEASE**
    59.               proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    60.               **SIGNCONFIG**
    61.           }
    62.     }
    63.  
    64.  
    65.     splits {
    66.        
    67.             // Configures multiple APKs based on ABI.
    68.             abi {
    69.        
    70.               // Enables building multiple APKs per ABI.
    71.               enable true
    72.        
    73.               // By default all ABIs are included, so use reset() and include to specify that we only
    74.               // want APKs for x86 and x86_64.
    75.        
    76.               // Resets the list of ABIs that Gradle should create APKs for to none.
    77.               reset()
    78.        
    79.               // Specifies a list of ABIs that Gradle should create APKs for.
    80.               include "armeabi-v7a"
    81.               //include "x86"
    82.        
    83.               // Specifies that we do not want to also generate a universal APK that includes all ABIs.
    84.               universalApk false
    85.             }
    86.           }
    87. }
    88.  
    89. // Map for the version code that gives each ABI a value.
    90. ext.abiCodes = ['armeabi-v7a':1, x86:2, x86_64:3]
    91.  
    92. // For per-density APKs, create a similar map like this:
    93. // ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3]
    94.  
    95. import com.android.build.OutputFile
    96.  
    97. // For each APK output variant, override versionCode with a combination of
    98. // ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
    99. // is equal to defaultConfig.versionCode. If you configure product flavors that
    100. // define their own versionCode, variant.versionCode uses that value instead.
    101. android.applicationVariants.all { variant ->
    102.  
    103.   // Assigns a different version code for each output APK
    104.   // other than the universal APK.
    105.   variant.outputs.each { output ->
    106.  
    107.     // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
    108.     def baseAbiVersionCode =
    109.             // Determines the ABI for this variant and returns the mapped value.
    110.             project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
    111.  
    112.     // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
    113.     // the following code does not override the version code for universal APKs.
    114.     // However, because we want universal APKs to have the lowest version code,
    115.     // this outcome is desirable.
    116.     if (baseAbiVersionCode != null) {
    117.  
    118.       // Assigns the new version code to versionCodeOverride, which changes the version code
    119.       // for only the output APK, not for the variant itself. Skipping this step simply
    120.       // causes Gradle to use the value of variant.versionCode for the APK.
    121.       output.versionCodeOverride =
    122.               baseAbiVersionCode * 1000 + variant.versionCode
    123.     }
    124.   }
    125. }
    126.  
    And i got an error
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:/Program Files/Java/jdk1.8.0_141\bin\java.exe -classpath "C:\Program Files\Unity 2018.4.19f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. A problem occurred configuring root project 'gradleOut'.
    10. > Could not resolve all artifacts for configuration ':classpath'.
    11.    > Could not find com.android.tools.build:gradle:3.2.
    12.      Searched in the following locations:
    13.          https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.pom
    14.          https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.jar
    15.          https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2/gradle-3.2.pom
    16.          https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2/gradle-3.2.jar
    17.      Required by:
    18.          project :
    19.  
    20. * Try:
    21. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    22.  
    23. * Get more help at https://help.gradle.org
    24.  
    25. BUILD FAILED in 5s
    26. ]
    27. stdout[
    28.  
    29. ]
    30. exit code: 1
    31. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    32. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    33. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    34. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1[T] progress) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    35. Rethrow as GradleInvokationException: Gradle build failed
    36. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1[T] progress) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    37. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    38. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    39. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    40.  
     
  23. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    I think you need to add
    google()
    jcenter()
    in allprojects { repositories }}
    Like this

    allprojects {
    repositories {
    google()
    jcenter()
    flatDir {
    dirs 'libs'
    }
    }
    }
     
  24. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    422
    Hi! Now i have this
    Code (CSharp):
    1. CommandInvokationFailure: Unable to retrieve /proc/meminfo from device. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.
    2. C:/Users/Teq/AppData/Local/Android/sdk\platform-tools\adb.exe -s "06d6b1170280cbc2" shell cat /proc/meminfo
    3.  
    4. stderr[
    5. error: closed
    6. ]
    7. stdout[
    8.  
    9. ]
    10. exit code: 1
    11. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    12. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    13. UnityEditor.Android.ADB.RunInternal (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    14. UnityEditor.Android.ADB.Run (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    15. UnityEditor.Android.AndroidDevice.Exec (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    16. UnityEditor.Android.AndroidDevice.get_MemInfo () (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    17. UnityEditor.Android.AndroidDeviceInfo.get_TotalMemory () (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    18. UnityEditor.Android.PostProcessor.Tasks.CheckDevice.FindDevice (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    19. UnityEditor.Android.PostProcessor.Tasks.CheckDevice.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    20. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <a84d5edaccb74c14ae23234d97e623b7>:0)
    21. UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
    22.  
     
  25. Martin_Gonzalez

    Martin_Gonzalez

    Joined:
    Mar 25, 2012
    Posts:
    361
    Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.

    Check in Unity -> Preference -> External Tools if you have properly configured the SDK at the bottom
     
  26. PEZO19

    PEZO19

    Joined:
    Oct 24, 2013
    Posts:
    23
    Guys, sorry it is not 100% related, but I think you might know the answer.

    Where can I set the value of '**BUILDTOOLS**'?

    I mean where are they coming from if it is not overridden by a value in mainTemplate.gradle or libTemplate.gradle?

    When I try to Build to android I get an error, because Build Tools 29.0.0 is not present, but I can't download it from anywhere: I have the latest Android Studio version, but 29.0.0 is not available to download, only 29.0.0-rc1 and 29.0.0-rc2.

    I'd like to force the environment to use 29.0.0-rc2 instead 29.0.0.

    When I checked the generated(?) build.gradle files I have seen 27.0.0 and 29.0.0 versions and the problem is only with the latter.
     
    Last edited: Apr 4, 2019
  27. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    This is a known issue and we are working on a fix. Unity build does not work when the rc version is available. Please uninstall build tools 29.0.0-rc1 and 29.0.0-rc2 for now. Leave the latest version that does not have rc and that should work.
     
  28. PEZO19

    PEZO19

    Joined:
    Oct 24, 2013
    Posts:
    23
    Ah, that is weird! Could you please write it in the docs in the meantime? :) It would save a lot of time. :)

    (At the end of the day I managed to get it work by altering build.gradle libTemplate and forcing it to '29.0.0 rc2')

    ----

    1.However, may I ask how the **BUILDTOOLS** variable gets populated (in libTemplate and mainTemplate)?

    2. Where does the value come from if its just a plain simple automatic build, and why is that sometimes it has different values in the same build (regarding to different build.gradle files).
    Is that part of the known issue?
     
    Voxel-Busters likes this.
  29. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    **BUILDTOOLS** gets replaced with the latest installed build tools version from the android SDK that is used by Unity editor. The replacement is done by Unity editor during the build process. Different *.gradle files should have the same value set during the same build, unless some of the custom files have that value hardcoded. In that case the hardcoded value will remain. I am not aware of any issues regarding to this, so if you believe that you are seeing a bad behavior, feel free to submit a bug report.
     
  30. JohnTube

    JohnTube

    Joined:
    Sep 29, 2014
    Posts:
    66
    Hi @Yury-Habets

    Thanks for this useful piece of info.
    Could you also give us the list of supported Android build tools (API, platform, platform-tools) version per Unity version?

    Maybe all this should be added to the documentation also?
     
  31. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    @JohnTube basically, latest version of Android SDK component should always work.
    There was a breaking change in the SDK few years ago which removed the "android" command and caused quite a few issues. These days are long gone, and unless you are using a very old Unity version (or a very outdated patch release), it shoudn't be an issue anymore.

    In addition, we've added Android SDK and NDK as components to install in Unity Hub. (can't remember the version; is it 2019.1?). It means that you can install a supported version of SDK/NDK together with Unity directly from Hub, without having to deal with the external downloads. This setup is preferred for simple use.
     
  32. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    JohnTube likes this.
  33. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    @Yury-Habets We have our own build.gradle file shipped with our plugins. What version we need to keep so that our plugins will work on the development environment properly?

    We would like to know if any macros exist so that these will be replaced during build time. Else, its becoming very difficult as every time Unity upgrades the android plugin version, it's breaking our developer builds or we need to push build for every new unity version which is tedious. Please let us know a possible solution.

    Thanks,
    VB Team
     
  34. escplus

    escplus

    Joined:
    Sep 30, 2016
    Posts:
    1
    Hi @Yury-Habets
    I'm using Unity 2018.1.4f1 and set classpath 'com.android.tools.build:gradle:4.0.1' in mainTemplate.grade
    But I got the error "could not fine com.android.tools.build:gradle:4.0.1"
    Can you help me a advice?
    Thanks
     
  35. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    Please read this post carefully:
    https://forum.unity.com/threads/gra...current-version-is-4-0-1.499520/#post-3500005
    There is no plugin version 4.0.1 released yet. You are most likely mixing up the gradle version and the Android build plugin version.
     
  36. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    @Yury-Habets Can you please answer my earlier query?

    We want a confirmation if something like an api exists to detect what versions unity is using so that we can generate our build.gradle files as per the supported versions.

    If not, we request your suggestion on how to handle this.
     
  37. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    @Voxel-Busters do I understand correctly that you are overriding build.gradle and want to be compatible with multiple Unity versions? That makes sense.

    I don't see a straightforward solution right now other than:
    1. Stop modifying build.gradle. Like, really see if you can end up with just your own build.gradle and not modifying it for the whole app. Same applies to the manifest.
    2. Use https://docs.unity3d.com/ScriptReference/Android.IPostGenerateGradleAndroidProject.html - works in 2018.1 and later - sample here https://github.com/Over17/UnityAndroidManifestCallback
    3. We could add the variable but this change won't make it into 2017.4 so you'd better select option #2.
     
  38. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    I don't mean overriding it but I meant having our own build.gralde files as we want to support the proguard setup automatically (instead of devs copying it to the final proguard.txt files which is totally manual process).

    Our structure looks like this
    Assets
    Plugins
    Android
    native_plugins_lib
    AndroidManifest.xml
    build.gradle
    proguard.txt
    libs
    *.jar files
    res

    We want to have proguard setup automatically so we have configured in our build.gradle so that the devs can avoid manual process of copying the contents of proguard.txt.

    As we need to fill in the gradle version in build.gradle file it breaks in some new versions as Unity expects different gradle versions. Moreover, the macros used in maintemplate.gradle (of unity's) won't work in our gradle files. So it would be great to have the versions accessible through code so that we can generate the build.gradle files during export time.


    Anyways, we are able to come up with a solution to match unity's gradle version and also enable new jetifier (AndroidX) process automatically.

    Thanks a lot @Yury-Habets. Your inputs (earlier related to proguard setup on a diff thread and about post gradle scripts) helped us a lot in automating many of the manual steps :)

    Cheers,
    VB Team
     
    Last edited: Jun 28, 2019
    Yury-Habets likes this.
  39. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
  40. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    Yes (Cross Platform Native Plugins). Exactly, we used consumerProguardFiles within our build.gradle file (with the help of yours earlier) and the proguard setup is automatic.

    Just only worry is when having our own build.gradle file we need to specify the android plugin version where it needs to be hardcoded and as gradle versions keep changing it became difficult to have a single build.gradle file for multiple unity versions. For this reason only we see it would be great if we can access the version numbers through scripting so that we can generate the build.gradle files at editor time to avoid these errors.

    However, from 2019, we started using the same android plugin version as unity's by parsing in post processor to avoid further errors.

    Thanks,
    VB Team
     
  41. Sompol_Rznet

    Sompol_Rznet

    Joined:
    Sep 14, 2018
    Posts:
    22
    Hi, I got the error also but I use 2017.4.26f1 (LTS) version and never modify any gradle setting.
    Because my game project need to support 64bit soon, so I have to move it from 2017.2.1p1 to a nearby version that could build 64bit app.
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Java\jdk1.8.0_45\bin\java.exe -classpath "C:\Program Files\Unity 2017.4.26f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * Where:
    9. Build file 'E:\UnityWorkspace\goldenrat-client3\Temp\gradleOut\build.gradle' line: 23
    10.  
    11. * What went wrong:
    12. A problem occurred evaluating root project 'gradleOut'.
    13. > Failed to apply plugin [id 'com.android.application']
    14.    > Gradle version 2.10 is required. Current version is 4.6. If using the gradle wrapper, try editing the distributionUrl in E:\UnityWorkspace\goldenrat-client3\Temp\gradleOut\gradle\wrapper\gradle-wrapper.properties to gradle-2.10-all.zip
    15.  
    16. * Try:
    17. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    18.  
    19. * Get more help at https://help.gradle.org
    20.  
    21. BUILD FAILED in 20s
    22. ]
    23. stdout[
    24. Starting a Gradle Daemon (subsequent builds will be faster)
    25. ]
    26. exit code: 1
    27. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    28. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    29. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
    30. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    31. Rethrow as GradleInvokationException: Gradle build failed
    32. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    33. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    34. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    35. UnityEditor.BuildPipeline:BuildPlayer(String[], String, BuildTarget, BuildOptions)
    36. RZ.Editor.RZBuildScript:GenericBuild(BuildTarget, BuildOptions) (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:620)
    37. RZ.Editor.<StartBuildProcess>c__AnonStorey1:<>m__0() (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:603)
    38. RZ.Editor.<BeginFirstProcess>c__AnonStorey0:<>m__0(Boolean, BuildSubmitResponse, String) (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:589)
    39. RZ.BuildProcess.Editor.<RequestBuildSubmit>c__AnonStorey0:<>m__0(UnityWebRequest, String, String) (at Assets/Scripts/RZ/BuildProcess/Editor/BuildVersionManagement.cs:69)
    40. RZ.Utils.SimpleHTTP.<Get>c__AnonStorey0:<>m__0(AsyncOperation) (at Assets/Scripts/RZ/Utils/SimpleHTTP/HTTP.cs:51)
    41. UnityEngine.AsyncOperation:InvokeCompletionEvent()
    How should I fix it in my case?

    P.S. My PC (Windows 10 - 64bit) have multiple version of Unity installed.
     
  42. Sompol_Rznet

    Sompol_Rznet

    Joined:
    Sep 14, 2018
    Posts:
    22
    After modify version number to match a current version that comes together with Unity.2017.4.26f1 (which is gredle 4.6.0) in Assets\Plugins\Android\mainTemplate.gradle
    Error changed to these :
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:\Program Files\Java\jdk1.8.0_45\bin\java.exe -classpath "C:\Program Files\Unity 2017.4.26f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. A problem occurred configuring root project 'gradleOut'.
    10. > Could not resolve all artifacts for configuration ':classpath'.
    11.    > Could not find com.android.tools.build:gradle:4.6.0.
    12.      Searched in the following locations:
    13.          https://jcenter.bintray.com/com/android/tools/build/gradle/4.6.0/gradle-4.6.0.pom
    14.          https://jcenter.bintray.com/com/android/tools/build/gradle/4.6.0/gradle-4.6.0.jar
    15.      Required by:
    16.          project :
    17.  
    18. * Try:
    19. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    20.  
    21. * Get more help at https://help.gradle.org
    22.  
    23. BUILD FAILED in 3s
    24. ]
    25. stdout[
    26.  
    27. ]
    28. exit code: 1
    29. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    30. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    31. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
    32. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    33. Rethrow as GradleInvokationException: Gradle build failed
    34. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    35. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    36. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    37. UnityEditor.BuildPipeline:BuildPlayer(String[], String, BuildTarget, BuildOptions)
    38. RZ.Editor.RZBuildScript:GenericBuild(BuildTarget, BuildOptions) (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:620)
    39. RZ.Editor.<StartBuildProcess>c__AnonStorey1:<>m__0() (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:603)
    40. RZ.Editor.<BeginFirstProcess>c__AnonStorey0:<>m__0(Boolean, BuildSubmitResponse, String) (at Assets/Scripts/RZ/Editor/RZBuildScript.cs:589)
    41. RZ.BuildProcess.Editor.<RequestBuildSubmit>c__AnonStorey0:<>m__0(UnityWebRequest, String, String) (at Assets/Scripts/RZ/BuildProcess/Editor/BuildVersionManagement.cs:69)
    42. RZ.Utils.SimpleHTTP.<Get>c__AnonStorey0:<>m__0(AsyncOperation) (at Assets/Scripts/RZ/Utils/SimpleHTTP/HTTP.cs:51)
    43. UnityEngine.AsyncOperation:InvokeCompletionEvent()
    44.  
    I suppose that we need to change the Assets\Plugins\Android\mainTemplate.gradle
    But this time need to make it looking in local directory instead of remote repository (now it looking at https://jcenter.bintray.com/com/android/tools/build/gradle/4.6.0/gradle-4.6.0.pom which actually jcenter had only 2.3.0 as a newest version)
     
  43. Sompol_Rznet

    Sompol_Rznet

    Joined:
    Sep 14, 2018
    Posts:
    22
    Somehow I can pass this issue by following method.
    1). Ignoring the version in error message (because it misleading) and just correct version as follow the https://forum.unity.com/threads/gra...current-version-is-4-0-1.499520/#post-3500005
    2). Put every repository that its need. (After passed the step 1, then we got an error about cannot find some library from repository. Fixing this directly by put the repo that contains those lib )

    Below is my mainTemplate.gradle file after fixed.

    buildscript {
    repositories {
    jcenter()
    google() // For Gradle 4.0+
    mavenCentral()
    maven { url "https://jitpack.io" }
    // maven { url 'https://maven.google.com' } // For Gradle < 4.0
    }

    dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0' // Correct version follow https://forum.unity.com/threads/gradle-build-error-gradle-version-2-10-is-required-current-version-is-4-0-1.499520/#post-3500005
    }
    }

    allprojects {
    repositories {
    flatDir {
    dirs 'libs'
    }
    jcenter()
    google() // For Gradle 4.0+
    mavenCentral()
    maven { url "https://jitpack.io" }
    // maven { url 'https://maven.google.com' } // For Gradle < 4.0
    }
    }


    Now it build successfully. But got another problem about Application.version goes wrong.
     
  44. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,834
    For anyone facing the mismatched version issue, I'm pasting here what we did in Cross Platform Native Plugins and Cross Platform Replay Kit to automate the process.
    WARNING : Here in this script we will try to match exactly the unity's gradle templates versions and make sure you are aware of it when using in your project.

    Code (CSharp):
    1. // Script from Cross Platform Native Plugins - http://u3d.as/bV0
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System.Linq;
    6. using System.Text;
    7.  
    8. #if UNITY_2018_2_OR_NEWER
    9.  
    10. using UnityEditor.Android;
    11. using System.IO;
    12.  
    13. namespace VoxelBusters.NativePlugins.Internal
    14. {
    15.     class GradlePostProcessor : IPostGenerateGradleAndroidProject
    16.     {
    17.         public int callbackOrder { get { return 0; } }
    18.         public void OnPostGenerateGradleAndroidProject(string path)
    19.         {
    20.             MatchUnityMainGradleVersion(path);
    21.             EnableJetifierIfRequired(path);
    22.         }
    23.  
    24.         private void MatchUnityMainGradleVersion(string path)
    25.         {
    26.             string rootGradleVersion = null;
    27.             string rootCompileSdkVersion = null;
    28.             string rootBuildToolsVersion = null;
    29.             string rootTargetSDKVersion = null;
    30.  
    31.             string[] targetProjectPaths =
    32.             {
    33.                 "/native_plugins_lib",
    34.                 "/twitter_lib",
    35.                 "/youtube_lib",
    36.                 "/voxelbusters_utility_lib"
    37.             }; //REPLACE WITH YOUR OWN PROJECT PATHS
    38.  
    39.             // First read the main build.gradle file
    40.             string[] lines = File.ReadAllLines(path + "/build.gradle");
    41.  
    42.             foreach (string eachLine in lines)
    43.             {
    44.                 // Detect gradle version
    45.                 if (HasText(eachLine, "classpath", "tools.build:gradle"))
    46.                 {
    47.                     rootGradleVersion = eachLine;
    48.                 }
    49.                 // Detect compileSdkVersion version
    50.                 else if (HasText(eachLine, "compileSdkVersion"))
    51.                 {
    52.                     rootCompileSdkVersion = eachLine;
    53.                 }
    54.                 // Detect buildToolsVersion version
    55.                 else if (HasText(eachLine, "buildToolsVersion"))
    56.                 {
    57.                     rootBuildToolsVersion = eachLine;
    58.                 }
    59.                 // Detect targetSdkVersion version
    60.                 else if (HasText(eachLine, "targetSdkVersion"))
    61.                 {
    62.                     rootTargetSDKVersion = eachLine;
    63.                 }
    64.             }
    65.  
    66.  
    67.             foreach (string eachProject in targetProjectPaths)
    68.             {
    69.                 UpdateGradleFile(path + eachProject, rootGradleVersion, rootCompileSdkVersion, rootBuildToolsVersion, rootTargetSDKVersion);
    70.             }
    71.         }
    72.  
    73.         private void UpdateGradleFile(string projectPath, string rootGradleVersion, string rootCompileSdkVersion, string rootBuildToolsVersion, string rootTargetSDKVersion)
    74.         {
    75.             string filePath = projectPath + "/build.gradle";
    76.  
    77.             if(File.Exists(filePath))
    78.             {
    79.                 string[] lines = File.ReadAllLines(filePath);
    80.                 string[] updatedLines = new string[lines.Length];
    81.  
    82.                 for (int i=0; i< lines.Length; i++)
    83.                 {
    84.                     string eachLine     = lines[i];
    85.                     string updatedText  = eachLine;
    86.  
    87.                     // Detect gradle version
    88.                     if (HasText(eachLine, "classpath", "tools.build:gradle"))
    89.                     {
    90.                         updatedText = rootGradleVersion;
    91.                     }
    92.                     // Detect compileSdkVersion version
    93.                     else if (HasText(eachLine, "compileSdkVersion"))
    94.                     {
    95.                         updatedText = rootCompileSdkVersion;
    96.                     }
    97.                     // Detect buildToolsVersion version
    98.                     else if (HasText(eachLine, "buildToolsVersion"))
    99.                     {
    100.                         updatedText = rootBuildToolsVersion;
    101.                     }
    102.                     // Detect targetSdkVersion version
    103.                     else if (HasText(eachLine, "targetSdkVersion"))
    104.                     {
    105.                         updatedText = rootTargetSDKVersion;
    106.                     }
    107.  
    108.                     updatedLines[i] = updatedText;
    109.                 }
    110.  
    111.                 File.WriteAllLines(filePath, updatedLines);
    112.             }
    113.         }
    114.  
    115.         private bool HasText(string inputString, string startSearchString, string additionalStringToSearch = null)
    116.         {
    117.             string trimmedText = inputString.Trim();
    118.  
    119.             if(trimmedText.StartsWith(startSearchString, System.StringComparison.InvariantCulture))
    120.             {
    121.                 if(additionalStringToSearch != null)
    122.                 {
    123.                     return trimmedText.Contains(additionalStringToSearch);
    124.                 }
    125.  
    126.                 return true;
    127.             }
    128.  
    129.             return false;
    130.         }
    131.  
    132.         private void EnableJetifierIfRequired(string path)
    133.         {
    134.             string[] files = Directory.GetFiles(Application.dataPath + "/Plugins/Android" , "androidx.*.aar");
    135.  
    136.             if(files.Length > 0)
    137.             {
    138.                 string gradlePropertiesPath = path + "/gradle.properties";
    139.  
    140.                 string[] lines = File.ReadAllLines(gradlePropertiesPath);
    141.  
    142.                 // Need jetifier patch process
    143.                 bool hasAndroidXProperty = lines.Any(text => text.Contains("android.useAndroidX"));
    144.                 bool hasJetifierProperty = lines.Any(text => text.Contains("android.enableJetifier"));
    145.  
    146.                 StringBuilder builder = new StringBuilder();
    147.  
    148.                 foreach(string each in lines)
    149.                 {
    150.                     builder.AppendLine(each);
    151.                 }
    152.  
    153.                 if (!hasAndroidXProperty)
    154.                 {
    155.                     builder.AppendLine("android.useAndroidX=true");
    156.                 }
    157.  
    158.                 if (!hasJetifierProperty)
    159.                 {
    160.                     builder.AppendLine("android.enableJetifier=true");
    161.                 }
    162.  
    163.                 File.WriteAllText(gradlePropertiesPath, builder.ToString());
    164.             }
    165.         }
    166.     }
    167. }
    168.  
    169. #endif
    Functionality :

    1. MatchUnityMainGradleVersion - The above script matches the exact android plugin version, target sdk version, compile sdk version and build tools version of unity's. This is done on purpose and we constantly make sure our native project accepts these updated versions.
    2. EnableJetifierIfRequired : This patches gradle.properties file when you want Jetifier to be enabled for your libraries.

    If you want to patch only gradle.properties for androidX compatibility, you can use below code.

    Code (CSharp):
    1. // Script from Cross Platform Native Plugins - http://u3d.as/bV0
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System.Linq;
    6. using System.Text;
    7.  
    8. #if UNITY_2018_2_OR_NEWER
    9.  
    10. using UnityEditor.Android;
    11. using System.IO;
    12.  
    13. namespace VoxelBusters.NativePlugins.Internal
    14. {
    15.     class GradlePropertiesPostProcessor : IPostGenerateGradleAndroidProject
    16.     {
    17.         public int callbackOrder { get { return 0; } }
    18.         public void OnPostGenerateGradleAndroidProject(string path)
    19.         {
    20.             EnableJetifierIfRequired(path);
    21.         }
    22.         private void EnableJetifierIfRequired(string path)
    23.         {
    24.             string[] files = Directory.GetFiles(Application.dataPath + "/Plugins/Android" , "androidx.*.aar");
    25.  
    26.             if(files.Length > 0)
    27.             {
    28.                 string gradlePropertiesPath = path + "/gradle.properties";
    29.  
    30.                 string[] lines = File.ReadAllLines(gradlePropertiesPath);
    31.  
    32.                 // Need jetifier patch process
    33.                 bool hasAndroidXProperty = lines.Any(text => text.Contains("android.useAndroidX"));
    34.                 bool hasJetifierProperty = lines.Any(text => text.Contains("android.enableJetifier"));
    35.  
    36.                 StringBuilder builder = new StringBuilder();
    37.  
    38.                 foreach(string each in lines)
    39.                 {
    40.                     builder.AppendLine(each);
    41.                 }
    42.  
    43.                 if (!hasAndroidXProperty)
    44.                 {
    45.                     builder.AppendLine("android.useAndroidX=true");
    46.                 }
    47.  
    48.                 if (!hasJetifierProperty)
    49.                 {
    50.                     builder.AppendLine("android.enableJetifier=true");
    51.                 }
    52.  
    53.                 File.WriteAllText(gradlePropertiesPath, builder.ToString());
    54.             }
    55.         }
    56.     }
    57. }
    58.  
    59. #endif
    Note : Make sure you have min 1.2.119 Play Services Resolver version so that you can be compatible with Jetifier/AndroidX workflow (you need to enable Jetifier in settings).

    Do let us know if you need any help regarding this.
     
    Last edited: Jul 11, 2019
    alex_roboto, JohnTube and Qbit86 like this.
  45. sh20020

    sh20020

    Joined:
    Mar 14, 2019
    Posts:
    2
    Hello ! I could not publish my game on google play for 2 months because google play wants x64 and BUILD APP BUNDLE
    and I can not make it
    I use uity2019.1.9 and 2017.4.20 and I have Errors in them
    I post question but any people could resolve it this is my link:
    https://stackoverflow.com/questions...droid-and-build-app-bundle-in-unity-2017-4-17

    How can I publish my game with mode gradle and x86 , x64 and BUILD APP BUNDLE ??????help me please
    thanks
     

    Attached Files:

    • y39.png
      y39.png
      File size:
      68.1 KB
      Views:
      871
  46. Hofmann

    Hofmann

    Joined:
    Sep 30, 2015
    Posts:
    25
    Hi,
    you can't publish the game for two months? Think a little better and you may find that you don't need a BUILD APP BUNDLE for Arm7 and ARM64. Is it news and google, and no one else writes about this possibility? And why? Because Google is trying to force developers to use their auto-encrypted application signing. why? because it's big business.
    I will advise you, just read this link and you can skip AAB:
    https://developer.android.com/google/play/publishing/multiple-apks

    Short Description: Try to create one APK ARM7 under one bundle version code for example 0 = ARM7 and build 1 = ARM64. Gradually upload both APKs to Google Play Store. Ignore the yellow warning and publish ;-)

     
  47. MechEthan

    MechEthan

    Joined:
    Mar 23, 2016
    Posts:
    166
    For 2017.4, 2018.4, 2019.x releases in the last 1-2 months, and moving forward, is it 100% accurate to refer to the contents of:

    .../PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/mainTemplate.gradle

    and the X.X.X name of:
    .../PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-wrapper-X.X.X.jar


    ...To determine Android plugin versions and Gradle versions?

    (Also, should it generally be safe to update the Android plugin version to a new minor release on an exported project, e.g. 3.4.0 to 3.4.2? Android Studio pesters me about it.)
     
  48. boukilmouad

    boukilmouad

    Joined:
    Jan 30, 2019
    Posts:
    3
    Solved for me, the keystore was stored on a folder that have space and apostrophe like " xxx's xxx ", I changed the name of the folder to something like "xxx" and it solved the problem (same thing for the output folder)
     
    MechEthan likes this.
  49. Banemus

    Banemus

    Joined:
    Jul 11, 2013
    Posts:
    9
    Code (CSharp):
    1. CommandInvokationFailure: Gradle build failed.
    2. C:/Program Files/Java/jdk1.8.0_251\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"
    3.  
    4. stderr[
    5.  
    6. FAILURE: Build failed with an exception.
    7.  
    8. * What went wrong:
    9. A problem occurred configuring root project 'gradleOut'.
    10. > Failed to create MD5 hash for file 'C:\Users\----\caches\modules-2\files-2.1\com.android.tools.build\gradle\2.3.0\f46008799137ca08edd65089fb544e1d7ceff3e7\gradle-2.3.0.jar'.
    11.  
    12. * Try:
    13. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    14.  
    15. BUILD FAILED in 7s
    16. ]
    17. stdout[
    18.  
    19. ]
    20. exit code: 1
    21. UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    22. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    23. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
    24. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    25. Rethrow as GradleInvokationException: Gradle build failed
    26. UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
    27. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    28. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    29. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    30.  
    I have been having this issue on my laptop. I can build my project just fine on my main computer but not on my laptop. I keep getting this error and i do not know what to do.
     
  50. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    > C:\Users\----\caches\...

    My guess: your username has some Unicode characters, and Gradle doesn't work well with that.
     
    Voxel-Busters likes this.