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

[Bug]: Unity 6 Preview Gradle Build Failed #752

Closed RudieCph closed 19 hours ago

RudieCph commented 3 weeks ago

What happened?

Hi. I am trying to build the app with Unity 6 Preview. It works perfectly fine without OneSignal. As soon as the OneSignalConfig is added to the Plugins/Android/ folder, it cannot build anymore. It says Gradle Build Failed. If I remove the OneSignalConfig it builds fine, but I guess OneSignal won't work then.

Kind regards Rune

Steps to reproduce?

1. Use unity 6 preview.
2. Install OneSignal 5.1.7
3. Build fails with "Gradle Build Failed"

What did you expect to happen?

I expect it to build like it does without OneSignal.

Unity version

Unity 6 Preview 6000.0.15f1

OneSignal Unity SDK version

5.1.7

Platform

Android

Relevant log output

CommandInvokationFailure: Gradle build failed. 
/Applications/Unity/Hub/Editor/6000.0.15f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/6000.0.15f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-8.4.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "bundleRelease" 

Environment Variables:
DEBUG_ENV_VAR = UnityHub
XPC_FLAGS = 0x0
__CFBundleIdentifier = com.unity3d.unityhub
AMPLITUDE_API_KEY_GREENBUCKET_DEV = 3ded2a762163603391a425f688f990c8
AMPLITUDE_TOKEN_REDBUCKET_DEV = U4PSN7S7PuYVRODivvdcFwbu8R6IHGqa
SECURITYSESSIONID = 186a3
AMPLITUDE_API_KEY_GREENBUCKET_PROD = c86fea37a9e1d3f0878b96e15b111c7c
SENTRY_ACCESS_TOKEN = 3df78d9e53f8456aa90fbae044ce1a6261421ab1d0014674bc2e933477289017
JAVA_HOME = /Applications/Unity/Hub/Editor/6000.0.15f1/PlaybackEngines/AndroidPlayer/OpenJDK
AMPLITUDE_DEPLOYMENT_KEY_RED_BUCKET_DEV = client-wbjHYrmeSR87GmWOE7LDpf7sUySOIKHm
AMPLITUDE_TOKEN_GREENBUCKET_PROD = ZpUcbAdZXJYzNSoHsAWtL_s_JppwWid9
AMPLITUDE_API_KEY = 28f3cae0b33b8b3702120c9ed1a935aa
XPC_SERVICE_NAME = application.com.unity3d.unityhub.13266996.13267002
ANDROID_NDK_ROOT = /Applications/Unity/Hub/Editor/6000.0.15f1/PlaybackEngines/AndroidPlayer/NDK
AMPLITUDE_API_KEY_STAGING = 83ee04fccc67e4fcc7dd527c4c6f1e21
WOOTRIC_CLIENT_TOKEN = NPS-aa8be4c3
USER = rune
MallocNanoZone = 0
LOGNAME = rune
__CF_USER_TEXT_ENCODING = 0x1F6:0x0:0x9
AMPLITUDE_API_KEY_YELLOWBUCKET_DEV = 48835b4d1f5e342aefe5f016324d296a
PATH = /usr/bin:/bin:/usr/sbin:/sbin
LaunchInstanceID = FE8DD2AD-21E4-4BD4-AA7E-BAD0F90BA266
SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.6UhsdPEoqU/Listeners
AMPLITUDE_API_KEY_YELLOWBUCKET_PROD = e03a9bbe92dc38a88cdb068d24c65b46
AMPLITUDE_TOKEN_REDBUCKET_PROD = jTIgKs5KTZOjiqEEVdZFbgo_VRhABduL
AMPLITUDE_TOKEN_YELLOWBUCKET_PROD = UYDQtPOw83dIfVy3SrW5oMyo7ru4PRkV
HOME = /Users/rune
TMPDIR = /var/folders/q_/_s1xb5zj29q9zr27d5dbfpxc0000gp/T/
ORIGINAL_XDG_CURRENT_DESKTOP = undefined
AMPLITUDE_TOKEN_GREENBUCKET_DEV = 84H2gMm_FJzhr3mBaX1lM1JVukmCM7d9
AMPLITUDE_TOKEN_YELLOWBUCKET_DEV = wKi8foVigDditGFvmZewRFWsEbX9Y0YO
SHELL = /bin/zsh
AMPLITUDE_API_KEY_REDBUCKET_PROD = ca12bb461ea96f9bdf5df4ded7d52994
AMPLITUDE_DEPLOYMENT_KEY_RED_BUCKET_PROD = client-zH8Y7OK1i331EKuG77C6UxN8ygcM6LzS
COMMAND_MODE = unix2003
AMPLITUDE_API_KEY_REDBUCKET_DEV = 46b8b46515e7632fc42a504b72e05fd0

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':unityLibrary:OneSignalConfig.androidlib'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
   > Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

     If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 15s
]
stdout[
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details

> Configure project :unityLibrary
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.

> Configure project :launcher
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg, System.Text.Encoding inputEncoding) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.String[] extraArguments, System.Action`1[T] progress) (at <b62d2280a88646e0944de30335629f39>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, Unity.Android.Gradle.AndroidGradle androidGradle, System.String workingdir, System.String task, System.String[] extraArguments, System.Action`1[T] progress) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.PostProcessor.Tasks.TasksCommon.RunLauncherGradleTask (UnityEditor.Android.PostProcessor.PostProcessorContext context, System.String taskName, System.String[] extraArguments, UnityEditor.Android.PostProcessor.IPostProcessorTask owner, UnityEditor.Android.PostProcessor.ProgressHandler progress) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <b62d2280a88646e0944de30335629f39>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)

