Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Painful Unity project export to Android each build (I'm doing something wrong)

I would like to know if there is a faster way than the following steps to test Unity app with Android (gradle export):

  1. Change something in unity
  2. Build settings & Run --> Export (new Gradle)
  3. Now the old gradle in the Android project is replaced, so i need to copy paste from a backup
  4. The Res folder is also replaced, so I need to copy paste the backup one
  5. Finally Build and Run the APK on the device

Steps 3 and 4 are obviously what makes this process painful (slow), I found the manifest.xml of the Unity android plugin, so this one stays the same (edited it directly in Unity). So am I doing something wrong ? Is there a way to update only parts of the Android project (like, if I only changed one line of a C# Script, just rebuild this one for Android)

Tell me if I'm not clear enough with my explanation :)

EDIT: I Already posted this in Unity forum but I didn't get any answer yet after a day

like image 434
Nayk0 Avatar asked Mar 16 '17 08:03

Nayk0


People also ask

How do I export Unity games to my phone?

Once your platform is switched over to Android, the Switch Platform button should be replaced with a Build button. Click on the Build button, and Unity should prompt you for a location to save your APK file. Save your APK file and upload it onto your phone. Then, open it on your phone to install it as an app!

How do I change from gradle to internal Unity?

Go to Preferences > External Tools > Android > Gradle Installed with Unity. Clear the option, and specify a custom version of 5.6. 4 or later.

How do I enable Android project in Unity?

During the installation of the Unity Editor, make sure to include the Android Build Support module by checking the box next to it. Expand the Android Build Support module. If you are using Unity 2019 or later, add the Android SDK & NDK Tools module. On the Projects tab, click New to start a new Unity project.


2 Answers

You can create your own Gradle file. Put it in Plugins/Android folder and call it mainTemplate.gradle It will use that.

As far as I know, there is no way to rebuild just part of it. Unity does not create java files from the c# code. It creates its own modules and uses them directly.

BTW, why are you exporting at all? Why not compile directly to your device?

like image 154
theblitz Avatar answered Nov 03 '22 01:11

theblitz


I just wanted an additional answer for this question even though it is a bit old (just in case anyone else in the future is wondering about this like me). I personally need to make use of both Android Studio and Unity so making a plugin wasn't really an option for me.

Now I have a custom gradle file as explained in the accepted answer. However I have also added an additional resource folder (Explained well by Android here: https://developer.android.com/studio/write/add-resources.html).

You basically just have to edit your custom gradle file to add paths to both resource directories. Add the resources you don't want Unity to overwrite to the other resource folder.

Now every time you rebuild to the project the resources remain and you don't have to copy them back in.

like image 30
Michelle Morry Avatar answered Nov 02 '22 23:11

Michelle Morry