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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With