Code of Conduct

shepherd-l commented 3 weeks ago

Edit: Please look at https://github.com/OneSignal/OneSignal-Unity-SDK/issues/752#issuecomment-2322184098

~~It looks like Unity 6 changed the setup for androidlibs. I was able to build it following their documentation: https://docs.unity3d.com/6000.0/Documentation/Manual/android-library-project-import.html~~

Here is what I did: 1. In the Unity Editor Project window, navigate to Assets/Plugins/Android/ and click on OneSignalConfig.androidlib. In the Inspector window, under Platform settings, change Select dependent module to None 2. Add the new Unity dependencies in your Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle file. It should look like this:

We are not actively working on supporting Unity 6 at the moment. Unfortunately, you will have to add these fixes manually for now. I recommend also checking the Unity 6 docs to see if they change anything with the androidlibs setup in the future.

sathyarajshetigar commented 2 weeks ago

It looks like Unity 6 changed the setup for androidlibs. I was able to build it following their documentation: https://docs.unity3d.com/6000.0/Documentation/Manual/android-library-project-import.html

Here is what I did:

  1. In the Unity Editor Project window, navigate to Assets/Plugins/Android/ and click on OneSignalConfig.androidlib. In the Inspector window, under Platform settings, change Select dependent module to None
  2. Add the new Unity dependencies in your Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle file. It should look like this:
apply plugin: 'com.android.library'

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }

    def unityLib = project(':unityLibrary').extensions.getByName('android')

   defaultConfig {
        consumerProguardFiles "consumer-proguard.pro"
        minSdkVersion unityLib.defaultConfig.minSdkVersion.mApiLevel
        targetSdkVersion unityLib.defaultConfig.targetSdkVersion.mApiLevel
   }

    compileSdkVersion unityLib.compileSdkVersion
    buildToolsVersion unityLib.buildToolsVersion

    lintOptions {
        abortOnError false
    }

    // added from Unity 6 documentation: https://docs.unity3d.com/6000.0/Documentation/Manual/android-library-project-import.html
    dependencies {
        implementation project(':unityLibrary')
        implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
    }
}

We are not actively working on supporting Unity 6 at the moment. Unfortunately, you will have to add these fixes manually for now. I recommend checking the Unity 6 docs to see if they change anything else with the androidlibs setup in the future.

with this. custom notifications icons don't get added to the build. but the build works.

shepherd-l commented 1 week ago

Thanks for the info,

I was able to get the custom default notifications icons to work after removing the package attribute from the AndroidManifest and moving it to the build.gradle instead.

Here is what I did:

  1. Make sure that the Select dependent module for OneSignalConfig.androidlib is set to Unity Library
  2. Remove package attribute from OneSignalExample/Assets/Plugins/Android/OneSignalConfig.androidlib/AndroidManifest.xml Should look like:
    
    <!--
    WARNING: Do NOT Modify! Changes will be overwritten by the OneSignal plugin.
            Make your changes to Assets/Plugins/Android/AndroidManifest.xml instead.
    -->

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" >

3. Add `namespace` to OneSignalExample/Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle
Should look like:

apply plugin: 'com.android.library'

android { namespace "com.onesignal.onesignalsdk"

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
    }
}

def unityLib = project(':unityLibrary').extensions.getByName('android')

defaultConfig { consumerProguardFiles "consumer-proguard.pro" minSdk unityLib.defaultConfig.minSdk // assign to same min sdk property name in OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle targetSdk unityLib.defaultConfig.targetSdk // assign to same target sdk property name in OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle }

compileSdk unityLib.compileSdk // assign to same compile sdk property name in OneSignalExample/Assets/Plugins/Android/mainTemplate.gradle
buildToolsVersion unityLib.buildToolsVersion

lintOptions {
    abortOnError false
}

}


4. Selecting "Yes" on all the prompts when building for Android
   - I noticed that this updates deprecated property names in `mainTemplate.gradle`. I manually updated the `build.gradle` file to match as shown above

Context:
After further testing, I realize that I was going down the wrong path in my previous response and that it's incorrect. `Select dependent module` should be set to **Unity Library**.
- In the Unity Editor Project window, navigate to `Assets/Plugins/Android/` and click on `OneSignalConfig.androidlib`. In the Inspector window, under Platform settings, make sure that `Select dependent module` is set to **Unity Library**. I think this is selected by default.

The original error looks to be caused from the higher [Gradle version in Unity 6](https://docs.unity3d.com/6000.0/Documentation/Manual/android-gradle-overview.html) that enforces removing the `package` attribute in the `AndroidManifest` and including a `namespace` to in the module's build file.