Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Gradle error during android building

Discussion in '2018.3 Beta' started by justtime, Oct 14, 2018.

  1. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    374
    After migrating from 2017.2.2p4 to 2018.3b5 during android build process i faced with gradle 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. * Where:
    9. Build file 'C:\Unity_Projects\JamTracks_2018.3b\Temp\gradleOut\build.gradle' line: 19
    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 C:\Unity_Projects\JamTracks_2018.3b\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 10s
    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.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    28. UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    29. UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
    30. UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <480e50343593457c94864bd38c09a2ca>:0)
    31. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <480e50343593457c94864bd38c09a2ca>:0)
    32. Rethrow as GradleInvokationException: Gradle build failed
    33. UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <480e50343593457c94864bd38c09a2ca>:0)
    34. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
    35. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
    36. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    37.  
    Used gradle file
    Code (CSharp):
    1. buildscript {
    2.     repositories {
    3.         jcenter()
    4.     }
    5.  
    6.     dependencies {
    7.         classpath 'com.android.tools.build:gradle:2.1.0'
    8.     }
    9. }
    10.  
    11. allprojects {
    12.    repositories {
    13.       flatDir {
    14.         dirs 'libs'
    15.       }
    16.    }
    17. }
    18.  
    19. apply plugin: 'com.android.application'
    20.  
    21. dependencies {
    22.     compile 'com.android.support:multidex:1.0.1'
    23.     compile fileTree(dir: 'libs', include: ['*.jar'])
    24.     compile 'com.android.support:multidex:1.0.1'
    25. **DEPS**}
    26.  
    27. android {
    28.     compileSdkVersion **APIVERSION**
    29.     buildToolsVersion '**BUILDTOOLS**'
    30.  
    31.     defaultConfig {
    32.         targetSdkVersion **TARGETSDKVERSION**
    33.         applicationId '**APPLICATIONID**'
    34.         multiDexEnabled true
    35.        
    36.         versionCode 25
    37.     }
    38.  
    39.     lintOptions {
    40.         abortOnError false
    41.     }
    42.  
    43.     aaptOptions {
    44.         noCompress '.unity3d', '.ress', '.resource', '.obb'
    45.     }
    46.  
    47. **SIGN**
    48.     buildTypes {
    49.           debug {
    50.              //minifyEnabled **MINIFY_DEBUG**
    51.              //useProguard **PROGUARD_DEBUG**
    52.              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    53.               jniDebuggable true
    54.           }
    55.           release {
    56.              //minifyEnabled **MINIFY_RELEASE**
    57.              //useProguard **PROGUARD_RELEASE**
    58.               proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    59.               **SIGNCONFIG**
    60.           }
    61.     }
    62.  
    63.  
    64.     splits {
    65.        
    66.             // Configures multiple APKs based on ABI.
    67.             abi {
    68.        
    69.               // Enables building multiple APKs per ABI.
    70.               enable true
    71.        
    72.               // By default all ABIs are included, so use reset() and include to specify that we only
    73.               // want APKs for x86 and x86_64.
    74.        
    75.               // Resets the list of ABIs that Gradle should create APKs for to none.
    76.               reset()
    77.        
    78.               // Specifies a list of ABIs that Gradle should create APKs for.
    79.               include "armeabi-v7a"
    80.               //include "x86"
    81.        
    82.               // Specifies that we do not want to also generate a universal APK that includes all ABIs.
    83.               universalApk false
    84.             }
    85.           }
    86. }
    87.  
    88. // Map for the version code that gives each ABI a value.
    89. ext.abiCodes = ['armeabi-v7a':1, x86:2, x86_64:3]
    90.  
    91. // For per-density APKs, create a similar map like this:
    92. // ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3]
    93.  
    94. import com.android.build.OutputFile
    95.  
    96. // For each APK output variant, override versionCode with a combination of
    97. // ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
    98. // is equal to defaultConfig.versionCode. If you configure product flavors that
    99. // define their own versionCode, variant.versionCode uses that value instead.
    100. android.applicationVariants.all { variant ->
    101.  
    102.   // Assigns a different version code for each output APK
    103.   // other than the universal APK.
    104.   variant.outputs.each { output ->
    105.  
    106.     // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
    107.     def baseAbiVersionCode =
    108.             // Determines the ABI for this variant and returns the mapped value.
    109.             project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
    110.  
    111.     // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
    112.     // the following code does not override the version code for universal APKs.
    113.     // However, because we want universal APKs to have the lowest version code,
    114.     // this outcome is desirable.
    115.     if (baseAbiVersionCode != null) {
    116.  
    117.       // Assigns the new version code to versionCodeOverride, which changes the version code
    118.       // for only the output APK, not for the variant itself. Skipping this step simply
    119.       // causes Gradle to use the value of variant.versionCode for the APK.
    120.       output.versionCodeOverride =
    121.               baseAbiVersionCode * 1000 + variant.versionCode
    122.     }
    123.   }
    124. }
    125.  
     
  2. ScottyB

    ScottyB

    Joined:
    Apr 4, 2011
    Posts:
    137
    When updating between major versions of Unity, you should compare your custom Gradle file with Unity's Gradle template file because Unity will sometimes change important details and you'll need to keep up-to-date.

    For example, below is mainTemplate.gradle file that ships with Unity 2018.3.0b5. On Mac that can be found at /Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/mainTemplate.gradle (not sure where it is on Windows but should be similar).

    You'll see a number of differences to your Gradle file, most notably for your error are the differences in the
    buildscript
    and
    allprojects
    sections.

    Code (CSharp):
    1. // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    2.  
    3. buildscript {
    4.     repositories {
    5.         jcenter()
    6.         google()
    7.     }
    8.  
    9.     dependencies {
    10.         classpath 'com.android.tools.build:gradle:3.2.0-alpha15'
    11. **BUILD_SCRIPT_DEPS**}
    12. }
    13.  
    14. allprojects {
    15.     repositories {
    16.         jcenter()
    17.         google()
    18.         flatDir {
    19.             dirs 'libs'
    20.         }
    21.     }
    22. }
    23.  
    24. apply plugin: 'com.android.application'
    25. **APPLY_PLUGINS**
    26.  
    27. dependencies {
    28.     implementation fileTree(dir: 'libs', include: ['*.jar'])
    29. **DEPS**}
    30.  
    31. android {
    32.     compileSdkVersion **APIVERSION**
    33.     buildToolsVersion '**BUILDTOOLS**'
    34.  
    35.     compileOptions {
    36.         sourceCompatibility JavaVersion.VERSION_1_8
    37.         targetCompatibility JavaVersion.VERSION_1_8
    38.     }
    39.  
    40.     defaultConfig {
    41.         minSdkVersion **MINSDKVERSION**
    42.         targetSdkVersion **TARGETSDKVERSION**
    43.         applicationId '**APPLICATIONID**'
    44.         ndk {
    45.             abiFilters **ABIFILTERS**
    46.         }
    47.         versionCode **VERSIONCODE**
    48.         versionName '**VERSIONNAME**'
    49.     }
    50.  
    51.     lintOptions {
    52.         abortOnError false
    53.     }
    54.  
    55.     aaptOptions {
    56.         noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]
    57.     }**SIGN**
    58.  
    59.     buildTypes {
    60.         debug {
    61.             minifyEnabled **MINIFY_DEBUG**
    62.             useProguard **PROGUARD_DEBUG**
    63.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
    64.             jniDebuggable true
    65.         }
    66.         release {
    67.             minifyEnabled **MINIFY_RELEASE**
    68.             useProguard **PROGUARD_RELEASE**
    69.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD****SIGNCONFIG**
    70.         }
    71.     }**PACKAGING_OPTIONS****SPLITS**
    72. **BUILT_APK_LOCATION**
    73.     bundle {
    74.         language {
    75.             enableSplit = false
    76.         }
    77.         density {
    78.             enableSplit = false
    79.         }
    80.         abi {
    81.             enableSplit = true
    82.         }
    83.     }
    84. }**SPLITS_VERSION_CODE****REPOSITORIES****SOURCE_BUILD_SETUP**
    85.  
     
  3. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    374
    After all changes i've got this
    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.  
     
  4. NinjaCat

    NinjaCat

    R&D Minion Unity Technologies

    Joined:
    Aug 22, 2013
    Posts:
    69
    Hey,

    ScottyB is correct, we've updated the gradle build template quite a bit between those versions, so your custom template has to be updated to match the new version. The last error you've posted seems to lack a bit of information - was there any other output in the console? How does your custom build template look like now?
     
  5. DoBrain

    DoBrain

    Joined:
    Mar 25, 2017
    Posts:
    1
    I'm also facing the similar problem.
    I have swapped the lib folder of gradle in Unity playbackEngine folder,
    (to the gradle 4.6 version according to this advice :
    https://answers.unity.com/questions/1490992/change-version-of-gradle-to-46.html )
    and override the mainTemplate.gradle and libTemplate.gradle with this files.
    (https://github.com/deltaDNA/unity-sdk/tree/master/Assets/Plugins/Android)
    and now I'm seeing the same error

    Code (CSharp):
    1. FileNotFoundException: Temp\gradleOut\build\outputs\apk\gradleOut-debug.apk does not exist
    2. System.IO.File.Move (System.String sourceFileName, System.String destFileName) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:318)
    3. UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    4. UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
    5. UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
    6. UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
    7. UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:186)
    what can I do???
    Should I export project and modify it with Android Studio?
    I can, but I would like to Build & Run in Unity...
    (I'm Unity 5.6.5f)
     
    SbiM and HoDragon like this.
unityunity