简体   繁体   中英

Failed resolution of: Lcom/google/android/gms/common/internal/Preconditions; in Unity

I am developing an android sdk, in which it gets user location. It is working fine for android apps, and now I want to make it compatible with Unity.

I am getting this error while using FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(context);

E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/Preconditions;
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/Preconditions;
    at com.google.android.gms.common.api.Api.<init>(Unknown Source:2)
    at com.google.android.gms.location.LocationServices.<clinit>(Unknown Source:22)
    at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source:0)
    at in.___.___..LocationManager.startLocationUpdates(LocationManager.java:43)
    at in.___.___..LocationManager.startLocation(LocationManager.java:33)
    at in.___.___.Main.initialize(Main.java:126)
    at in.___.___.Main.registerAPP(Main.java:83)
    at in.___.___.init(__.java:76)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
    at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source:151)
    at android.os

I added play-services-location, play-services-base etc but cannot resolve this error.

At last, after spending 2 days on this problem, I solved it. It was actually very simple. When you add an aar library to unity, you have to check its dependencies, it will be listed in the page or in pom file. So when I check for play-service-location, I found that it has dependencies on play-service-basement and play-service-tasks. So when I add those aar packages, everything worked fine.

You can see that listing in here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM