google / play-unity-plugins

The Google Play Plugins for Unity provide C# APIs for accessing various Play services
Other
433 stars 110 forks source link

When running on device ClassNotFoundException for AssetPackManagerFactory #180

Open userqt opened 2 years ago

userqt commented 2 years ago

I have installed the google play plugins for instant apps for unity. I created an aab file and uploaded it to google play. When I run the game, I see this. This happens when in the code I am using the PlayAssetDelivery.RetrieveAssetBundleAsync method:

ERROR: 04-30 18:29:07.638 26312 26334 E Unity : AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.play.core.assetpacks.AssetPackManagerFactory 04-30 18:29:07.638 26312 26334 E Unity : java.lang.ClassNotFoundException: com.google.android.play.core.assetpacks.AssetPackManagerFactory 04-30 18:29:07.638 26312 26334 E Unity : at java.lang.Class.classForName(Native Method) 04-30 18:29:07.638 26312 26334 E Unity : at java.lang.Class.forName(Class.java:454) 04-30 18:29:07.638 26312 26334 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 04-30 18:29:07.638 26312 26334 E Unity : at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 04-30 18:29:07.638 26312 26334 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 04-30 18:29:07.638 26312 26334 E Unity : at android.os.Handler.dispatchMessage(Handler.java:102) 04-30 18:29:07.638 26312 26334 E Unity : at android.os.Looper.loopOnce(Looper.java:201) 04-30 18:29:07.638 26312 26334 E Unity : at android.os.Looper.loop(Looper.java:288) 04-30 18:29:07.638 26312 26334 E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 04-30 18:29:07.638 26312 26334 E Unity : Caused by: java.lang.ClassNotFoundException: com.google.android.play.core.assetpacks.AssetPackManagerFactory 04-30 18:29:07.638 26312 26334 E Unity : ... 9 more 04-30 18:29:07.638 26312 26334 E Unity : at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 04-30 18:29:07.638 26312 26334 E Unity : at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <000000

Abhishek-pixelperinches commented 2 years ago

Facing same issue, Solved - Did 2 things 1->removed - -keep class com.google.android.play.core.appupdate.AppUpdateManagerFactory {

(); public static com.google.android.play.core.appupdate.AppUpdateManager create(android.content.Context); } from com.google.play.appupdate/Progard 2->in unity Preferenced>ExternalTools> tick mark all, NDk, sdk,etc. That WOrked for me.
lvfoxx1 commented 1 year ago

Facing same issue.

CarlosCabarcos commented 1 year ago

I tried @Abhishek-pixelperinches solution, but it didn't work for me.

After trying 20 millions things, I finally got it to work. The solution for me, was to do the following:

Hope it helps save anyone who faces the same problem a few hours of troubleshooting.

PS: I also updated the project to Unity 2021.3.1f1, but I don't think this matters much. It's just one more of the millions things I tried.

SachinTichkule commented 1 year ago

Facing same issue, I tried @Abhishek-pixelperinches guidlines also use proguard file to include play.core to keep file @CarlosCabarcos i tried this method but my app is going crash after write the implementation

when i add inappupdate plugin without external dependencies then build make sucessfully but got constructor error class not found if i use external dependencies then build not make i got the build error related com.android.support.support-v4-26.1.0.aar I make il2cpp build using target sdk 30 >= i did not found solution yet. please help me out @userqt @lvfoxx1 @CarlosCabarcos @Abhishek-pixelperinches if anyone find solution

CarlosCabarcos commented 1 year ago

@SachinTichkule Sorry I can't be of more help. Simple as the solution I wrote might be, it took me over 10 hours of work to find it. I just tried about every single idea I could come up with or found online until something suddenly worked. I proably rebuilt the .apk 100+ times... I'm afraid you're going to have to go through a similar process, trying all sorts of things until something works :(.

SachinTichkule commented 1 year ago

External dependency manager help me out to resolve this issue because when i deleted the external dependencies lib files which feels unnecessary and produce error. It save me to lost my time and worth my efforts

vbashiri commented 1 year ago

Add app update package (https://github.com/google/play-unity-plugins#play-in-app-update) and add these 2 lines to launcher template in the dependencies section (Enable custom launcher gradle template in project settings -> Player-> publishing settings)

implementation('com.google.android.play:asset-delivery:2.0.2')
implementation('com.google.android.play:core-common:2.0.0')

then make sure the minify is unchecked (again in project settings -> player -> publishing settings) and in asset_delivery.txt in Proguard folder in com.google.play.assetdelivery under GooglePlayPlugins find the corresponding line for AssetPackManagerFactory and replace it with the following line

-keep class com.google.android.play.core.assetpacks.** {*;}

to keep all the classes and functions. (Keeping only AssetPackManagerFactory with its constructor would be fine I guess, I just didn't risk :D).

resolve and build.

lvchy commented 1 year ago

upgrade or downgrade to com.google.play.assetdelivery-1.7.0.unitypackage , it saves my life . hopes it helped for yours .