Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

unity3d - Google firebase analytics plugin for unity

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...