Closed RudieCph closed 19 hours 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 None2. 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.
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.htmlHere is what I did:
- In the Unity Editor Project window, navigate to
Assets/Plugins/Android/
and click onOneSignalConfig.androidlib
. In the Inspector window, under Platform settings, change Select dependent module to None- 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.
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:
Select dependent module
for OneSignalConfig.androidlib
is set to Unity Librarypackage
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.
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?
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
Code of Conduct