Android 中的 Flurry 实施

Flurry implementation in Android

我正在 Android 中实施 Flurry Analytic。我在 Flurry.com 上创建了一个帐户并获得了一个 API 密钥。为了实施,我遵循了描述的步骤 here。我正在使用 eclipse 编译成功的 development.The 代码,但是当

FlurryAgent.init(this, "FS3****X8HRP*******2");

被称为我的应用程序崩溃。

这是我的代码:

package com.example.flurry;

import com.flurry.android.FlurryAgent;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class Flurry extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flurry);

        FlurryAgent.setLogEnabled(false);

        FlurryAgent.init(this, "FS3****X8HRP*******2");
    }

    @Override
    public void onStart()
    {
       super.onStart();
       FlurryAgent.onStartSession(this, "FS3****X8HRP*******2");
       // your code
    }

    @Override
    public void onStop()
    {
       super.onStop();
       FlurryAgent.onEndSession(this);
       // your code
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.flurry, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

下面是我的Manifest.XML

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.flurry"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="22" />

    <uses-permission android:name="android.permission.INTERNET" /> 
    <!--optional permission - highly recommended-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <!--optional permission -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Flurry"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

      <meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />  

    </application>

</manifest>

我在 this.Please 上进行了大量研究后仍未能解决问题。如果可能,请找出问题所在。

这里是 Logcat:

09-01 11:44:25.643: W/ActivityThread(13114): Application com.example.flurry is waiting for the debugger on port 8100...
09-01 11:44:25.644: I/System.out(13114): Sending WAIT chunk
09-01 11:44:25.665: I/art(13114): Debugger is active
09-01 11:44:25.845: I/System.out(13114): Debugger has connected
09-01 11:44:25.845: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:26.045: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:26.246: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:26.446: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:26.647: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:26.847: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:27.048: I/System.out(13114): waiting for debugger to settle...
09-01 11:44:27.248: I/System.out(13114): debugger has settled (1452)
09-01 11:44:46.840: D/AndroidRuntime(13114): Shutting down VM
09-01 11:44:46.848: E/AndroidRuntime(13114): FATAL EXCEPTION: main
09-01 11:44:46.848: E/AndroidRuntime(13114): Process: com.example.flurry, PID: 13114
09-01 11:44:46.848: E/AndroidRuntime(13114): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/flurry/android/FlurryAgent;
09-01 11:44:46.848: E/AndroidRuntime(13114):    at com.example.flurry.Flurry.onCreate(Flurry.java:18)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.Activity.performCreate(Activity.java:6010)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.ActivityThread.access0(ActivityThread.java:155)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.os.Looper.loop(Looper.java:135)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at android.app.ActivityThread.main(ActivityThread.java:5343)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at java.lang.reflect.Method.invoke(Native Method)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at java.lang.reflect.Method.invoke(Method.java:372)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
09-01 11:44:46.848: E/AndroidRuntime(13114): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.flurry.android.FlurryAgent" on path: DexPathList[[zip file "/data/app/com.example.flurry-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
09-01 11:44:46.848: E/AndroidRuntime(13114):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-01 11:44:46.848: E/AndroidRuntime(13114):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
09-01 11:44:46.848: E/AndroidRuntime(13114):    ... 14 more
09-01 11:44:46.848: E/AndroidRuntime(13114):    Suppressed: java.lang.ClassNotFoundException: com.flurry.android.FlurryAgent
09-01 11:44:46.848: E/AndroidRuntime(13114):        at java.lang.Class.classForName(Native Method)
09-01 11:44:46.848: E/AndroidRuntime(13114):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
09-01 11:44:46.848: E/AndroidRuntime(13114):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
09-01 11:44:46.848: E/AndroidRuntime(13114):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
09-01 11:44:46.848: E/AndroidRuntime(13114):        ... 15 more
09-01 11:44:46.848: E/AndroidRuntime(13114):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

您收到 class 未找到异常 在 Eclipse 中,可以通过检查项目>属性>Java 构建路径>订购和导出(选项卡)中的 FlurryAnalytics.jar 来解决此问题。构建后它将起作用。