简体   繁体   English

适用于Unity3D的Google Fit Android插件

[英]Google Fit Android plug-in for Unity3D

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. 我是Android开发和Unity的新手,我正在尝试为Unity3D创建一个Android插件,该插件使用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: 我已经将我的插件导出为jar文件,并与AndroidManifest.xml一起导入Assets / Plugin / Android中,当我尝试在手机上构建并运行时,出现此错误:

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. 我猜想Unity无法找到Google Fit库,它是我对Android Gradle文件的依赖项。 Is there a way to add this in Unity or would it make more sense to try making an aar file instead of jar? 有没有一种方法可以在Unity中添加它,还是尝试制作aar文件而不是jar更有意义?

I could think of 2 possible scenarios: 我可以想到2种可能的情况:

  1. You run proguard on your library with "minify enabled" which cuts that class (because you don't reference it anywhere in your activity). 您可以在带有“最小化启用”功能的库上运行proguard ,这会削减该类(因为您在活动中的任何地方都不会引用它)。 In this case tell proguard to keep the class by adding to your proguard.properties file the following line: 在这种情况下通过将以下行添加到proguard.properties文件中来告诉proguard 保留该类

    -keep class "com.google.android.gms.fitness.request.OnDataPointListener" -keep类“ com.google.android.gms.fitness.request.OnDataPointListener”

  2. You are using implementation setting for you Fit dependency therefore not including it in the output. 您正在为Fit依赖项使用implementation设置,因此不将其包括在输出中。 Try adding the same dependency to your Unity project. 尝试向您的Unity项目添加相同的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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