Unity-Technologies / GooglePlayLicenseVerification

Unity Android plugin example on how to interface the Google Play License Verification (LVL) servers
MIT License
85 stars 26 forks source link

Not working in Unity 2020.3 #14

Open sph0001 opened 3 years ago

sph0001 commented 3 years ago

Building a project that worked fine in Unity 2019.4 now causes the following error in Unity 2020.3:

2021/08/27 14:32:24.237 5315 5338 Error Unity AndroidJavaException: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.android.vending.licensing.ILicensingService pkg=com.android.vending } 2021/08/27 14:32:24.237 5315 5338 Error Unity java.lang.SecurityException: Not allowed to bind to service Intent { act=com.android.vending.licensing.ILicensingService pkg=com.android.vending } 2021/08/27 14:32:24.237 5315 5338 Error Unity at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1838) 2021/08/27 14:32:24.237 5315 5338 Error Unity at android.app.ContextImpl.bindService(ContextImpl.java:1749) 2021/08/27 14:32:24.237 5315 5338 Error Unity at android.content.ContextWrapper.bindService(ContextWrapper.java:756) 2021/08/27 14:32:24.237 5315 5338 Error Unity at com.unity3d.plugin.lvl.ServiceBinder.create(ServiceBinder.java:32) 2021/08/27 14:32:24.237 5315 5338 Error Unity at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 2021/08/27 14:32:24.237 5315 5338 Error Unity at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 2021/08/27 14:32:24.237 5315 5338 Error Unity at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 2021/08/27 14:32:24.237 5315 5338 Error Unity at android.os.Handler.dispatchMessage(Handler.java:102) 2021/08/27 14:32:24.237 5315 5338 Error Unity at android.os.Looper.loop(Looper.java:223) 2021/08/27 14:32:24.237 5315 5338 Error Unity at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 2021/08/27 14:32:24.237 5315 5338 Error Unity at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000

Apparently I'm not the only one getting this error:

https://forum.unity.com/threads/google-play-pass-licencing-check-no-longer-working.1122247/

Any ideas about why this is happening and how to fix it?

SmilingCatEntertainment commented 3 years ago

I was also experiencing this issue in Unity 2021.1, and found that Unity was no longer correctly merging the Android manifest, so the permission for license verification was not being added to the built Android Manifest. I worked around the issue by taking Unity's generated manifest from the <project>\Temp\StagingArea\UnityManifest.xml, copying it to <project>\Assets\Plugins\AndroidManifest.xml, and then adding the permission <uses-permission android:name="com.android.vending.CHECK_LICENSE" />

sph0001 commented 3 years ago

Awesome! Directly adding <uses-permission android:name="com.android.vending.CHECK_LICENSE" /> to <project>\Assets\Plugins\Android\AndroidManifest.xml worked for me. Thanks @DukeOfDelmar!

Tanek81 commented 3 years ago

For future readers, here's what I discovered. Starting from Unity 2020 there is a fundamental change needed for a plugin folder to be considered an Android library: the folder name must end with ".androidlib" otherwise Unity won't use/merge the AndroidManifest included in the folder. Here's the Unity 2020.3 documentation: https://docs.unity3d.com/2020.3/Documentation/Manual/AndroidAARPlugins.html , in the "Android Library Projects" paragraph there's this very important change (you can check the 2019.4 documentation to see that it has been changed). So for example "GooglePlayLicensing" must be renamed to "GooglePlayLicensing.androidlib" and then the included AndroidManifest will me merged in the build. Without that, it simply won't be merged/included.

sph0001 commented 2 years ago

@Tanek81 said:

So for example "GooglePlayLicensing" must be renamed to "GooglePlayLicensing.androidlib" and then the included AndroidManifest will me merged in the build. Without that, it simply won't be merged/included.

Hi, @Tanek81. I finally got around to testing this and unfortunately simply changing "GooglePlayLicensing" to "GooglePlayLicensing.androidlib" does not seem to work. I think you're on the right track about needing to add ".androidlib" to the end of the folder name. But it seem the current project folder structure does not match the folder scheme required by Unity for Android Libraries. After I change the folder name and run my app the app is unable to find the jar file and errors out. For now going back to just adding the uses-permission line directly to the AndroidManifest file works fine but it would be nice if someone who knows how the folders should be structured makes the necessary change so the plugin will continue to work on upcoming versions of Unity out of the box...

Tanek81 commented 2 years ago

Hi @sph0001 , I am sorry but I can't help you, we had so many issues on Android with Unity 2020.3 that we reverted to Unity 2019.4. For what I recall, the change I did fixed the issue with this plugin, but I don't know if now there is more to do, maybe Unity implemented some more changes in their latest 2020.3 build? I agree with you in saying that this of course should work out of the box with the latest Unity versions :)

KyryloKuzyk commented 2 years ago

I struggled with this repo for three years with my two Play Pass games and decided that it was time to address all its issues in a well-maintained Asset Store plugin: https://assetstore.unity.com/packages/tools/integration/google-play-license-check-227317

Feel free to ask me questions here or join the Unity forum discussion: https://forum.unity.com/threads/google-play-license-check-protect-your-game-from-piracy-and-hacking.1311378/

Over17 commented 2 years ago

@KirillKuzyk please stop spamming.

KyryloKuzyk commented 2 years ago

@Over17 I'm sorry for that. My intention wasn't to spam, but to provide value for other developers. Telling people about my product here is the perfect place for people to know about it. Yes, it's a sort of advertisement, but my plugin solves many unaddressed issues that this repo has. Less work for you for maintaining this repo, more happy developers. Win-win for everyone as I see it.