OneSignal / OneSignal-Unity-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Other
222 stars 61 forks source link

Gradle build failed using latest 5.0.2 asset #646

Closed breban1 closed 1 year ago

breban1 commented 1 year ago

How can we help?

I am getting a Gradle build error when I build my project with the latest OneSignal asset 5.0.2 from the repo.

BUILD ERROR

FAILURE: Build failed with an exception.

I'm not an android programmer so not sure where to look. I must have another file somewhere, but doing a directory search yielded only the 3 kotlinx files in Assets/Plugins/Android (core, core-jvm, core-android all 1.6.4).

Hoping someone can help. Thanks.

Using Unity 2020.3.42f1

Code of Conduct

shepherd-l commented 1 year ago

Could you try

  1. Enabling these custom templates in Edit > Project Settings > Player > Android > Publishing Settings
    • Custom Main Gradle Template
    • Custom Gradle Properties Template
  2. Then resolve your Android dependencies from Assets > External Dependency Manager > Android Resolver > Force Resolve

And let us know if this works for you?

I appreciate that you took the time to look into the issue.

If you would like to know - both kotlinx_coroutines_core and kotlinx_coroutines_core-jvm contain a kotlinx_coroutines_core.version file. We discovered that duplicate kotlinx_coroutines_core.version files occur because the EDM4U resolver picks up org.jetbrains.kotlinx.kotlinx-coroutines-core-1.6.4.jarand org.jetbrains.kotlinx.kotlinx-coroutines-core-jvm-1.6.4.jar. This seems like a bug with EDM4U because the core module is the same as the core-jvm module but for a different platform.

breban1 commented 1 year ago

Okay, I checked those 2 boxes.

Now: 1) After pressing Force Resolve, it immediately shows, "Android Dependencies Resolution Succeeded" without showing the popup with all the text in it with a progress bar. There are also 0 files related to androidx, kotlix, etc. in the Assets/Plugins/Android directory. There used to be a bunch of files there.

2) When I try to build, I get a dialog with error mainTemplate.gradle need to be updated! We've detected that your custom mainTemplate.gradle file is using the old android appilcation format and needs to be upgraded to function as an android library. We can try to do this automatically, your current mainTemplate.gradle file will be backed up. Continue?

Waiting to hear back before continuing.

shepherd-l commented 1 year ago
  1. After pressing Force Resolve, it immediately shows, "Android Dependencies Resolution Succeeded" without showing the popup with all the text in it with a progress bar. There are also 0 files related to androidx, kotlix, etc. in the Assets/Plugins/Android directory. There used to be a bunch of files there.

This is supposed to happen, so all good there

  1. When I try to build, I get a dialog with error mainTemplate.gradle need to be updated! We've detected that your custom mainTemplate.gradle file is using the old android appilcation format and needs to be upgraded to function as an android library. We can try to do this automatically, your current mainTemplate.gradle file will be backed up. Continue?

I would try doing this, let me know how it goes. I was unable to reproduce that message with a new project on 2020.3.42f1. (What I suspect is happening is that the mainTemplate.gradle was generated on a previous Unity Editor version. You can try deleting the mainTemplate.gradle and mainTemplate.gradle.meta file and then check "Custom Main Gradle Template" again)

breban1 commented 1 year ago

Sorry for all the back and forth.

I pressed OK to number 2 above, and a new dialog showed up without any time between the original dialog: mainTemplate.grade. needs to be updated! Assets/Plugins/Android/mainTemplate.gradle file is using a deprecatee way of controlling with tool should be used to do the minification. To fix this, remove "useProguard" entries yourself. We can also do this automatically, your curent mainTemplate will be backed up. Continue?

Rabbit hole lol. Looking forward to hearing back.

shepherd-l commented 1 year ago

No worries, glad I could help!

In your gradleTemplate.properties file, can you delete this line of code:

android.enableR8=**MINIFY_WITH_R_EIGHT**

and try building again - let me know the results

I ran into that issue before (on 2021.3 but not on 2022) and that worked for me

breban1 commented 1 year ago

Deleted:

android.enableR8=**MINIFY_WITH_R_EIGHT**

Same error dialog.

I do have a proguard file:

-keep class com.hippogames.simpleandroidnotifications.* { *; }
-keep class com.applovin.sdk.unity.** { *; }
-keep class com.takohi.unity.plugins.** { *; }
-keep class com.unity.purchasing.**{*;}
-keep class com.android.vending.billing.**{*;}
-dontwarn com.unity.purchasing.**

That's the whole file, not sure if that helps you.

shepherd-l commented 1 year ago

Looking over the dialog, I realize that I haven't seen that message before for mainTemplate.gradle

You can add back android.enableR8=**MINIFY_WITH_R_EIGHT** for now. Sorry about that

In your mainTemplate.gradle, does your aaptOptions look like this?

aaptOptions {
        noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**PACKAGING_OPTIONS**

If not, could you try pressing Continue and report back?

Hopefully something changes because I haven't been able to reproduce this myself. If it comes down to it, you can try to reproduce the issue in a new project and share it with me

breban1 commented 1 year ago

Okay I put MINIFY back and continued through the 2 dialogs.

New one popped up: ERROR mainTemplate.gradle is using the old aaptOptions noCompress property definition which does not include types defined by unityStreamingAssets constant.

OK

shepherd-l commented 1 year ago

Does your mainTemplate.gradle aaptOptions look like what I mentioned above?

You can also try to using newer version of Unity. Unity announced 2022 LTS and documents that 2021.3 is now the legacy LTS

breban1 commented 1 year ago

No, the mainTemplate.gradle file did not look like that, it had: noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]

I changed it to yours and now a new build error: DirectoryNotFoundException: Could not find a part of the path "C:\Projects\Unity\Fishing_2018_4_26f1_10032023_unity_2020_OneSignal_unity_package_file_gradle_kotinx_build_error\Library\PackageCache\com.unity.mobile.notifications@2.2.2\Runtime\Android\Plugins\com\unity\androidnotifications\UnityNotificationBackgroundThread.java"

shepherd-l commented 1 year ago

I’m not sure about that error and it seems unrelated to OneSignal

It could be that your path is too long - you can try renaming your project, “Fishing_2018_4_26f1_10032023_unity_2020_OneSignal_unity_package_file_gradle_kotinx_build_error” to make the path shorter. https://forum.unity.com/threads/mobile-notification-package.620227/page-13#post-7920271

As for the previous build error - I found the solution mentioned here for context https://support.unity.com/hc/en-us/articles/4408584577044-Why-do-I-get-errors-when-using-a-Gradle-file-with-an-old-aaptOptions-noCompress-property-

It seems like there you are running into various Unity setup issues. I'm not really sure about them. In general, I would recommend using Unity 2022.

As for OneSignal, in 5.0.2 there is a runtime error for Android builds with Minify enabled. We fixed this and it will be in the next release. There is also a workaround you can do instead in 5.0.2.
 Let me know if you have any questions

breban1 commented 1 year ago

Sounds good, I'll take your advice and then move to Unity 2022 (again). I've moved to 2022 a few times copying/pasting the project, making changes, etc. with no luck before :(

Thanks again for your help!

breban1 commented 1 year ago

SUCCESS!

Renaming the project to a shorter name did the trick! Not only does the project build, but I sent my first push notification too! Woohoo!

My final aaptOptions are:

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
    }**SIGN**

I forgot that I deleted the line: ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"

before I shortened the project name. Not sure if it would work including that line or not. I'm not going to mess with it, just glad it works.

Thank you SO MUCH for your help @shepherd-l

shepherd-l commented 1 year ago

Glad you got it to work! I'm happy that I was able to help