问题
I am relatively new to Android development and Unity and I am trying to create an Android plug-in for Unity3D that detects steps and distance using the Google fit Sensors API. I have already exported my plugin as a jar file, imported in on Assets/Plugin/Android together with my AndroidManifest.xml and when I try to build and run on my phone I get this error:
java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.fitness.request.OnDataPointListener" on path: DexPathList[[zip file "/data/app/com.example.me.androidstepcounterplugin-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.me.androidstepcounterplugin-2/lib/arm, /system/fake-libs, /data/app/com.example.me.androidstepcounterplugin-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/vendor/lib]]
I am guessing that Unity cannot find the Google Fit library, which I added as a dependency on my Android Gradle file. Is there a way to add this in Unity or would it make more sense to try making an aar file instead of jar?
回答1:
I could think of 2 possible scenarios:
You run proguard on your library with "minify enabled" which cuts that class (because you don't reference it anywhere in your activity). In this case tell proguard to keep the class by adding to your proguard.properties file the following line:
-keep class "com.google.android.gms.fitness.request.OnDataPointListener"
You are using implementation setting for you Fit dependency therefore not including it in the output. Try adding the same dependency to your Unity project.
来源:https://stackoverflow.com/questions/47393625/google-fit-android-plug-in-for-unity3d