Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Any ideas how to solve an encoding error?

Discussion in 'Android' started by TiggyFairy, May 19, 2024.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    526
    I'm using a Unity Android plugin that, it turns out, is not supported by the author anymore. Any ideas how to fix this error?

    upload_2024-5-19_12-31-1.png
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,098
    Reading the gradle build errors in Unity is always a bit confusing. In this case, the encoding option is not an error, just some information before the actual error:
    The
    com.nado.stepcounter
    adds a service to the
    AndroidManifest.xml
    . Android 12+ requires that services set the
    android:exported
    attribute on the service element. You need to figure out how the plugin adds the service and update it to include the attribute. It needs to be
    true
    if it's a service that other apps can access or
    false
    if it's something internal to your app.
     
  3. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    526
    Ah. Exported isn't mentioned in any of the files I can access.

    I don't know Javascript, or Android, and not sure how to add that :|
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,098
    There's no JavaScript involved and you don't need to know much about Android, everything is probably done within Unity. It could be an Android Library Project that bundles an AndroidManifest.xml that you can edit or it includes some C# code that patches the Android project unity generates that you need to adapt.

    But maybe other issues that are harder to fix will pop up once you fix this one. Finding another supported plugin might be the better path if you don't want to dabble in Android stuff.
     
  5. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    526
    Unfortunately, what I need is a working Android step counter. And that's apparently not easy. There are dozens of plugins for Unity that can do it, but none seem to work. Unity itself has an Input System that says it can do it, but I can't make that work either.

    Any ideas?
     
  6. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,098
    No, sorry, I don't have any experience with step counters on Android. You'd really need to debug the Android build to see where exactly it's not working.

    At the very least, the step counter in the Input System is supported, so you could make a simple reproduction project that shows it doesn't work and then submit it as a bug.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,948
    Does your phone support this sensor?

    Before using any sensor, you need to explicitly enable it with InputSystem.EnableDevice.
     
  8. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    526
    I have other apps that use it, so I assume so.

    I think I did that while using Input system. I think the problem was I had no permission and no way to ask. There don't seem to be any online examples on how to use the step counter, so I'm totally lost. I've found no tutorials that even mention it. Is that something you'd be able to talk me through?

    Thanks, that's an idea. I may do that.

    I wouldn't know how to even begin, unfortunately.
     
  9. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,948
    Hmph, it looks like starting with API 29, ACTIVITY_RECOGNITION permission is required https://developer.android.com/reference/android/Manifest.permission#ACTIVITY_RECOGNITION

    When step counter implementation was initially done in Unity, this was not yet required, maybe that's the reason it doesn't work for you.

    You could try manually adding this permission to manifest.


    And then use https://docs.unity3d.com/ScriptReference/Android.Permission.RequestUserPermission.html with "android.permission.ACTIVITY_RECOGNITION" to ask for permission.

    Could you also submit a bug to Unity?

    Thank you
     
  10. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    526
    Will do!

    And thank you for your help!