Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy path wrongly set and error in build options #287

Closed
WouterVandenputte opened this issue Dec 25, 2020 · 14 comments
Closed

Copy path wrongly set and error in build options #287

WouterVandenputte opened this issue Dec 25, 2020 · 14 comments

Comments

@WouterVandenputte
Copy link

Describe the bug
First of all, love it that there is finally support for adding Unity to flutter!
Now for the bug, the issue is twofold

  1. The build options make the build fail
  2. The path to copy the .apk is wrongly formatted

A clear and concise description of what the bug is.

To Reproduce
When pressing Flutter > Export Android, line 55 of build.cs will crash. This is the exception thrown

InvalidOperationException: The build target does not support build appending.
UnityEditor.BuildPipeline.BuildPlayer (System.String[] scenes, System.String locationPathName, System.String assetBundleManifestPath, UnityEditor.BuildTargetGroup buildTargetGroup, UnityEditor.BuildTarget target, UnityEditor.BuildOptions options, System.String[] extraScriptingDefines) (at <1e441e8684a14fe4b8f8a926d91afc3a>:0)
UnityEditor.BuildPipeline.BuildPlayer (UnityEditor.BuildPlayerOptions buildPlayerOptions) (at <1e441e8684a14fe4b8f8a926d91afc3a>:0)
UnityEditor.BuildPipeline.BuildPlayer (System.String[] levels, System.String locationPathName, UnityEditor.BuildTarget target, UnityEditor.BuildOptions options) (at <1e441e8684a14fe4b8f8a926d91afc3a>:0)
Build.DoBuildAndroid (System.String buildPath, System.Boolean isPlugin) (at Assets/FlutterUnityIntegration/Editor/Build.cs:55)
Build.DoBuildAndroidLibrary () (at Assets/FlutterUnityIntegration/Editor/Build.cs:23)

I have manually been editing stuff and the problem lies with defining var options = BuildOptions.AcceptExternalModificationsToPlayer;. It seems that overwriting it with options = BuildOptions.None; at least mitigated it, but I assume that is not something a user actually needs.

With this new options set, retrying Flutter > Export Android a new issue arises, this is the ouptut

DirectoryNotFoundException: Could not find a part of the path 'D:\repositories\my_flutter_project\unity\MyUnityProject\Builds\MyUnityProject.apk\unityLibrary'.

I tracked the issue and the error can be traced back to build.cs line 23

DoBuildAndroid(Path.Combine(apkPath, "unityLibrary"), false);

This Path combines apkPath which is D:\repositories\my_flutter_project\unity\MyUnityProject\Builds\MyUnityProject.apk\ and then tries to create a subfolder, yet you cannot create a folder inside a file. So I ASSUME the intended directory would be

D:\repositories\my_flutter_project\unity\MyUnityProject\Builds\unityLibrary\MyUnityProject.apk\

Expected behavior
The build succeeds and the copy is done to wherever the plug expects it to be.

Desktop (please complete the following information):

  • OS: Windows 10
  • Unity 2020.2.1f1
  • flutter_unity_widget 3.0.2
@BlickwinkelTour
Copy link

Hi, I just started with flutter development and nw integrated unity. I ran into the same issue and edited the build.cs a littlebit. the export works for now. But in my case handling with the integration of Unity into Flutter/Android feels a bit wonky. I also tried to edit all the dependencies and manifest from scratch, so that I could start from a clean Flutter project. But unfortunately I am too much of a noob to know what I was doing, and I couldn´t get the dependencies to work properly. I am glad my cs editing works now. I know, this has nothing to do with Flutter/Unity, but I hope that someone could make a deep dive (or point to a good tutorial) reagarding build.gradle, AndroidManifest (merging) SDK versions etc. Keep up the good work to all the plugin devs! Thank you!! B

and herés the whole script.
What I did: just added another variable for a "buildPath" so that the Copy functions don´t point to the apk-file.
Don´t expect me that I knew what I was doing, but it works ;P
Build.cs.txt

@mathtasatlime
Copy link

@juicycleff I'm also running in the exact same error. Have you any solution for this problem?

@juicycleff
Copy link
Owner

Hi @mathtasatlime theres a v4 branch where I am fixing a lot, you can test it out will release fir alpha soon. Aside I have not seen this error, and I've done multiple exports, what version of unity are you using?

@mathtasatlime
Copy link

Thanks @juicycleff !
Atm I'm using 2019.4.18f1.

Steps:

  1. Download the current version of your repo.
  2. open the example unity project with 2019.4.18f1
  3. click on "Export Android"
  4. exactly to above mentioned errors occur

@juicycleff
Copy link
Owner

@mathtasatlime its weird as I have exported fir that exact version, did you select export Android or Export Android Plugin

@mathtasatlime
Copy link

definitely export Android.

I successfully used the export function several times in last autemn. Yesterday I tried it again and the errors occured.

@alexanderameye
Copy link

I had this same issue but the fix was super easy.

This comment fixed it for me: #234 (comment)

@BlickwinkelTour
Copy link

BlickwinkelTour commented Feb 4, 2021

Hi, it is a simple path error in the build.cs script. It tries to make a path in the apk file. just overwrite the build.cs with this:
Build.cs.txt

Sorry git code snippet doesn´t work.
That worked for me

@BlickwinkelTour
Copy link

BlickwinkelTour commented Feb 4, 2021

Oh I am Sorry, I hardcoded my project folder . you might need to change it.
public static void DoBuildAndroid(String buildPath, bool isPlugin) { ... Directory.CreateDirectory("E:/Blickwinkel_Tour/Unity_Projects/Remote_Client/Blickwinkel_Remote/Builds/unityLibrary"); );

@BlickwinkelTour
Copy link

BlickwinkelTour commented Feb 4, 2021

Damn it, can somebody explain how to use this github codesnippe t thing correctly ? :D

@mathtasatlime
Copy link

I had this same issue but the fix was super easy.

This comment fixed it for me: #234 (comment)

It fixed it for me as well! Thank you a lot 👍

@mathtasatlime
Copy link

I had this same issue but the fix was super easy.

This comment fixed it for me: #234 (comment)

btw, do I have to change to BuildOptions.None for a release build ?

@ksroo
Copy link

ksroo commented May 27, 2021

work with me
Build.cs.txt

@dibenedetto
Copy link

Hi, it is a simple path error in the build.cs script. It tries to make a path in the apk file. just overwrite the build.cs with this:
Build.cs.txt

i suspect there is still an error where resources are copied:
Copy(Path.Combine(apkPath + "/launcher/src/main/res"), Path.Combine(androidExportPath, "src/main/res"));

looking at the unity project directory, the subtree "/launcher/src/main/res" is inside <unity_project>/Temp/gradleOut/

so shouldn't we replace the apkPath here with the aforementioned gradleOut subfolder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants