用于统一的 Google Firebase 分析插件 [英] Google firebase analytics plugin for unity

查看:28
本文介绍了用于统一的 Google Firebase 分析插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 最近推出了适用于 iOS 和 android 的 firebase 分析,这很棒,我想在我用 unity3d 5.4b19 制作的 android 游戏中使用它.我尝试在 android studio 中为此构建一个插件

如果找不到它们,请从这里下载 jar 文件

我希望这些信息足以让您开始使用.如果您需要任何其他信息,请发表评论.

Google recently launched firebase analytics for iOS and android, which is great and I want to use it in my android game made in unity3d 5.4b19. I tried to build a plugin for this in android studio following this link. I have successfully build the jar, imported in unity, and build an apk file. But when I try to initialize firebase analytics I get following errors

AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/analytics/FirebaseAnalytics;

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/analytics/FirebaseAnalytics;

Here is my main activity class from android studio

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import com.unity3d.player.UnityPlayerActivity;
import com.google.firebase.analytics.FirebaseAnalytics;

public class MainActivity extends UnityPlayerActivity {
    private FirebaseAnalytics mFirebaseAnalytics;

    public void init() {
        // [START shared_app_measurement]
        // Obtain the FirebaseAnalytics instance.
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        // [END shared_app_measurement]
    }

    public void setUserProperty(String Property, String value) {
        // [START user_property]
        mFirebaseAnalytics.setUserProperty(Property, value);
        // [END user_property]
    }

    public void logCustomEvent(MenuItem item) {
        // [START custom_event]
        Bundle params = new Bundle();
        params.putString("image_name", "name");
        params.putString("full_text", "text");
        mFirebaseAnalytics.logEvent("share_image", params);
        // [END custom_event]
    }

    public void logEvent(String id, String name, String type) {
        // [START image_view_event]
        Bundle bundle = new Bundle();
        bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
        bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, type);
        mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
        // [END image_view_event]
    }

    public void shareText(String subject, String body) {
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
        startActivity(Intent.createChooser(sharingIntent, "Share via"));
    }
}

I understand that this is not working because it cannot find the firebase classes. I don't know how to include these files in my project. I have tried to find jar files for firebase analytics, but I couldn't find it.

解决方案

Update 31/11/16

Now you can do this from this unitypackage

I extracted all required jar file from SDK folder. It is all there inside Extra folder. Now it is working perfectly fine.

Update: Few people have requested me to post the whole process. So here is the overview of how I got firebase working in the unity. These are basically snapshots I have taken during the process for record.

Download jar files from here if have trouble finding them

I hope this much information will be enough for you to get started. If you need any other information then please comment.

这篇关于用于统一的 Google Firebase 分析插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