Search Unity

Question Can't export an apk in Unity 2019.2.21f1 (64-bit) please help

Discussion in 'Editor & General Support' started by cgutierrez71, Jun 6, 2023.

  1. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69
    Hello everyone, please I need help. I've seen many Youtube tutorials, but nothing seems to work with my problem...

    I'm getting the error: Gradle build failed...

    Please, I appreciate your comments and help. I need to work with this version of the editor because my project has a lot of legacy GUI textures that don't work in the latest versions.

    Thank you so much.


    CommandInvokationFailure: Gradle build failed.
    C:\Program Files\Java\jdk1.8.0_77\bin\java.exe -classpath "D:\UNITY\gradle\gradle-6.9.2\lib\gradle-launcher-6.9.2.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

    stderr[

    FAILURE: Build failed with an exception.

    * What went wrong:
    A problem occurred configuring root project 'gradleOut'.
    > Could not resolve all artifacts for configuration ':classpath'.
    > Could not find com.android.tools.build:gradle:6.9.2.
    Searched in the following locations:
    - https://jcenter.bintray.com/com/android/tools/build/gradle/6.9.2/gradle-6.9.2.pom
    If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
    Required by:
    project :

    * Try:
    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.

    * Get more help at https://help.gradle.org

    BUILD FAILED in 2s
    ]
    stdout[

    Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See https://docs.gradle.org/6.9.2/userguide/command_line_interface.html#sec:command_line_warnings
    ]
    exit code: 1
    UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    Rethrow as GradleInvokationException: Gradle build failed
    UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    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 <502f1b7df2d7430696af84c6f02852ed>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <502f1b7df2d7430696af84c6f02852ed>:0)
    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:281)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    How to troubleshoot build failures:

    First, make a blank project with a single blank scene and prove that it builds successfully.

    If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

    Until you can build a blank project to the target platform, don't fiddle with anything else.

    Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

    Most often things that prevent building are third-party libraries such as Firebase.

    Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

    It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

    Android build not building:

    Recently (circa July 2022) there have been reports of Unity's installer failing to install the Android Tools.

    https://forum.unity.com/threads/cant-build-for-android.1306098/

    Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022:

    https://forum.unity.com/threads/aab...y-2021-3-8-with-jdk-1-8.1322211/#post-8551193

    Android Gradle errors and other related stuff:

    https://forum.unity.com/threads/unity-gradle-bug-please-help.1368018/#post-8625789
     
    cgutierrez71 likes this.
  3. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    I am in shock!!! you're right... :eek: I created a new empty project and was able to export the apk without any problem... I didn't think it could happen but it did... you're a genius. That means the JDK, SDK, NDK and gradle are correct :)

    So the following is what is happening with my game :( I could export the apk in Unity Unity 2018.1.9f2 (64 bit) but now I can't. What do you suggest?

    Thank you so much.
     

    Attached Files:

  4. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    Hi Kurt, I've been doing a lot of tests and at least I know where the problem is. To find out what was causing the "Gradle build failed" error I started removing things little by little until it allowed me to export the apk and finally it let me export it if I remove the files: "mainTemplate.gradle" and "AndroidManifest.xml" Obviously I can't get rid of AndroidManifest as it's necessary to upload the file to Google play, but if I don't remove the manifest, I get the following error when exporting: "Android Resource Linking failed. See the console for details" and around 1000 new errors appear in console. I think what I should do is modify something in the Android Manifest, I don't know if you see what could be causing the error. This is my Android Manifest:
    Please help me, you are the only person who has guided me so far and thanks to you I have been able to get here.


    <?xml version="1.0" encoding="utf-8"?>
    <manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    android:installLocation="preferExternal"
    android:theme="@android:style/Theme.NoTitleBar"
    android:versionCode="1"
    android:versionName="0.9.7.2">

    <supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"
    android:xlargeScreens="true"
    android:anyDensity="true"/>

    <!-- android:debuggable should be removed in release build -->
    <application
    android:icon="@drawable/app_icon"
    android:label="@String/app_name"
    android:debuggable="true"
    android:hasCode="true">

    <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
    android:launchMode="singleTask"
    android:label="@String/app_name"
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">

    </activity>

    <activity android:exported="true" android:name="com.unity3d.player.UnityPlayerActivity"
    android:launchMode="singleTask"
    android:label="@String/app_name"
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
    android:launchMode="singleTask"
    android:label="@String/app_name"
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />

    </activity>

    <receiver android:exported="true" android:name="com.amazon.device.iap.ResponseReceiver">
    <intent-filter>
    <action
    android:name="com.amazon.inapp.purchasing.NOTIFY"
    android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
    </intent-filter>
    </receiver>

    </application>

    <!--Fortumo start-->
    <receiver android:name="mp.MpSMSReceiver">
    <intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
    </receiver>

    <service android:name="mp.MpService" />
    <service android:name="mp.StatusUpdateService" />

    <activity
    android:name="mp.MpActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    <!--Fortumo end-->

    <!--all-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <!--Google Play-->
    <uses-permission android:name="com.android.vending.BILLING" />
    <!--Amazon requires no permissions -->
    <!--Samsung Apps-->
    <uses-permission android:name="com.sec.android.iap.permission.BILLING" />
    <!--Nokia-->
    <uses-permission android:name="com.nokia.payment.BILLING"/>
    <!--SlideME-->
    <uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />

    <!-- Highly recommended permission to get more ads and revenue -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!--Google Play Advertising ID-->
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    </manifest>
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    This is too arcane for me, sorry! I would need to noodle with the machine right there.

    You should report your own post and ask this thread be moved to the android group.

    Or just go there and make a fresh post linking these specific things you have found.