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. Dismiss Notice

Question I can't export the apk file

Discussion in 'Android' started by cgutierrez71, Jun 10, 2023.

  1. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69
    Hello everyone, please I need your help. I have my game on Unity 2019.2.21f1 (64-bit). Every time I try to export the apk, I'm getting the error: Gradle build failed...

    To know if the problem is due to the game or the editor, I created a new empty project and was able to export the apk without any problem... That means the JDK, SDK, NDK and gradle are correct.

    After doing a lot of tests I realize 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.
    I really appreciate your comments and help.

    Thanks


    <?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>
     
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,817
    Share the complete error under "CommandInvocationFailure" entry.
     
  3. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    Hi, the "Gradle build failed" error should provide more details about the error or the reason why it failed. If I look at the manifest, I think you should change

    Code (csharp):
    1.  <receiver android:name="mp.MpSMSReceiver">
    to

    Code (csharp):
    1.  <receiver android:exported="true" android:name="mp.MpSMSReceiver">
    if it doesn't help try to export the project to the Android Studio and try to build there.
     
    Voxel-Busters likes this.
  4. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    Hi Duriga I chanded that but still get the error "Android Resource Linking failed." with 480 errors.

    What is the relationship betwen "mainTemplate.gradle" and "AndroidManifest. xml" ?
     

    Attached Files:

  5. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    How can I copy all the console errors? There are too much
     
  6. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    I found the LOG
     

    Attached Files:

  7. tduriga

    tduriga

    Joined:
    Dec 9, 2015
    Posts:
    52
    As you can see in "Screenshot_3" there is clear reason of the failure. You have <receiver>, <activity> and <service> elements outside of the <application></application> element.

    Just move everything between "Fortumo start" and "Fortumo end" to the correct place and it should work, or you might get next error and you could find it in CommandInvocationFailure log entry exactly like on "Screenshot_3".

    Also if you don't know where some elements in manifest should be placed, you can always find out if you check the Android documentation. Here is link to the receiver element for example: <receiver> | Android Developers.
     
    Voxel-Busters and cgutierrez71 like this.
  8. cgutierrez71

    cgutierrez71

    Joined:
    Oct 15, 2013
    Posts:
    69

    My friend... you solved the problem... I can't believe it!!! I've spent over a week trying to figure out where the problem was and you did it right away... I really appreciate your help. :)

    Screenshot_4.png Screenshot_5.png
     
    Voxel-Busters and tduriga like this.