Search Unity

Exporting Gradle Project - How to include gradlew

Discussion in 'Android' started by giacomohomunculus, Jan 31, 2019.

  1. giacomohomunculus

    giacomohomunculus

    Joined:
    Oct 3, 2018
    Posts:
    20
    Setting up an automated build process. Want to export the Unity project as a gradle project so that I can build in two steps (use two seperate docker images).

    When Unity exports the project, there isn't a gradlew file in the project folder. How might I go about including one?
     
  2. charlesJRG

    charlesJRG

    Joined:
    Jul 18, 2016
    Posts:
    16
    Our solution here is to manually copy the gradlew from the local PC into the exported gradle project in a postbuild event. We keep the gradlews in a folder with other relevant gradle scripts and do a file copy.

    This sample code assumes a folder called Gradle at the root level of the project (same level as /Assets/) with all relevant gradle files.

    Code (CSharp):
    1. var gradlewsPath = Path.Combine(new DirectoryInfo(Application.dataPath).Parent.FullName, GradleDir);
    2.             var gradleWrapperPath = Path.Combine(gradlewsPath, "gradle");
    3.  
    4.             foreach (var directory in Directory.GetDirectories(gradleWrapperPath, "*", SearchOption.AllDirectories))
    5.             {
    6.                 Directory.CreateDirectory(directory.Replace(gradlewsPath, projectPath));
    7.             }
    8.             foreach (var file in Directory.GetFiles(gradleWrapperPath, "*", SearchOption.AllDirectories))
    9.             {
    10.                 File.Copy(file, file.Replace(gradlewsPath, projectPath), true);
    11.             }
    12.  
    13.             File.Copy(Path.Combine(gradlewsPath, GradlewName), Path.Combine(projectPath, GradlewName), true);
     
  3. giacomohomunculus

    giacomohomunculus

    Joined:
    Oct 3, 2018
    Posts:
    20
    Thanks for the reply - seems like a simple enough solution. For now I am just creating a gradle wrapper after the project exports.
     
  4. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    18
    Hi,
    Where exactly can I find the gradlew files on my computer?
    I don't need to make a gradle export. I just want to upload the NDK Symbol files to Firebase Crashlytics.
    As described here: https://firebase.google.com/docs/crashlytics/ndk-reports

    @charlesJRG , How were you able to get a working gradlew file from the Unity project?
     
    Last edited: Aug 27, 2019
  5. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    did you manage to do this?
     
  6. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    18
    Not yet.
    I did a one time export to a gradle project to get a gradlew file.
    It seems to me that this is just a generic file, I can't find anything in there that seems to be projectspecific.
    So I guess I can use this file to upload the symbols.

    I am currently trying to integrate the exported gradlew file (and other dependencies) in the build process.
    I will update here when I have something that works.

    Edit: I am trying to find the folder where I shoudld copy the gradle files.
    I expected there to be a gradleOut folder, but I can't find it in the StagingArea

    Here is an update:
    I first forgot to put Unity back to not export a gradle project.
    The gradleOut folder is at {UnityProjectPath}/Temp/gradleOut

    In a postbuildprocess I copy the gradle files to that folder and use
    System.Diagnostics.ProcessStartInfo
    to start the command tool (cmd.exe on windows, I will have to find out what to use on Mac)

    I don't know how to see if the upload of the symbols was successful though.
    I will update here if I can get it working successfully.

    Update 2:
    I currently get a warning like this. I added the obj folder because I received an error first that said it enjoyed having a folder with that name. I provided. It did not deliver.
     WARN - Crashlytics found no object files in {UnityProjectPath}\Temp\gradleOut\obj. Is the -androidNdkOut setting configured correctly?

    I don't know what kind of files it would expect in that folder.
    I don't know if I can ignore this warning. It seems like it won't generate the correct symbols if the folder is empty though.

    Update 3:
    I managed to get something working. I can now execute
    ./gradlew crashlyticsUploadSymbolsDebug
    correctly. It seems to update just fine.
    I tested it by calling it manually. I don't know how I can check if it runs correctly as a postbuildstep though. But I imagine it does.
    What I did: I just added 2 lines in the crahlytics scope in the gradletemplate.
    Code (Boo):
    1. // Enable Crashlytics NDK reporting
    2. crashlytics {
    3.     enableNdk true
    4.     androidNdkOut 'src/main/jniLibs'
    5.     androidNdkLibsOut 'src/main/jniLibs'
    6. }
    I hope it helps.
     
    Last edited: Sep 23, 2019
  7. thiagolrosa

    thiagolrosa

    Joined:
    Feb 22, 2017
    Posts:
    60
    How did you get the crashlytics API key?

    The crashlyticsUploadSymbolsDebug task is failing because it can't find the API key.

    $ ./gradlew crashlyticsUploadSymbolsRelease
    > Task :fabricGenerateResourcesRelease FAILED
    ERROR - Crashlytics Developer Tools error.
    java.lang.IllegalArgumentException: Crashlytics found an invalid API key: null.
    Check the Crashlytics plugin to make sure that the application has been added successfully!
     
  8. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    18
    I think that is part of the strings.xml file